|
6 | 6 | import json
|
7 | 7 |
|
8 | 8 | from django.test import TestCase
|
| 9 | +import pytest |
9 | 10 |
|
10 | 11 | from readthedocs.builds.constants import BRANCH, STABLE, TAG
|
11 | 12 | from readthedocs.builds.models import Version
|
@@ -152,6 +153,106 @@ def test_new_tag_update_inactive(self):
|
152 | 153 | version_8 = Version.objects.get(slug='0.8.3')
|
153 | 154 | self.assertFalse(version_8.active)
|
154 | 155 |
|
| 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 | + |
155 | 256 |
|
156 | 257 | class TestStableVersion(TestCase):
|
157 | 258 | fixtures = ['eric', 'test_data']
|
|
0 commit comments