Beispiel #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")
Beispiel #2
0
    def test_should_get_false_when_user_is_not_related_to_campaign(self):
        # given
        campaign = CampaignEntity()
        campaign.id = 99
        campaign.created_on = date(2020, 1, 1)
        campaign.modified_on = date(2020, 1, 1)
        campaign.opt_lock = 0
        campaign.campaign_name = "Test Campaign"
        campaign.begin_date = date(2055, 1, 1)
        campaign.passed_days = 10

        gm = UserEntity()
        gm.id = 77
        gm.created_on = date(2019, 1, 1)
        gm.modified_on = date(2019, 1, 1)
        gm.opt_lock = 0
        gm.user_name = "Test User"

        campaign.game_master = gm

        self.campaign_repository_mock.read_by_id.return_value = campaign

        # when
        result = campaign_service.check_if_user_related_to_campaign(88, 99)

        # then
        self.assertEqual(False, result)
    def test_should_get_all_user_roles(self):
        # given
        user = UserEntity()
        user.id = 1
        user.user_name = "test_user"

        role_1 = UserRoleEntity()
        role_1.id = 1
        role_1.role_name = "test_role_1"
        role_1.user = user

        role_2 = UserRoleEntity()
        role_2.id = 2
        role_2.role_name = "test_role_2"
        role_2.user = user

        self.user_repository_mock.read_by_user_name.return_value = user

        # when
        found_roles = user_roles_service.get_user_roles("test_user")

        # then
        self.assertIsNotNone(found_roles)
        self.assertEqual(2, len(found_roles))
        self.assertIn("test_role_1", found_roles)
        self.assertIn("test_role_2", found_roles)
Beispiel #4
0
    def test_should_get_campaign_details(self):
        # given
        campaign = CampaignEntity()
        campaign.id = 99
        campaign.created_on = datetime(2020, 1, 1, 12, 12, 12)
        campaign.modified_on = datetime(2020, 1, 1, 13, 13, 13)
        campaign.opt_lock = 0
        campaign.campaign_name = "Test Campaign"
        campaign.begin_date = date(2055, 1, 1)
        campaign.passed_days = 10

        gm = UserEntity()
        gm.id = 88
        gm.created_on = date(2019, 1, 1)
        gm.modified_on = date(2019, 1, 1)
        gm.opt_lock = 0
        gm.user_name = "Test User"

        campaign.game_master = gm

        self.campaign_repository_mock.read_by_id.return_value = campaign

        # when
        campaign_details = campaign_service.get_campaign_details(99)

        # then
        self.assertEqual(99, campaign_details["id"])
        self.assertEqual("Test Campaign", campaign_details["title"])
        self.assertEqual("2020-01-01T12:12:12", campaign_details["creationDate"])
        self.assertEqual("2055-01-01", campaign_details["startDate"])
        self.assertEqual(10, campaign_details["passedDays"])
        self.assertEqual("2055-01-11", campaign_details["currentDate"])
        self.assertEqual(88, campaign_details["gameMasterId"])
        self.assertEqual("Test User", campaign_details["gameMasterName"])
Beispiel #5
0
    def test_should_raise_error_when_user_already_exists(self):
        # given
        user = UserEntity()
        user.id = 1
        user.user_name = "test_user"

        self.user_repository_mock.read_by_user_name.return_value = user

        with self.assertRaises(BusinessError):
            user_service.create_user("test_editor", "test_user",
                                     "test_password")