diff --git a/readthedocs/rtd_tests/tests/test_sync_versions.py b/readthedocs/rtd_tests/tests/test_sync_versions.py index 92e1006047d..0c9b9deb840 100644 --- a/readthedocs/rtd_tests/tests/test_sync_versions.py +++ b/readthedocs/rtd_tests/tests/test_sync_versions.py @@ -570,8 +570,85 @@ def test_unicode(self): ) self.assertEqual(resp.status_code, 200) - def test_user_defined_stable_version_with_tags(self): + def test_user_defined_stable_version_tag_with_tags(self): + Version.objects.create( + project=self.pip, + identifier='0.8.3', + verbose_name='0.8.3', + active=True, + ) + # A pre-existing active stable tag that was machine created + Version.objects.create( + project=self.pip, + identifier='foo', + type=TAG, + verbose_name='stable', + active=True, + machine=True, + ) + + version_post_data = { + 'branches': [ + { + 'identifier': 'origin/master', + 'verbose_name': 'master', + }, + ], + 'tags': [ + # A new user-defined stable branch + { + 'identifier': '1abc2def3', + 'verbose_name': 'stable', + }, + { + 'identifier': '0.9', + 'verbose_name': '0.9', + }, + { + 'identifier': '0.8.3', + 'verbose_name': '0.8.3', + }, + ], + } + + resp = self.client.post( + '/api/v2/project/{}/sync_versions/'.format(self.pip.pk), + data=json.dumps(version_post_data), + content_type='application/json', + ) + self.assertEqual(resp.status_code, 200) + + # Didn't update to newest tag + version_9 = Version.objects.get(slug='0.9') + self.assertFalse(version_9.active) + + # Did update to user-defined stable version + version_stable = Version.objects.get(slug='stable') + self.assertFalse(version_stable.machine) + self.assertTrue(version_stable.active) + self.assertEqual( + '1abc2def3', + self.pip.get_stable_version().identifier + ) + + # Check that posting again doesn't change anything from current state. + resp = self.client.post( + '/api/v2/project/{}/sync_versions/'.format(self.pip.pk), + data=json.dumps(version_post_data), + content_type='application/json', + ) + self.assertEqual(resp.status_code, 200) + + version_stable = Version.objects.get(slug='stable') + self.assertFalse(version_stable.machine) + self.assertTrue(version_stable.active) + self.assertEqual( + '1abc2def3', + self.pip.get_stable_version().identifier + ) + + def test_user_defined_stable_version_branch_with_tags(self): Version.objects.create( project=self.pip, identifier='0.8.3', @@ -583,7 +660,7 @@ def test_user_defined_stable_version_with_tags(self): Version.objects.create( project=self.pip, identifier='foo', - type='branch', + type=BRANCH, verbose_name='stable', active=True, machine=True, @@ -613,11 +690,12 @@ def test_user_defined_stable_version_with_tags(self): ], } - self.client.post( + resp = self.client.post( '/api/v2/project/{}/sync_versions/'.format(self.pip.pk), data=json.dumps(version_post_data), content_type='application/json', ) + self.assertEqual(resp.status_code, 200) # Didn't update to newest tag version_9 = Version.objects.get(slug='0.9') @@ -627,13 +705,23 @@ def test_user_defined_stable_version_with_tags(self): version_stable = Version.objects.get(slug='stable') self.assertFalse(version_stable.machine) self.assertTrue(version_stable.active) - self.assertEqual('origin/stable', self.pip.get_stable_version().identifier) + self.assertEqual( + 'origin/stable', + self.pip.get_stable_version().identifier + ) # Check that posting again doesn't change anything from current state. - self.client.post( + resp = self.client.post( '/api/v2/project/{}/sync_versions/'.format(self.pip.pk), data=json.dumps(version_post_data), content_type='application/json', ) + self.assertEqual(resp.status_code, 200) - self.assertEqual('origin/stable', self.pip.get_stable_version().identifier) + version_stable = Version.objects.get(slug='stable') + self.assertFalse(version_stable.machine) + self.assertTrue(version_stable.active) + self.assertEqual( + 'origin/stable', + self.pip.get_stable_version().identifier + )