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)
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))
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)
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))
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)
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)
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)
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)
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)
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_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)
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
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_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)
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)