Skip to content

Commit

Permalink
Add tests on test_project
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd committed Mar 27, 2018
1 parent 634dbec commit 9fcb9bb
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions readthedocs/rtd_tests/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,71 @@ def test_user_cant_delete_other_user_translations(self):
self.assertEqual(resp.status_code, 404)
self.assertIn(project_b, project_a.translations.all())

def test_user_cant_change_lang_to_translation_lang(self):
user_a = User.objects.get(username='eric')
project_a = Project.objects.get(slug='read-the-docs')
project_b = get(
Project, users=[user_a],
language='es', main_language_project=None
)

project_a.translations.add(project_b)
project_a.save()

# User tries to change the language
# to the same of the translation
self.client.login(username=user_a.username, password='test')
self.assertIn(project_b, project_a.translations.all())
self.assertEqual(project_a.language, 'en')
self.assertEqual(project_b.language, 'es')
data = model_to_dict(project_a)
data['language'] = 'es'
resp = self.client.post(
reverse(
'projects_edit',
args=[project_a.slug]
),
data=data,
follow=True
)
self.assertEqual(resp.status_code, 200)
self.assertContains(resp, 'error')
self.assertContains(
resp,
'There is already a "es" translation '
'for the read-the-docs project'
)

def test_user_can_change_project_whith_same_lang(self):
user_a = User.objects.get(username='eric')
project_a = Project.objects.get(slug='read-the-docs')
project_b = get(
Project, users=[user_a],
language='es', main_language_project=None
)

project_a.translations.add(project_b)
project_a.save()

# User save the project with no modifications
self.client.login(username=user_a.username, password='test')
self.assertIn(project_b, project_a.translations.all())
self.assertEqual(project_a.language, 'en')
self.assertEqual(project_b.language, 'es')
data = model_to_dict(project_a)
# Same languge
data['language'] = 'en'
resp = self.client.post(
reverse(
'projects_edit',
args=[project_a.slug]
),
data=data,
follow=True
)
self.assertEqual(resp.status_code, 200)
self.assertNotContains(resp, 'error')

def test_token(self):
r = self.client.get('/api/v2/project/6/token/', {})
resp = json.loads(r.content)
Expand Down

0 comments on commit 9fcb9bb

Please sign in to comment.