Commit 67a6c319 authored by Michal Čihař's avatar Michal Čihař

Add tests for getting individual items as well

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent b4c07052
......@@ -34,25 +34,65 @@ class APITest(APITestCase, RepoTestMixin):
response = self.client.get(
reverse('api:project-list')
)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]['slug'], 'test')
self.assertEqual(response.data['count'], 1)
self.assertEqual(response.data['results'][0]['slug'], 'test')
def test_get_project(self):
response = self.client.get(
reverse('api:project-detail', kwargs={'slug': 'test'})
)
self.assertEqual(response.data['slug'], 'test')
def test_list_components(self):
response = self.client.get(
reverse('api:subproject-list')
reverse('api:component-list')
)
self.assertEqual(response.data['count'], 1)
self.assertEqual(response.data['results'][0]['slug'], 'test')
self.assertEqual(
response.data['results'][0]['project']['slug'], 'test'
)
def test_get_component(self):
response = self.client.get(
reverse(
'api:component-detail',
kwargs={
'slug': 'test',
'project__slug': 'test'
}
)
)
self.assertEqual(len(response.data), 1)
self.assertEqual(response.data[0]['slug'], 'test')
self.assertEqual(response.data[0]['project']['slug'], 'test')
self.assertEqual(response.data['slug'], 'test')
self.assertEqual(response.data['project']['slug'], 'test')
def test_list_translations(self):
response = self.client.get(
reverse('api:translation-list')
)
self.assertEqual(len(response.data), 3)
self.assertEqual(response.data['count'], 3)
def test_get_translation(self):
response = self.client.get(
reverse(
'api:translation-detail',
kwargs={
'language__code': 'cs',
'subproject__slug': 'test',
'subproject__project__slug': 'test'
}
)
)
self.assertEqual(response.data['language_code'], 'cs')
def test_list_languages(self):
response = self.client.get(
reverse('api:language-list')
)
self.assertEqual(len(response.data), 3)
self.assertEqual(response.data['count'], 3)
def test_get_language(self):
response = self.client.get(
reverse('api:language-detail', kwargs={'code': 'cs'})
)
self.assertEqual(response.data['name'], 'Czech')
......@@ -33,6 +33,11 @@ router.register(
r'projects',
ProjectViewSet
)
router.register(
r'components',
ComponentViewSet,
'component',
)
router.register(
r'components/(?P<project__slug>[^/]+)',
ComponentViewSet,
......@@ -44,6 +49,10 @@ router.register(
r'(?P<subproject__slug>[^/]+)',
TranslationViewSet
)
router.register(
r'translations',
TranslationViewSet
)
router.register(
r'languages',
LanguageViewSet
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment