Skip to content

Commit

Permalink
More Tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
saadmk11 committed Jun 14, 2019
1 parent 033d2a9 commit de5ce44
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ def previous(self):
date = self.date or timezone.now()
if self.project is not None and self.version is not None:
return (
Build.internal.filter(
Build.objects.filter(
project=self.project,
version=self.version,
date__lt=date,
Expand Down
6 changes: 6 additions & 0 deletions readthedocs/rtd_tests/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ def test_update_stable_version_excludes_pr_versions(self):
# Test that PR Version is not considered for stable.
self.assertEqual(self.pip.update_stable_version(), None)

def test_has_good_build_excludes_pr_versions(self):
# Delete all versions excluding PR Versions.
self.pip.versions.exclude(type=PULL_REQUEST).delete()
# Test that PR Version is not considered for has_good_build.
self.assertFalse(self.pip.has_good_build)


class TestProjectTranslations(ProjectMixin, TestCase):

Expand Down
25 changes: 23 additions & 2 deletions readthedocs/rtd_tests/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from django.urls import reverse
from django_dynamic_fixture import get, new

from readthedocs.builds.constants import LATEST
from readthedocs.builds.models import Build
from readthedocs.builds.constants import LATEST, PULL_REQUEST
from readthedocs.builds.models import Build, Version
from readthedocs.core.permissions import AdminPermission
from readthedocs.projects.forms import UpdateProjectForm
from readthedocs.projects.models import HTMLFile, Project
Expand Down Expand Up @@ -266,6 +266,7 @@ class BuildViewTests(TestCase):

def setUp(self):
self.client.login(username='eric', password='test')
self.pip = Project.objects.get(slug='pip')

@mock.patch('readthedocs.projects.tasks.update_docs_task')
def test_build_redirect(self, mock):
Expand All @@ -276,3 +277,23 @@ def test_build_redirect(self, mock):
r._headers['location'][1],
'/projects/pip/builds/%s/' % build.pk,
)

def test_build_list_does_not_include_pr_versions(self):
pr_version = get(
Version,
project = self.pip,
active = True,
type = PULL_REQUEST,
)
pr_version_build = get(
Build,
project = self.pip,
version = pr_version
)
response = self.client.get(
reverse('builds_project_list', args=[self.pip.slug]),
)
self.assertEqual(response.status_code, 200)

self.assertNotIn(pr_version_build, response.context['build_qs'])
self.assertNotIn(pr_version_build, response.context['active_builds'])

0 comments on commit de5ce44

Please sign in to comment.