Example #1
0
    def test_should_get_user_by_id(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_id.return_value = user

        # when
        user_data = user_service.get_user_by_id(1)

        # 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_id.assert_called_once_with(1)
Example #2
0
    def test_should_get_none_when_user_does_not_exist(self):
        # given
        self.user_repository_mock.read_by_id.return_value = None

        # when
        user_data = user_service.get_user_by_id(1)

        # then
        self.assertIsNone(user_data)
Example #3
0
def get_campaigns_by_gm_id(gm_id):
    """
    Get the campaigns belonging to the game master of the given ID.
    """

    validate_int_arg(gm_id, "ID mistrza gry")

    if user_service.get_user_by_id(gm_id) is None:
        raise BusinessError(f"Użytkownik o ID {gm_id} nie istnieje!")

    campaigns = campaign_repository.read_by_gm_id(gm_id)

    result = list()

    for campaign in campaigns:
        result.append(_map_campaign_to_dict(campaign))

    return result
Example #4
0
 def test_should_get_value_error_when_user_id_is_not_str(self):
     # when then
     with self.assertRaises(ValueError):
         user_service.get_user_by_id("1")
Example #5
0
 def test_should_get_business_error_when_user_id_is_none(self):
     # when then
     with self.assertRaises(BusinessError):
         user_service.get_user_by_id(None)