def test_dependency_build_pagination(self): """ The dependency build list should return maximum number records as defined in PAGINATE_BUILDS. The previous page link should be disabled and the next page link should be available. """ dependency = DependencyFactory.create() BuildFactory.create_batch( DependencyDetailView.PAGINATE_BUILDS + 1, job=dependency.job) depend_url = reverse("dependency_detail", kwargs={"pk": dependency.pk}) response = self.app.get(depend_url, user="******") self.assertEqual(200, response.status_code) self.assertEqual(len(response.context["builds"]), DependencyDetailView.PAGINATE_BUILDS) self.assertEqual(response.context["builds"].number, 1) # Check that the 'Newer' link is disabled self.assertRaises(IndexError, response.click, "Newer") # Check that the 'Older' link takes us to page two older = response.click("Older") self.assertEqual(200, older.status_code) self.assertNotEquals(older, response) self.assertEqual(older.context["builds"].number, 2)
def test_get_build_table_for_project_with_multiple_dependencies(self): """ We should get a table of rows with all dependencies, indicating whether or not the current build is the build. """ project = ProjectFactory.create() dependency1 = DependencyFactory.create() dependency2 = DependencyFactory.create() [build1, build2, build3, build4, build5] = BuildFactory.create_batch( 5, job=dependency1.job) ProjectDependency.objects.create( project=project, dependency=dependency1, auto_track=False, current_build=build5) [build6, build7, build8, build9, build10] = BuildFactory.create_batch( 5, job=dependency2.job) ProjectDependency.objects.create( project=project, dependency=dependency2, auto_track=False, current_build=build8) header, table = get_build_table_for_project(project) self.assertEqual([dependency1, dependency2], header) self.assertEqual([ [{"build": build5, "current": True}, {"build": build10, "current": False}], [{"build": build4, "current": False}, {"build": build9, "current": False}], [{"build": build3, "current": False}, {"build": build8, "current": True}], [{"build": build2, "current": False}, {"build": build7, "current": False}], [{"build": build1, "current": False}, {"build": build6, "current": False}]], table)
def test_dependency_build_pagination_page_invalid(self): """ The dependency build list should return the last page when an out-of- range number is supplied. """ dependency = DependencyFactory.create() BuildFactory.create_batch( DependencyDetailView.PAGINATE_BUILDS + 1, job=dependency.job) depend_url = reverse("dependency_detail", kwargs={"pk": dependency.pk}) depend_url += "?page=999" response = self.app.get(depend_url, user="******") self.assertEqual(200, response.status_code) self.assertEqual(len(response.context["builds"]), 1) self.assertEqual(response.context["builds"].number, 2)
def test_get_build_table_with_current_build_outside_recent(self): """ If we have a current build outside the most recent 5, then we should extend the dependencies list for that row to illustrate the current build. """ project = ProjectFactory.create() dependency = DependencyFactory.create() build = BuildFactory.create(job=dependency.job) [build1, build2, build3, build4, build5] = BuildFactory.create_batch( 5, job=dependency.job) ProjectDependency.objects.create( project=project, dependency=dependency, auto_track=False, current_build=build) header, table = get_build_table_for_project(project) self.assertEqual([dependency], header) self.assertEqual([ [{"build": build5, "current": False}], [{"build": build4, "current": False}], [{"build": build3, "current": False}], [{"build": build2, "current": False}], [{"build": build1, "current": False}], [{"build": build, "current": True}]], table)
def test_projectbuild_list_view(self): """ The list view should provide a list of projects. """ job = JobFactory.create() BuildFactory.create_batch(5, job=job) project = ProjectFactory.create() ProjectDependency.objects.create( project=project, dependency=DependencyFactory.create(job=job)) projectbuild = ProjectBuildFactory.create(project=project) BuildFactory.create(job=job, build_id=projectbuild.build_id) url = reverse("project_projectbuild_list", kwargs={"pk": project.pk}) response = self.app.get(url, user="******") self.assertEqual(200, response.status_code) self.assertEqual( set([projectbuild]), set(response.context["projectbuilds"])) self.assertEqual(project, response.context["project"])
def test_dependency_build_pagination_page_two(self): """ The dependency build list should return 1 record when retrieving the second page. """ dependency = DependencyFactory.create() BuildFactory.create_batch( DependencyDetailView.PAGINATE_BUILDS + 1, job=dependency.job) depend_url = reverse("dependency_detail", kwargs={"pk": dependency.pk}) depend_url += "?page=2" response = self.app.get(depend_url, user="******") self.assertEqual(200, response.status_code) self.assertEqual(len(response.context["builds"]), 1) self.assertEqual(response.context["builds"].number, 2) # Check that the 'Older' link is disabled self.assertRaises(IndexError, response.click, "Older") # Check that the 'newer' link takes us to page one newer = response.click("Newer") self.assertEqual(200, newer.status_code) self.assertNotEquals(newer, response) self.assertEqual(newer.context["builds"].number, 1)
def test_project_dependencies(self): """ Project Dependencies view should show all dependencies and the status of their build. """ project = ProjectFactory.create() dependency = DependencyFactory.create() builds = BuildFactory.create_batch(5, job=dependency.job) ProjectDependency.objects.create( project=project, dependency=dependency, auto_track=False, current_build=builds[-1]) project_url = reverse( "project_dependencies", kwargs={"pk": project.pk}) response = self.app.get(project_url, user="******") self.assertEqual(200, response.status_code) self.assertEqual(project, response.context["project"]) self.assertEqual( [dependency], list(response.context["builds_header"]))
def test_get_build_table_for_project_with_single_dependency(self): """ We should get a table of rows for this dependency, indicating whether or not the current build is the build. """ project = ProjectFactory.create() dependency = DependencyFactory.create() [build1, build2, build3, build4, build5] = BuildFactory.create_batch( 5, job=dependency.job) ProjectDependency.objects.create( project=project, dependency=dependency, auto_track=False, current_build=build5) header, table = get_build_table_for_project(project) self.assertEqual([dependency], header) self.assertEqual([ [{"build": build5, "current": True}], [{"build": build4, "current": False}], [{"build": build3, "current": False}], [{"build": build2, "current": False}], [{"build": build1, "current": False}]], table)