Skip to content

Commit 2ab9257

Browse files
committed
Test for stuck stable
1 parent 46890a9 commit 2ab9257

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

readthedocs/rtd_tests/tests/test_sync_versions.py

+101
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77

88
from django.test import TestCase
9+
import pytest
910

1011
from readthedocs.builds.constants import BRANCH, STABLE, TAG
1112
from readthedocs.builds.models import Version
@@ -152,6 +153,106 @@ def test_new_tag_update_inactive(self):
152153
version_8 = Version.objects.get(slug='0.8.3')
153154
self.assertFalse(version_8.active)
154155

156+
def test_stable_stuck(self):
157+
"""
158+
The repository has a tag named ``stable``,
159+
when syncing the versions, the RTD's ``stable`` is lost
160+
and doesn't update automatically anymore, when the tag is deleted
161+
on the user repository, the RTD's ``stable`` is back.
162+
"""
163+
version8 = Version.objects.create(
164+
project=self.pip,
165+
identifier='0.8.3',
166+
verbose_name='0.8.3',
167+
type=TAG,
168+
active=False,
169+
)
170+
self.pip.update_stable_version()
171+
current_stable = self.pip.get_stable_version()
172+
173+
# 0.8.3 is the current stable
174+
self.assertTrue(
175+
version8.identifier,
176+
current_stable.identifier
177+
)
178+
self.assertTrue(current_stable.machine)
179+
180+
version_post_data = {
181+
'branches': [
182+
{
183+
'identifier': 'origin/master',
184+
'verbose_name': 'master',
185+
},
186+
],
187+
'tags': [
188+
{
189+
'identifier': '1abc2def3',
190+
'verbose_name': 'stable',
191+
},
192+
{
193+
'identifier': '0.8.3',
194+
'verbose_name': '0.8.3',
195+
},
196+
],
197+
}
198+
199+
resp = self.client.post(
200+
'/api/v2/project/{}/sync_versions/'.format(self.pip.pk),
201+
data=json.dumps(version_post_data),
202+
content_type='application/json',
203+
)
204+
self.assertEqual(resp.status_code, 200)
205+
206+
# The new tag is the new stable
207+
version8 = Version.objects.get(slug='0.8.3')
208+
version_stable = Version.objects.get(slug='stable')
209+
current_stable = self.pip.get_stable_version()
210+
self.assertEqual(
211+
version_stable.identifier,
212+
current_stable.identifier,
213+
)
214+
215+
# The current_stable lost its machine property
216+
# it's not automatically updated anymore
217+
self.assertFalse(current_stable.machine)
218+
219+
# Deleting the stable version should
220+
# return the RTD's stable
221+
version_post_data = {
222+
'branches': [
223+
{
224+
'identifier': 'origin/master',
225+
'verbose_name': 'master',
226+
},
227+
],
228+
'tags': [
229+
{
230+
'identifier': '0.8.3',
231+
'verbose_name': '0.8.3',
232+
},
233+
],
234+
}
235+
236+
resp = self.client.post(
237+
'/api/v2/project/{}/sync_versions/'.format(self.pip.pk),
238+
data=json.dumps(version_post_data),
239+
content_type='application/json',
240+
)
241+
self.assertEqual(resp.status_code, 200)
242+
243+
# The version 8 should be the new stable
244+
version8 = Version.objects.get(slug='0.8.3')
245+
current_stable = self.pip.get_stable_version()
246+
self.assertEqual(
247+
version8.identifier,
248+
current_stable.identifier,
249+
)
250+
# The stable isn't stuck with the previous commit
251+
self.assertNotEqual(
252+
'1abc2def3',
253+
current_stable.identifier,
254+
)
255+
155256

156257
class TestStableVersion(TestCase):
157258
fixtures = ['eric', 'test_data']

0 commit comments

Comments
 (0)