Add test for this case
@@ -468,3 +468,79 @@ class TestStableVersion(TestCase):
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,
+ )
+
+ 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',
+ },
+ {
+ 'identifier': 'origin/stable',
+ 'verbose_name': 'stable',
+ },
+ {
+ 'identifier': 'origin/to_add',
+ 'verbose_name': 'to_add',
+ },
+ ],
+ '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',
+ )
+
+ version_9 = Version.objects.get(slug='0.9')
+ self.assertFalse(version_9.active)
+
+ version_stable = Version.objects.get(slug='stable')
+ self.assertFalse(version_stable.machine)
+ self.assertTrue(version_stable.active)
+
+ # Version 0.9 doesn't become stable, since we already had a user-defined stable
+ self.assertEqual(
+ 'origin/stable',
+ self.pip.get_stable_version().identifier,
+ )
+
+ self.client.post(
+ '/api/v2/project/{}/sync_versions/'.format(self.pip.pk),
+ data=json.dumps(version_post_data),
+ content_type='application/json',
+ )
+
+ # Version 0.9 doesn't become stable, since we already had a user-defined stable
+ self.assertEqual(
+ 'origin/stable',
+ self.pip.get_stable_version().identifier,
+ )
