Skip to content

Commit

Permalink
Add new test
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd committed Apr 8, 2018
1 parent 2ab9257 commit e6e6e5e
Showing 1 changed file with 94 additions and 6 deletions.
100 changes: 94 additions & 6 deletions readthedocs/rtd_tests/tests/test_sync_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand Down Expand Up @@ -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')
Expand All @@ -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
)

0 comments on commit e6e6e5e

Please sign in to comment.