Beispiel #1
0
    def test_should_is_valid_false_when_not_authenticate(self):
        email = Email('*****@*****.**')
        password = Password('sasuke123')

        naruto = User(email, password)

        naruto.authenticate(Password('sasuke321'))

        self.assertFalse(naruto.is_valid)
Beispiel #2
0
    def test_should_change_password_when_old_password_is_right(self):
        email = Email('*****@*****.**')
        password = Password('sasuke123')

        naruto = User(email, password)

        new_password = Password('boruto123')

        naruto.change_password(old_password=password,
                               new_password=new_password)

        self.assertEqual(naruto.password, str(new_password))
Beispiel #3
0
    def test_should_is_valid_false_when_old_password_is_wrong(self):
        email = Email('*****@*****.**')
        password = Password('sasuke123')

        naruto = User(email, password)

        wrong_password = Password('sakura123')

        new_password = Password('boruto123')

        naruto.change_password(old_password=wrong_password,
                               new_password=new_password)

        self.assertFalse(naruto.is_valid)
Beispiel #4
0
    def test_should_not_change_password_when_old_password_is_wrong(self):
        email = Email('*****@*****.**')
        password = Password('sasuke123')

        naruto = User(email, password)

        wrong_password = Password('sakura123')

        new_password = Password('boruto123')

        naruto.change_password(old_password=wrong_password,
                               new_password=new_password)

        self.assertEqual(naruto.password, str(password))
Beispiel #5
0
    def test_should_is_valid_true_when_email_and_password_is_valid(self):
        email = Email('*****@*****.**')
        password = Password('sasuke123')

        naruto = User(email, password)

        self.assertTrue(naruto.is_valid)
Beispiel #6
0
    def test_should_is_valid_false_when_password_not_is_valid(self):
        email = Email('*****@*****.**')
        password = Password('sas')

        naruto = User(email, password)

        self.assertFalse(naruto.is_valid)
Beispiel #7
0
    def test_should_is_valid_false_when_email_not_is_valid(self):
        email = Email('naruto')
        password = Password('sasuke123')

        naruto = User(email, password)

        self.assertFalse(naruto.is_valid)
Beispiel #8
0
    def test_should_encode_return_jwt_token(self):
        email = Email('*****@*****.**')
        password = Password('sasuke123')
        naruto = User(email, password)

        token = self._token_service.encode(naruto)

        self.assertIsInstance(token, str)
Beispiel #9
0
    def test_should_decode_return_dict_when_token_is_valid(self):
        email = Email('*****@*****.**')
        password = Password('sasuke123')
        naruto = User(email, password)

        token = self._token_service.encode(naruto)

        user = self._token_service.decode(token)

        self.assertIsInstance(user, dict)
    def test_should_save_create_user_when_user_not_exists(self):
        naruto = User(Email('*****@*****.**'), Password('test123'))

        self._user_repository.save(naruto)

        expected = 1

        result = self._session.query(UserTable).count()

        self.assertEqual(expected, result)
Beispiel #11
0
    def get_by_email(self, email):
        user_table = self._uow.session.query(UserTable).filter(
            UserTable.email == email).first()

        if not user_table:
            return

        user = User(email=Email(user_table.email),
                    password=Password(user_table.password, encrypt=False),
                    uid=user_table.uid)

        return user
Beispiel #12
0
    def test_should_is_valid_false_when_not_authenticate(self):
        email = Email('*****@*****.**')
        password = Password('sasuke123')
        naruto = User(email, password)

        self._user_repository.get_by_email.return_value = naruto

        command = AuthenticateUserCommand(email='*****@*****.**', password='******')

        self._use_case.execute(command)

        self.assertFalse(self._use_case.is_valid)
Beispiel #13
0
    def test_should_is_valid_false_when_not_change_password(self):
        email = Email('*****@*****.**')
        password = Password('sasuke123')
        naruto = User(email, password)

        self._user_repository.get_by_email.return_value = naruto

        command = ChangeUserPasswordCommand(email='*****@*****.**',
                                            old_password='******',
                                            new_password='******')

        self._use_case.execute(command)

        self.assertFalse(self._use_case.is_valid)
Beispiel #14
0
    def test_should_return_token_when_authenticate(self):
        email = Email('*****@*****.**')
        password = Password('sasuke123')
        naruto = User(email, password)

        self._user_repository.get_by_email.return_value = naruto

        self._token_service.encode.return_value = 'token'

        command = AuthenticateUserCommand(email='*****@*****.**', password='******')

        token = self._use_case.execute(command)

        self.assertEqual('token', token)
    def test_should_save_update_user_when_user_exists(self):
        naruto_table = UserTable(uid=str(uuid.uuid4()),
                                 email='*****@*****.**',
                                 password='******')

        self._session.add(naruto_table)

        naruto = User(Email('*****@*****.**'),
                      Password('test123'),
                      uid=naruto_table.uid)

        self._user_repository.save(naruto)

        expected = 1

        result = self._session.query(UserTable).count()

        self.assertEqual(expected, result)
Beispiel #16
0
    def test_should_return_is_valid_true_when_password_is_valid(self):
        password = Password('sasuke123')

        self.assertTrue(password.is_valid)
Beispiel #17
0
    def test_should_return_is_valid_false_when_password_not_contains_alphabetic_character(
            self):
        password = Password('123456')

        self.assertFalse(password.is_valid)
Beispiel #18
0
    def test_should_return_is_valid_false_when_password_not_contains_numeric_character(
            self):
        password = Password('sasuke uchiha')

        self.assertFalse(password.is_valid)
Beispiel #19
0
    def test_should_encrypt_password_when_encrypt_is_true(self):
        password = Password('sasuke123')

        self.assertNotEqual('sasuke123', str(password))
Beispiel #20
0
    def test_should_not_encrypt_password_when_encrypt_is_false(self):
        password = Password('sasuke123', encrypt=False)

        self.assertEqual('sasuke123', str(password))
Beispiel #21
0
    def test_should_return_is_valid_false_when_password_not_contains_min_len_6(
            self):
        password = Password('sas12')

        self.assertFalse(password.is_valid)