def test_a(self):
        """A user is allowed to view a public scenario.

        The user is not logged in.

        """
        configurations = retrieve_viewable_configurations(AnonymousUser())
        self.assertEqual([self.configuration], list(configurations))
    def test_c(self):
        """A user is allowed to view a public scenario.

        The user is logged in.

        """
        user = authenticate(username="******", password="******")
        assert user is not None

        configurations = retrieve_viewable_configurations(user)
        self.assertEqual([self.configuration], list(configurations))
    def test_b(self):
        """A user is not allowed to view a non-public scenario.

        The user is not logged in.

        """
        self.scenario.public = False
        self.scenario.save()

        configurations = retrieve_viewable_configurations(AnonymousUser())
        self.assertEqual([], list(configurations))
    def test_d(self):
        """A user is not-allowed to view a non-public scenario.

        The user is logged in.

        """
        self.scenario.public = False
        self.scenario.save()
        user = authenticate(username="******", password="******")
        assert user is not None

        configurations = retrieve_viewable_configurations(user)
        self.assertEqual([], list(configurations))
    def test_e(self):
        """A user is allowed to view a non-public scenario.

        The user is logged in and has the right to view non-public scenarios.

        """
        self.scenario.public = False
        self.scenario.save()
        permission = Permission.objects.get(codename="see_not_public_scenarios")
        assert permission is not None
        self.user.user_permissions.add(permission)
        self.user.save()
        user = authenticate(username="******", password="******")
        assert user is not None

        configurations = retrieve_viewable_configurations(user)
        self.assertEqual([self.configuration], list(configurations))