Beispiel #1
0
    def test_list_filter_with_fields(self):
        alpha = Dragonfly.objects.create(name="alpha", age=12)
        omega = Dragonfly.objects.create(name="omega", age=99)
        Sighting.objects.create(name="Berlin", dragonfly=alpha)
        Sighting.objects.create(name="Tokyo", dragonfly=omega)

        response = self.app.get(
            SightingViewSet().links["list"].reverse(),
            user=user_with_perms(["testapp.view_sighting"]),
        )

        filter_form = response.forms["filter-form"]

        filter_form["filter-name"] = "Tokyo"
        tokyo_response = filter_form.submit()
        self.assertNotContains(tokyo_response, "alpha")
        self.assertContains(tokyo_response, "omega")

        filter_form["filter-name"] = "nothing"
        empty_response = filter_form.submit()
        self.assertNotContains(empty_response, "alpha")
        self.assertNotContains(empty_response, "omega")
        self.assertContains(
            empty_response,
            "Could not find any sightings that match the current filters",
        )
Beispiel #2
0
 def test_navigation_hides_empty_submenus(self):
     user = user_with_perms([])
     base_page = self.app.get(reverse("base-template"), user=user)
     self.maxDiff = None
     self.assertNotContains(base_page, "Testapp")
     self.assertNotContains(base_page, SightingViewSet().links["list"].reverse())
     self.assertNotContains(base_page, DragonflyViewSet().links["list"].reverse())
Beispiel #3
0
 def test_navigation_entry_handles_other_components(self):
     user = user_with_perms(["testapp.view_sighting"])
     self.assertEqual(
         navigation_component_entry(SightingViewSet().links["other_list"],
                                    user=user),
         ("Another list is possible", "/sighting/other/"),
     )
Beispiel #4
0
 def test_navigation_entry_respects_permissions(self):
     user = user_with_perms(["testapp.view_dragonfly"])
     self.assertEqual(
         navigation_component_entry(DragonflyViewSet().links["list"],
                                    user=user),
         ("dragonflys", "/dragonfly/"),
     )
     self.assertEqual(
         navigation_component_entry(SightingViewSet().links["list"],
                                    user=user), None)
Beispiel #5
0
 def test_detail_links_to_related_require_permission(self):
     alpha = Dragonfly.objects.create(name="alpha", age=47)
     sighting = Sighting.objects.create(dragonfly=alpha)
     links = SightingViewSet().links
     detail_page = self.app.get(
         links["detail"].reverse(sighting),
         user=user_with_perms(
             [
                 "testapp.view_sighting",
             ]
         ),
     )
     with self.assertRaises(IndexError):
         detail_page.click(
             "alpha", href=DragonflyViewSet().links["detail"].reverse(alpha)
         )
Beispiel #6
0
 def test_detail_links_related(self):
     alpha = Dragonfly.objects.create(name="alpha", age=47)
     sighting = Sighting.objects.create(dragonfly=alpha)
     links = SightingViewSet().links
     detail_page = self.app.get(
         links["detail"].reverse(sighting),
         user=user_with_perms(
             [
                 "testapp.view_dragonfly",
                 "testapp.view_sighting",
             ]
         ),
     )
     detail_page.click(
         "alpha", href=DragonflyViewSet().links["detail"].reverse(alpha)
     )
Beispiel #7
0
 def test_navigation_respects_permissions(self):
     user = user_with_perms(["testapp.view_sighting"])
     base_page = self.app.get(reverse("base-template"), user=user)
     self.assertNotContains(base_page, DragonflyViewSet().links["list"].reverse())
     self.assertContains(base_page, SightingViewSet().links["list"].reverse())