Exemplo n.º 1
0
    def test_should_get_user_by_user_name(self):
        # given
        user = UserEntity()
        user.id = 1
        user.user_name = "test_user"
        user.created_on = datetime.utcnow()
        user.modified_on = datetime.utcnow()
        user.opt_lock = 0
        user.password_hash = "test_hash"

        self.user_repository_mock.read_by_user_name.return_value = user

        # when
        user_data = user_service.get_user_by_user_name("test_user")

        # then
        self.assertIsNotNone(user_data)
        self.assertIsInstance(user_data, dict)
        self.assertEqual(user.id, user_data["id"])
        self.assertEqual(user.user_name, user_data["user_name"])
        self.assertEqual(user.created_on, user_data["created_on"])
        self.assertEqual(user.modified_on, user_data["modified_on"])
        self.assertEqual(user.opt_lock, user_data["opt_lock"])
        self.assertEqual(user.password_hash, user_data["password_hash"])

        self.user_repository_mock.read_by_user_name.assert_called_once_with(
            "test_user")
Exemplo n.º 2
0
def _create_user_entity(user_name, password, timestamp):
    user = UserEntity()
    user.user_name = user_name
    user.password_hash = security.generate_password_hash(password)
    user.created_on = timestamp
    user.modified_on = timestamp
    user.opt_lock = 0

    return user
Exemplo n.º 3
0
    def test_should_update_user(self):
        # given
        user = UserEntity()
        user.user_name = "test_user"
        user.created_on = datetime.utcnow()
        user.modified_on = datetime.utcnow()
        user.opt_lock = 0

        self.session.add(user)
        self.session.flush()

        # when
        user.password_hash = "test_hash"
        user_repository.persist(user)

        # then
        self.assertEqual(
            "test_hash",
            self.session.query(UserEntity).filter_by(
                user_name="test_user").first().password_hash)