77
88@pytest .fixture
99def client ():
10+ client = models .Client ('mock://example.com' )
11+ client .header = {}
12+ client .cookies = {}
13+ client .user_full_name = ''
14+ return client
15+
16+
17+ def test_authenticate (client ):
18+ """Test authenticate function."""
1019 with requests_mock .Mocker () as m :
11- uri1 = 'mock://example.com/rest/login'
12- uri2 = 'mock://example.com/rest/status'
20+ url1 = '/rest/login'
21+ url2 = '/rest/status'
22+ email = 'test@test.mock'
23+ password = '1234'
24+ header = {'content-type' : 'application/json' , 'accept' :
25+ 'application/json' }
1326 cookies = {'JSESSIONID' : '11111111' }
1427 json_object = {'fullname' : 'User Name' }
15- m .post (uri1 , cookies = cookies )
16- m .get (uri2 , json = json_object )
17- client = models .Client ('mock://example.com' , 'test' , 'test' )
18- return client
28+ m .post (url1 , cookies = cookies )
29+ m .get (url2 , json = json_object )
30+ client .authenticate (email , password )
31+ assert client .user_full_name == 'User Name'
32+ assert client .cookies == cookies
33+ assert client .header == header
1934
2035
2136def test_get_record (client ):
@@ -28,18 +43,32 @@ def test_get_record(client):
2843 assert attr .asdict (rec_obj )['metadata' ] == json_object ['metadata' ]
2944
3045
31- # def test_filtered_item_search(client):
32- # """Test filtered_item_search function."""
33- # item_links = client.filtered_item_search(key, string, query_type,
34- # selected_collections='')
35- # assert False
36- #
37- #
38- # def test__pop_inst(client):
39- # rec_obj = client._pop_inst(class_type, rec_obj)
40- # assert False
41- #
42- #
43- # def test__build_uuid_list(client):
44- # child_list = client._build_uuid_list(self, rec_obj, kwargs, children)
45- # assert False
46+ def test_filtered_item_search (client ):
47+ """Test filtered_item_search function."""
48+ with requests_mock .Mocker () as m :
49+ key = 'dc.title'
50+ string = 'test'
51+ query_type = 'contains'
52+ endpoint = '/rest/filtered-items?'
53+ json_object_1 = {'items' : [{'link' : '1234' }]}
54+ json_object_2 = {'items' : []}
55+ m .get (endpoint , [{'json' : json_object_1 }, {'json' : json_object_2 }])
56+
57+ item_links = client .filtered_item_search (key , string , query_type ,
58+ selected_collections = '' )
59+ assert '1234' in item_links
60+
61+
62+ def test__pop_inst (client ):
63+ class_type = models .Collection
64+ rec_obj = {'name' : 'Test title' , 'type' : 'collection' , 'items' : []}
65+ rec_obj = client ._pop_inst (class_type , rec_obj )
66+ assert type (rec_obj ) == class_type
67+ assert rec_obj .name == 'Test title'
68+
69+
70+ def test__build_uuid_list (client ):
71+ rec_obj = {'items' : [{'uuid' : '1234' }]}
72+ children = 'items'
73+ child_list = client ._build_uuid_list (rec_obj , children )
74+ assert '1234' in child_list
0 commit comments