diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py index a07454f040d..bc3b2131153 100644 --- a/readthedocs/projects/models.py +++ b/readthedocs/projects/models.py @@ -707,7 +707,7 @@ def update_stable_version(self): if current_stable: identifier_updated = ( new_stable.identifier != current_stable.identifier) - if identifier_updated and current_stable.active: + if identifier_updated and current_stable.active and current_stable.machine: log.info( "Update stable version: {project}:{version}".format( project=self.slug, diff --git a/readthedocs/rtd_tests/tests/test_sync_versions.py b/readthedocs/rtd_tests/tests/test_sync_versions.py index 8e525b06b9e..945a765bb6b 100644 --- a/readthedocs/rtd_tests/tests/test_sync_versions.py +++ b/readthedocs/rtd_tests/tests/test_sync_versions.py @@ -349,9 +349,6 @@ def test_update_stable_version(self): self.assertEqual(version_stable.identifier, '1.0.0') def test_update_inactive_stable_version(self): - """ - Test that stable doesn't get updated when it isn't active - """ version_post_data = { 'branches': [ { @@ -471,3 +468,71 @@ def test_unicode(self): content_type='application/json', ) self.assertEqual(resp.status_code, 200) + + def test_user_defined_stable_version_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 branch that was machine created + Version.objects.create( + project=self.pip, + identifier='foo', + type='branch', + verbose_name='stable', + active=True, + machine=True, + ) + + version_post_data = { + 'branches': [ + { + 'identifier': 'origin/master', + 'verbose_name': 'master', + }, + # A new user-defined stable branch + { + 'identifier': 'origin/stable', + 'verbose_name': 'stable', + }, + ], + 'tags': [ + { + 'identifier': '0.9', + 'verbose_name': '0.9', + }, + { + 'identifier': '0.8.3', + 'verbose_name': '0.8.3', + }, + ], + } + + self.client.post( + '/api/v2/project/{}/sync_versions/'.format(self.pip.pk), + data=json.dumps(version_post_data), + content_type='application/json', + ) + + # 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('origin/stable', self.pip.get_stable_version().identifier) + + # Check that posting again doesn't change anything from current state. + self.client.post( + '/api/v2/project/{}/sync_versions/'.format(self.pip.pk), + data=json.dumps(version_post_data), + content_type='application/json', + ) + + self.assertEqual('origin/stable', self.pip.get_stable_version().identifier)