Ejemplo n.º 1
0
    def test_untrusted(self):
        agent = self._roundtrip_agent(Agent.untrusted_agent(self.alice))

        self.assertTrue(not agent.is_trusted)
        self.assertTrue(not agent.is_session)
        self.assertEqual(agent.trusted_at, None)
        self.assertEqual(agent.serial, -1)
Ejemplo n.º 2
0
    def test_view_2_trusted(self):
        request = self.factory.get('/')
        request.user = self.alice
        request.agent = Agent.trusted_agent(self.alice)

        response = decorated_view_2(request)

        self.assertEqual(response.status_code, 200)
Ejemplo n.º 3
0
    def test_cross_user(self):
        AgentSettings.objects.get_or_create(user=self.bob)

        agent = Agent.trusted_agent(self.alice)
        encoded = self.middleware._encode_cookie(agent, self.alice)
        agent = self.middleware._decode_cookie(encoded, self.bob)

        self.assertTrue(not agent.is_trusted)
Ejemplo n.º 4
0
 def test_session_anonymous(self):
     with self.assertRaises(Exception):
         Agent.session_agent(AnonymousUser(), 0)
Ejemplo n.º 5
0
 def test_trust_anonymous(self):
     with self.assertRaises(Exception):
         Agent.trusted_agent(AnonymousUser())
Ejemplo n.º 6
0
    def _roundtrip(self, *args, **kwargs):
        agent = Agent(self.alice, *args, **kwargs)

        return self._roundtrip_agent(agent)