Пример #1
0
    def test_user_profile_without_teams_returns_empty_team_list(self):
        data = MagicMock()
        '''Mocked outputs'''
        user = MagicMock()
        user.id = 1
        user.team_id = None
        user.username = "******"

        sys.modules[
            "models.authentication"].Authenticator.authenticate.return_value = user
        sys.modules["daos.teams"].TeamDatabaseClient.get_user_teams_by_user_id.return_value = []
        sys.modules[
            "daos.users"].UserDatabaseClient.get_user_profile.return_value = [
                user
            ]

        response = UserService.user_profile(data)
        self.assertEqual(1, response.client.id)
        self.assertEqual("TEST", response.client.username)
        self.assertEqual(0, len(response.client.teams))
        self.assertIsInstance(response, SuccessfulFullUserResponse)
Пример #2
0
    def test_user_profile_with_two_teams_returns_full_list(self):
        data = MagicMock()
        '''Mocked outputs'''
        user = User(user_id=0, username="******")
        teams = [Team(team_id=1, name="TEST1"), Team(team_id=2, name="TEST2")]
        user_with_teams1 = MagicMock()
        user_with_teams1.id = 0
        user_with_teams1.username = "******"
        user_with_teams1.team_id = 1
        user_with_teams1.team_name = "TEST1"
        user_with_teams1.team_role = "CREATOR"
        user_with_teams2 = MagicMock()
        user_with_teams2.id = 0
        user_with_teams2.username = "******"
        user_with_teams2.team_id = 2
        user_with_teams2.team_name = "TEST2"
        user_with_teams2.team_role = "MEMBER"
        user_with_teams = [user_with_teams1, user_with_teams2]

        sys.modules[
            "models.authentication"].Authenticator.authenticate.return_value = user
        sys.modules[
            "daos.teams"].TeamDatabaseClient.get_user_teams_by_user_id.return_value = teams
        sys.modules[
            "daos.users"].UserDatabaseClient.get_user_profile.return_value = user_with_teams

        response = UserService.user_profile(data)
        self.assertEqual(0, response.client.id)
        self.assertEqual("TEST", response.client.username)
        self.assertEqual(2, len(response.client.teams))
        self.assertEqual(1, response.client.teams[0]["id"])
        self.assertEqual("TEST1", response.client.teams[0]["name"])
        self.assertEqual("CREATOR", response.client.teams[0]["role"])
        self.assertEqual(2, response.client.teams[1]["id"])
        self.assertEqual("TEST2", response.client.teams[1]["name"])
        self.assertEqual("MEMBER", response.client.teams[1]["role"])
        self.assertIsInstance(response, SuccessfulFullUserResponse)