-
Notifications
You must be signed in to change notification settings - Fork 27
/
tests.py
67 lines (46 loc) · 2.62 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from core.collections.documents import CollectionDocument
from core.collections.models import Collection
from core.collections.tests.factories import OrganizationCollectionFactory
from core.common.tests import OCLAPITestCase
from core.orgs.tests.factories import OrganizationFactory
from core.sources.documents import SourceDocument
from core.sources.models import Source
from core.sources.tests.factories import OrganizationSourceFactory
class ReposListViewTest(OCLAPITestCase):
def test_get_200(self):
CollectionDocument._index.delete() # pylint: disable=protected-access
SourceDocument._index.delete() # pylint: disable=protected-access
CollectionDocument.init()
SourceDocument.init()
org1 = OrganizationFactory(mnemonic='org1')
OrganizationSourceFactory(organization=org1, mnemonic='repo-source1', source_type='Dictionary')
OrganizationCollectionFactory(organization=org1, mnemonic='repo-coll1', collection_type='Dictionary')
org2 = OrganizationFactory(mnemonic='org2')
OrganizationSourceFactory(organization=org2, mnemonic='repo-source2', source_type='Dictionary')
OrganizationCollectionFactory(organization=org2, mnemonic='repo-coll2', collection_type='Dictionary')
SourceDocument().update(Source.objects.all())
CollectionDocument().update(Collection.objects.all())
response = self.client.get('/repos/')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 4)
response = self.client.get('/repos/?q=repo')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 4)
response = self.client.get('/repos/?q=coll')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 2)
response = self.client.get('/repos/?source_type=Dictionary')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 2)
response = self.client.get(org1.uri + 'repos/')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 2)
response = self.client.get(org1.uri + 'repos/?q=repo')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 2)
response = self.client.get(org1.uri + 'repos/?q=coll')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 1)
response = self.client.get(org1.uri + 'repos/?collection_type=Dictionary')
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.data), 1)