def test_authentication_serializer_invalid_no_details(self):
     """Tests that the AuthenticationSerializer is invalid when passed neither a username nor password"""
     serializer = AuthenticationSerializer(data={
         "email": None,
         "password": None
     })
     self.assertFalse(serializer.is_valid())
 def test_authentication_serializer_invalid_wrong_password(self):
     """Tests that the AuthenticationSerializer is invalid when passed an incorrect password"""
     serializer = AuthenticationSerializer(data={
         "email": email,
         "password": "******"
     })
     self.assertFalse(serializer.is_valid())
 def test_authentication_serializer_invalid_deleted_user(self):
     """Tests that the AuthenticationSerializer is invalid when passed a User who has been deleted"""
     self.user.delete()
     serializer = AuthenticationSerializer(data={
         "email": email,
         "password": password
     })
     self.assertFalse(serializer.is_valid())
Ejemplo n.º 4
0
    def test_authentication_serializer_valid_email_not_verified(self):
        """Tests that the AuthenticationSerializer is valid when passed a correct user and password.

        However, with an unverified email address the needs_verify flag on the response_dict will be True.
        """
        serializer = AuthenticationSerializer(data={
            "email": email,
            "password": password
        }, context={"request": self.valid_mock_request})
        serializer.is_valid()
        self.assertTrue(serializer.data["needs_verify"])
 def test_authentication_serializer_valid(self):
     """Tests that the AuthenticationSerializer is valid when passed a correct user and password"""
     self.user.userprofile.verify_email()  # verifying their email
     serializer = AuthenticationSerializer(
         data={
             "email": email,
             "password": password
         },
         context={"request": self.valid_mock_request})
     self.assertTrue(serializer.is_valid())
     self.assertEqual(serializer.data["token"],
                      self.user.get_access_token().key)
Ejemplo n.º 6
0
 def test_authentication_serializer_invalid_wrong_environment(self):
     """Tests that the AuthenticationSerializer is invalid when passed an incorrect HTTP_X_ORIGIN_ENVIRONMENT"""
     invalid_mock_request = self.MockRequest(
         META={"HTTP_X_ORIGIN_ENVIRONMENT": "12354fs"}
     )
     serializer = AuthenticationSerializer(data={
         "email": email,
         "password": password,
     }, context={"request": invalid_mock_request})
     with self.assertRaises(KeyError):
         # It will raise a KeyError as the invalid environment is not in the ENVIRONMENT_GROUPS dict
         serializer.is_valid()
Ejemplo n.º 7
0
    def test_login_failure_audit_log_created(self):
        """A failed login should create a related audit log.

        Given that a public user attempts to log in

        When they fail to log in

        Then a record recording the unsuccessful log-in is written to the audit log
        """
        self.assertEqual(
            Audit.objects.filter(type=AUDIT_TYPE_LOGIN_FAILED, data__email=self.user.email).count(),
            0
        )
        self.user.userprofile.verify_email()  # verifying their email
        serializer = AuthenticationSerializer(data={
            "email": email,
            "password": "******"
        }, context={"request": self.valid_mock_request})
        serializer.is_valid()
        self.assertEqual(
            Audit.objects.filter(type=AUDIT_TYPE_LOGIN_FAILED, data__email=self.user.email).count(),
            1
        )