Пример #1
0
 def test_delete_guest(self):
     signed_user_controller = SignedUserController()
     g1 = Guest("0.0.0.1", 23)
     g2 = Guest("0.0.0.2", 46)
     signed_user_controller.add_user(g1)
     signed_user_controller.add_user(g2)
     signed_user_controller.delete_guest(g1.user_ip)
     """ Cannot be deleted """
     signed_user_controller.delete_guest("0.020.1")
     self.assertEqual(1, signed_user_controller.get_guests().__len__())
     self.assertIsNone(signed_user_controller.get_guests().get("0.0.0.1"))
Пример #2
0
 def test_number_of_admins(self):
     signed_user_controller = SignedUserController()
     d1 = datetime.datetime(2020, 4, 23)
     d2 = datetime.datetime(2020, 4, 23)
     self.assertEqual(0, signed_user_controller.number_of_admins())
     signed_user_controller.add_system_admin("name_u1", "1234", "ro", d1,
                                             "0.0.0.5")
     signed_user_controller.add_system_admin("name_u21", "1234", "rso", d2,
                                             "0.0.0.2")
     signed_user_controller.add_fan_to_data("name_u2221", "12334", "rowe",
                                            d2, "0.0.0.1")
     self.assertEqual(2, signed_user_controller.number_of_admins())
Пример #3
0
 def test_show_all_users(self):
     signed_user_controller = SignedUserController()
     signed_user_controller.add_guest("0.0.0.1")
     signed_user_controller.add_guest("0.0.0.3")
     signed_user_controller.add_guest("0.0.0.3")
     d1 = datetime.datetime(2020, 4, 23)
     signed_user_controller.add_signed_user("name_u1", "1234", "ro", d1,
                                            "0.0.0.5")
     l1, l2 = signed_user_controller.show_all_users()
     self.assertEqual(3, l1.__len__() + l2.__len__())
Пример #4
0
 def test_add_search(self):
     signed_user_controller = SignedUserController()
     d1 = datetime.datetime(2020, 4, 23)
     s = SignedUser("name_u1", "1234", "ro", d1, "0.0.0.5", 23)
     signed_user_controller.add_user(s)
     signed_user_controller.add_search(s.user_name, "first massage")
     signed_user_controller.add_search(s.user_name, "second massage")
     self.assertIsNotNone(signed_user_controller)
Пример #5
0
 def test_edit_personal_name(self):
     signed_user_controller = SignedUserController()
     d1 = datetime.datetime(2020, 4, 23)
     signed_user_controller.add_signed_user("name_u1", "1234", "ro", d1,
                                            "0.0.0.5")
     self.assertTrue(
         signed_user_controller.edit_personal_name("name_u1", "moshe"))
     self.assertNotEqual("ro",
                         signed_user_controller.get_user("name_u1").name)
     self.assertEqual("moshe",
                      signed_user_controller.get_user("name_u1").name)
     self.assertFalse(
         signed_user_controller.edit_personal_name("name21", "moshe"))
    def setUp(self):
        # Preparation
        self.team_db = MongoTeamDB()
        self.user_db = MongoUserDB()
        self.team_control = TeamManagementController(self.team_db,
                                                     self.user_db)
        self.user_controller = SignedUserController(self.user_db)

        self.user_controller.add_team_owner('user_nam2', 'password', 'NameB',
                                            date.datetime(1993, 1, 12))
        self.owner = self.user_controller.get_user_by_name('user_nam2')
        self.user_controller.add_team_owner('user_nam3', 'password', 'NameC',
                                            date.datetime(1993, 1, 12))
        self.add_owner = self.user_controller.get_user_by_name('user_nam3')
        self.user_controller.add_team_owner('owner_with_team', 'password',
                                            'owner', date.datetime(1993, 1, 1))
        self.owner_with_team = self.user_controller.get_user_by_name(
            'owner_with_team')

        self.user_controller.add_team_manager('user_nam1', 'password', 'nameA',
                                              date.datetime(1993, 1, 1))
        self.manager = self.user_controller.get_user_by_name('user_nam1')
        self.user_controller.add_team_manager('manager_with_team', 'password',
                                              'manager',
                                              date.datetime(1993, 1, 1))
        self.manager_with_team = self.user_controller.get_user_by_name(
            'manager_with_team')

        self.user_controller.add_player('user_nam4', 'password', 'NameD',
                                        date.datetime(1993, 1, 12))
        self.p1 = self.user_controller.get_user_by_name('user_nam4')
        self.user_controller.add_player('user_nam5', 'password', 'NameE',
                                        date.datetime(1993, 1, 12))
        self.p2 = self.user_controller.get_user_by_name('user_nam5')

        self.team_control.open_new_team("Barca", self.owner.user_id)
        self.team_control.open_new_team("ajax", self.owner_with_team.user_id)

        self.team_control.add_manager_to_team('ajax',
                                              self.manager_with_team.user_id)
Пример #7
0
 def test_add_guest(self):
     signed_user_controller = SignedUserController()
     signed_user_controller.add_guest("0.0.0.1")
     signed_user_controller.add_guest("0.0.0.2")
     self.assertEqual(
         1,
         signed_user_controller.get_guests().get("0.0.0.1").user_id)
     self.assertEqual(
         2,
         signed_user_controller.get_guests().get("0.0.0.2").user_id)
     self.assertIsNone(signed_user_controller.get_guests().get("0.0.02"))
Пример #8
0
 def test_edit_personal_birth_date(self):
     signed_user_controller = SignedUserController()
     d1 = datetime.datetime(2020, 4, 23)
     d2 = datetime.datetime(1998, 4, 23)
     signed_user_controller.add_signed_user("name_u1", "1234", "ro", d1,
                                            "0.0.0.5")
     self.assertTrue(
         signed_user_controller.edit_personal_birth_date("name_u1", d2))
     self.assertNotEqual(
         d1,
         signed_user_controller.get_user("name_u1").birth_date)
     self.assertEqual(d2,
                      signed_user_controller.get_user("name_u1").birth_date)
     self.assertFalse(
         signed_user_controller.edit_personal_birth_date("name21", d1))
Пример #9
0
 def test_add_fan_to_data(self):
     signed_user_controller = SignedUserController()
     d1 = datetime.datetime(2020, 4, 23)
     signed_user_controller.add_fan_to_data("name_u1", "1234", "ro", d1,
                                            "0.0.0.5")
     self.assertTrue(signed_user_controller.get_user("name_u1"))
     self.assertTrue(
         type(signed_user_controller.get_user("name_u1")) is Fan)
Пример #10
0
 def test_confirm_user(self):
     signed_user_controller = SignedUserController()
     d1 = datetime.datetime(2020, 4, 23)
     signed_user_controller.add_system_admin("name_u1", "1234", "ro", d1,
                                             "0.0.0.5")
     self.assertEqual(
         "SystemAdmin",
         signed_user_controller.confirm_user("name_u1", "1234"))
     self.assertFalse(
         signed_user_controller.confirm_user("name_u1", "12345"))
     self.assertFalse(signed_user_controller.confirm_user(
         "name_u2", "1234"))
Пример #11
0
    def __init__(self, admin_user_name, admin_password, admin_name,
                 admin_birth_date, admin_ip):
        self.complaint_db = ComplaintDB()
        self.game_db = GameDB()
        self.league_db = LeagueDB()
        self.season_DB = SeasonDB()
        self.team_db = TeamDB()
        self.user_db = UserDB()
        self.policy_db = PolicyDB()

        self.union_organization = UnionOrganization()

        self.complaint_controller = ComplaintController(self.complaint_db)
        self.league_controller = LeagueController(self.league_db,
                                                  self.season_DB, PolicyDB)
        self.match_controller = MatchController(self.game_db)
        self.user_controller = SignedUserController(self.user_db)
        self.team_controller = TeamManagementController(self.team_db)
        self.union_controller = UnionController(self.union_organization)

        self.user_controller.add_system_admin(admin_user_name, admin_password,
                                              admin_name, admin_birth_date,
                                              admin_ip)
Пример #12
0
 def test_add_referee_to_data(self):
     signed_user_controller = SignedUserController()
     d1 = datetime.datetime(2020, 4, 23)
     signed_user_controller.add_referee_to_data(
         RefereeQualificationEnum.MAIN, "name_u1", "1234", "ro", d1,
         "0.0.0.5")
     self.assertTrue(signed_user_controller.get_user("name_u1"))
     self.assertTrue(
         type(signed_user_controller.get_user("name_u1")) is Referee)
Пример #13
0
 def test_add_system_admin(self):
     """
     test if the admin in the DB
     If we ran all test its check that ID of the guest is not getting up when we got same guest
     @return:
     """
     signed_user_controller = SignedUserController()
     signed_user_controller.add_guest("0.0.0.1")
     d = datetime.datetime(2020, 4, 23)
     signed_user_controller.add_system_admin("name_u0", "1234", "ro", d,
                                             "0.0.0.5")
     self.assertIsNotNone(
         signed_user_controller.get_signed_users().get("name_u0"))
Пример #14
0
 def test_edit_personal_password(self):
     signed_user_controller = SignedUserController()
     d1 = datetime.datetime(2020, 4, 23)
     old_password = "******"
     new_password = "******"
     signed_user_controller.add_signed_user("name_u1", old_password, "ro",
                                            d1, "0.0.0.5")
     self.assertTrue(
         signed_user_controller.edit_personal_password(
             "name_u1", old_password, new_password))
     self.assertNotEqual(
         str(hashlib.sha256(old_password.encode()).hexdigest()),
         signed_user_controller.get_user("name_u1").password)
     self.assertEqual(
         str(hashlib.sha256(new_password.encode()).hexdigest()),
         signed_user_controller.get_user("name_u1").password)
     self.assertFalse(
         signed_user_controller.edit_personal_password(
             "name1", new_password, old_password))
class AcceptanceTestsSignedUser(TestCase):

    # Preparation
    user_db = MongoUserDB()
    controller = SignedUserController(user_db)

    # UC 4.1, UC 5.1, UC 10.1 acceptance tests
    # Personal details update received from user GUI
    def test_update_personal_info(self):

        user_name = 'userName'
        password = '******'

        self.controller.add_fan(user_name, password, 'name',
                                date.datetime(2000, 1, 1))
        user = self.controller.get_user_by_name(user_name)

        # valid details
        valid_name = 'Shahar'
        valid_birth_date = date.datetime(1993, 1, 1)

        # Invalid details
        invalid_name = '123'

        # --- Testing valid input data ---
        # GUI calls to this method in service layer
        self.controller.edit_personal_data(user.user_id, user_name, password,
                                           valid_name, valid_birth_date)
        self.assertEqual(
            self.controller.get_user_by_name(user_name).name, valid_name)
        self.assertEqual(
            self.controller.get_user_by_name(user_name).birth_date,
            valid_birth_date)

        # --- Testing invalid input data ---
        self.assertRaises(ValueError, self.controller.edit_personal_data,
                          user.user_id, user_name, password, invalid_name,
                          valid_birth_date)

        self.controller.delete_signed_user(user.user_id)
from Enums.RefereeQualificationEnum import RefereeQualificationEnum
from Enums.EventTypeEnum import EventTypeEnum

import datetime as date
import csv
""" This class is the controller that connects the server to the Domain """

users_db = MongoUserDB()
team_db = MongoTeamDB()
policy_db = MongoPolicyDB()
league_db = MongoLeagueDB()
season_db = MongoSeasonDB()
game_db = MongoGameDB()
game_event_db = MongoGameEventDB()
league_controller = LeagueController(league_db, season_db, users_db, policy_db)
signed_user_controller = SignedUserController(users_db)
notification_controller = NotificationController(users_db, game_db)
team_management_controller = TeamManagementController(team_db, users_db)
match_controller = MatchController(game_db, users_db, game_event_db, team_db)
if not signed_user_controller.confirm_user('dor', '1234'):
    signed_user_controller.add_system_admin('dor', '1234', 'dor',
                                            date.datetime(1994, 1, 20))

try:
    signed_user_controller.add_team_owner('shahar', '1234', 'shahar',
                                          date.datetime(1993, 1, 1))
    signed_user_controller.add_referee(RefereeQualificationEnum.MAIN, 'oscar',
                                       '1234', 'oscar',
                                       date.datetime(1994, 11, 9))
    main_referee = signed_user_controller.get_user_by_name('oscar')
    owner = signed_user_controller.get_user_by_name('shahar')
Пример #17
0
from datetime import datetime
from Domain.PointsCalculationPolicy import PointsCalculationPolicy
from Domain.GameSchedulePolicy import GameSchedulePolicy
from Domain.TeamBudgetPolicy import TeamBudgetPolicy

user_db = MongoUserDB()
team_db = MongoTeamDB()
league_db = MongoLeagueDB()
policy_db = MongoPolicyDB()
season_db = MongoSeasonDB()
game_db = MongoGameDB()
game_event_db = MongoGameEventDB()

match_cont = MatchController(game_db, user_db, game_event_db, team_db)
team_cont = TeamManagementController(team_db, user_db)
user_con = SignedUserController(user_db)

policy = PointsCalculationPolicy(2, 12, 2, 13)
policy_db.add_point_policy(policy)

# game = game_db.get(1)
# game.remove_event(1)
# game.remove_event(2)
# game.remove_event(3)
# game.remove_event(6)
# game.remove_event(21)
# game.remove_event(22)
# game.remove_event(14)
# game.remove_event(16)
# game.remove_event(17)
# game.remove_event(18)
Пример #18
0
 def test_add_user(self):
     signed_user_controller = SignedUserController()
     d1 = datetime.datetime(2020, 4, 23)
     s_u = SignedUser("name_u1", "1234", "ro", d1, "0.0.0.5", 23)
     g = Guest("0.0.0.1", 23)
     signed_user_controller.add_user(s_u)
     signed_user_controller.add_user(g)
     self.assertEqual(2, (signed_user_controller.get_guests().__len__()) +
                      (signed_user_controller.get_signed_users().__len__()))
     self.assertIsNotNone(
         signed_user_controller.get_signed_users().get("name_u1"))
     self.assertIsNotNone(
         signed_user_controller.get_guests().get("0.0.0.1"))
     self.assertIsNone(
         signed_user_controller.get_signed_users().get("0.0.0.1"))
Пример #19
0
 def test_delete_signed_user(self):
     signed_user_controller = SignedUserController()
     d1 = datetime.datetime(2020, 4, 23)
     d2 = datetime.datetime(1998, 4, 23)
     signed_user_controller.add_signed_user("name_u1", "1234", "ro", d1,
                                            "0.0.0.5")
     signed_user_controller.add_signed_user("name_u2", "1234", "ro", d2,
                                            "0.0.0.6")
     signed_user_controller.delete_signed_user("name_u1")
     signed_user_controller.delete_signed_user("name_u12")
     self.assertEqual(1,
                      signed_user_controller.get_signed_users().__len__())
     self.assertIsNone(
         signed_user_controller.get_signed_users().get("name_u1"))
Пример #20
0
class AcceptanceTestsUnionRepresentor(TestCase):

    league_db = MongoLeagueDB()
    season_db = MongoSeasonDB()
    user_db = MongoUserDB()
    team_db = MongoTeamDB()
    policy_db = MongoPolicyDB()
    league_controller = LeagueController(league_db, season_db, user_db,
                                         policy_db)
    team_controller = TeamManagementController(team_db, user_db)
    user_controller = SignedUserController(user_db)

    pcp = {'win_points': 3, 'tie_points': 0, 'lose_points': -3}

    gsp = {
        'team_games_num': 2,
        'games_per_week': 4,
        'chosen_days': ['S', 'M'],
        'games_stadium_assigning': GameAssigningPoliciesEnum.EQUAL_HOME_AWAY
    }

    tbp = {'min_amount': 50000}

    def setUp(self):

        self.user_controller.add_team_owner('rm_owner', '1234', 'owner',
                                            datetime.now())
        self.rm_owner = self.user_controller.get_user_by_name('rm_owner')
        self.user_controller.add_team_owner('barca_owner', '1234', 'owner',
                                            datetime.now())
        self.barca_owner = self.user_controller.get_user_by_name('barca_owner')
        self.user_controller.add_team_owner('lp_owner', '1234', 'owner',
                                            datetime.now())
        self.lp_owner = self.user_controller.get_user_by_name('lp_owner')
        self.user_controller.add_team_owner('manch_owner', '1234', 'owner',
                                            datetime.now())
        self.manch_owner = self.user_controller.get_user_by_name('manch_owner')

        self.team_controller.open_new_team('Real Madrid',
                                           self.rm_owner.user_id)
        self.team_controller.open_new_team('Barcelona',
                                           self.barca_owner.user_id)
        self.team_controller.open_new_team('Liverpool', self.lp_owner.user_id)
        self.team_controller.open_new_team('Manchester',
                                           self.manch_owner.user_id)

        self.league_controller.create_new_season(2020)
        self.season = self.league_controller.get_season(2020)

        self.league_controller.create_points_policy(3, 0, -3)
        self.points_policy = self.league_controller.get_all_points_policies(
        )[0]
        self.league_controller.create_game_schedule_policy(
            2, 4, GameAssigningPoliciesEnum.EQUAL_HOME_AWAY)
        self.schedule_policy = self.league_controller.get_all_schedule_policies(
        )[0]
        self.league_controller.create_team_budget_policy(50000)
        self.budget_policy = self.league_controller.get_all_budget_policies(
        )[0]

        self.league_controller.create_new_league(
            'Euro', 2020, self.points_policy.policy_id,
            self.schedule_policy.policy_id, self.budget_policy.policy_id)
        self.league = self.league_controller.get_league(
            self.league_db.get_id_counter() - 1)

    def tearDown(self):

        self.league_db.reset_db()
        self.league_controller.delete_points_calculation_policy(
            self.points_policy.policy_id)
        self.league_controller.delete_schedule_calculation_policy(
            self.schedule_policy.policy_id)
        self.league_controller.delete_budget_calculation_policy(
            self.budget_policy.policy_id)
        self.season_db.reset_db()
        self.team_db.reset_db()
        self.user_db.reset_db()

    # U.C 9.1, 9.5
    def test_create_new_league(self):

        self.assertIsInstance(self.league, League)
        self.league.add_teams(
            ['Real Madrid', 'Barcelona', 'Liverpool', 'Manchester'])
        # wrong values
        self.assertRaises(ValueError, self.league_controller.create_new_league,
                          'Euro', 2021, self.points_policy.policy_id + 1,
                          self.schedule_policy.policy_id,
                          self.budget_policy.policy_id)

    # U.C 9.2, 9.4, 9.5
    def test_create_new_season(self):

        self.assertIsInstance(self.season, Season)
        self.assertIn(self.league.league_id,
                      self.league_controller.get_season(2020).leagues)
        # wrong values
        self.assertRaises(ValueError, self.league_controller.create_new_season,
                          2020)

    # U.C 9.5
    def test_create_and_update_points_calculation_policy(self):

        self.assertIsInstance(self.points_policy, PointsCalculationPolicy)

        self.league_controller.create_points_policy(5, 0, -5)

        self.league_controller.update_points_calculation_policy_in_league(
            self.league.league_id,
            self.policy_db.get_points_id_counter() - 1)
        self.league = self.league_controller.get_league(self.league.league_id)
        self.assertEqual(self.policy_db.get_points_id_counter() - 1,
                         self.league.points_calculation_policy)

        self.league_controller.delete_points_calculation_policy(
            self.policy_db.get_points_id_counter() - 1)

    # U.C 9.6
    def test_create_and_update_game_schedule_policy(self):

        self.assertIsInstance(self.schedule_policy, GameSchedulePolicy)

        self.league_controller.create_game_schedule_policy(
            5, 5, GameAssigningPoliciesEnum.RANDOM)

        self.league_controller.update_game_schedule_policy_in_league(
            self.league.league_id,
            self.policy_db.get_schedule_id_counter() - 1)
        self.league = self.league_controller.get_league(self.league.league_id)
        self.assertEqual(self.policy_db.get_schedule_id_counter() - 1,
                         self.league.game_schedule_policy)

        self.league_controller.delete_schedule_calculation_policy(
            self.policy_db.get_schedule_id_counter() - 1)

    # U.C 9.8
    def test_create_and_update_team_budget_policy(self):

        self.assertIsInstance(self.budget_policy, TeamBudgetPolicy)

        self.league_controller.create_team_budget_policy(10000)

        self.league_controller.update_team_budget_policy_in_league(
            self.league.league_id,
            self.policy_db.get_budget_id_counter() - 1)
        self.league = self.league_controller.get_league(self.league.league_id)
        self.assertEqual(self.policy_db.get_budget_id_counter() - 1,
                         self.league.team_budget_policy)

        self.league_controller.delete_budget_calculation_policy(
            self.policy_db.get_budget_id_counter() - 1)

    # U.U 9.9
    def test_manage_union_budget(self):

        self.team_controller.add_income_to_team('Real Madrid', 10000, 'income')
        t1 = self.team_controller.get_team('Real Madrid')
        self.team_controller.add_income_to_team("Barcelona", 2000, 'income')
        t2 = self.team_controller.get_team("Barcelona")

        organization = UnionOrganization()
        union_controller = UnionController(organization, self.user_db,
                                           self.team_db, 5000)
        union_controller.add_team_to_union(t1.name)
        union_controller.add_team_to_union(t2.name)

        union_controller.add_income(10000, '')
        self.assertEqual(10000, organization.balance)
        # wrong value
        self.assertRaises(ValueError, union_controller.add_income, -10000, '')

        union_controller.add_expense(10000, '')
        self.assertEqual(0, organization.balance)
        # wrong value
        self.assertRaises(ValueError, union_controller.add_expense, -10000, '')

        self.assertIn(t2.name, organization.teams_in_union)
        union_controller.collect_registration_fee()
        self.assertEqual(5000, organization.balance)
        self.assertIn(t1.name, organization.teams_in_union)
        self.assertNotIn(t2.name, organization.teams_in_union)

        self.user_controller.add_union_representor('Dor123', '12345678', 'Dor',
                                                   datetime(1990, 8, 8), 2000)
        representor = self.user_controller.get_user_by_name('Dor123')
        organization.add_employee_to_union(representor.user_id)
        union_controller.pay_employees()
        self.assertEqual(3000, organization.balance)
        union_controller.remove_employee_from_union(representor.user_id)
        union_controller.remove_team_from_union(t1.name)
        self.user_controller.delete_signed_user(representor.user_id)
        organization.reset_organization()
Пример #21
0
 def test_add_signed_user(self):
     signed_user_controller = SignedUserController()
     signed_user_controller.add_guest("0.0.0.1")
     signed_user_controller.add_guest("0.0.0.1")
     d1 = datetime.datetime(2020, 4, 23)
     d2 = datetime.datetime(1998, 4, 23)
     signed_user_controller.add_signed_user("name_u1", "1234", "ro", d1,
                                            "0.0.0.5")
     signed_user_controller.add_signed_user("name_u2", "1234", "ro", d2,
                                            "0.0.0.6")
     self.assertIsNotNone(
         signed_user_controller.get_signed_users().get("name_u1").user_id)
     self.assertEqual(3, (signed_user_controller.get_guests().__len__()) +
                      (signed_user_controller.get_signed_users().__len__()))
Пример #22
0
class AcceptanceTestsReferee(TestCase):
    # Preparation
    game_db = MongoGameDB()
    user_db = MongoUserDB()
    team_db = MongoTeamDB()
    game_event_db = MongoGameEventDB()

    match_controller = MatchController(game_db, user_db, game_event_db,
                                       team_db)
    team_controller = TeamManagementController(team_db, user_db)
    user_controller = SignedUserController(user_db)

    d_now = datetime.now()
    owner1 = None
    owner2 = None
    main_referee = None
    referee = None
    referee2 = None
    referee3 = None
    game1 = None
    game2 = None
    game_event = None

    def setUp(self):

        self.user_controller.add_team_owner('owner', '1234', 'owner',
                                            datetime.now())
        self.user_controller.add_team_owner('owner2', '1234', 'otherowner',
                                            datetime.now())
        self.owner1 = self.user_controller.get_user_by_name('owner')
        self.owner2 = self.user_controller.get_user_by_name('owner2')

        self.team_controller.open_new_team('team1', self.owner1.user_id)
        self.team_controller.open_new_team('team2', self.owner2.user_id)

        self.user_controller.add_referee(RefereeQualificationEnum.MAIN,
                                         'S123', '12345678', 'Sas',
                                         datetime(1990, 8, 8))
        self.user_controller.add_referee(RefereeQualificationEnum.REGULAR,
                                         'S12', '12345678', 'Sde',
                                         datetime(1990, 8, 8))
        self.user_controller.add_referee(RefereeQualificationEnum.MAIN, 'S13',
                                         '12345678', 'Swqed',
                                         datetime(1990, 8, 8))
        self.user_controller.add_referee(RefereeQualificationEnum.REGULAR,
                                         'S23', '12345678', 'Saf',
                                         datetime(1990, 8, 8))

        self.main_referee = self.user_controller.get_user_by_name('S123')
        self.referee = self.user_controller.get_user_by_name('S12')
        self.referee2 = self.user_controller.get_user_by_name('S13')
        self.referee3 = self.user_controller.get_user_by_name('S23')

        self.match_controller.add_game('team1', 'team2', self.d_now, '',
                                       self.main_referee.user_id,
                                       [self.referee.user_id])
        self.game1 = self.match_controller.get_game(
            self.game_db.get_id_counter() - 1)
        self.match_controller.add_game('team1', 'team2', datetime(2021, 4, 23),
                                       '', self.referee2.user_id, [])
        self.game2 = self.match_controller.get_game(
            self.game_db.get_id_counter() - 1)

        self.match_controller.start_game(self.game1.game_id)
        self.match_controller.add_event(self.game1.game_id,
                                        self.main_referee.user_id,
                                        EventTypeEnum.GOAL,
                                        'Goal to home team',
                                        datetime(2020, 4, 4), 90)
        self.game_event = self.match_controller.get_event(
            self.game_event_db.get_id_counter() - 1)

    def tearDown(self):

        self.match_controller.remove_event(self.game_event.event_id)
        self.match_controller.remove_game(self.game2.game_id)
        self.match_controller.remove_game(self.game1.game_id)
        self.user_controller.delete_signed_user(self.referee3.user_id)
        self.user_controller.delete_signed_user(self.referee2.user_id)
        self.user_controller.delete_signed_user(self.referee.user_id)
        self.user_controller.delete_signed_user(self.main_referee.user_id)
        self.team_controller.delete_team('team1')
        self.team_controller.delete_team('team2')
        self.user_controller.delete_signed_user(self.owner1.user_id)
        self.user_controller.delete_signed_user(self.owner2.user_id)

    # UC 10.2
    def test_watch_games(self):
        # --- Referee want to see future assigned games ---
        game_list = self.match_controller.show_ongoing_games_by_referee(
            self.main_referee.user_id)
        self.assertEqual(game_list[-1].game_id, self.game1.game_id)

        # --- Referee want to see future assigned games without having any ---
        game_list = self.match_controller.show_games_by_referee(
            self.referee3.user_id)
        self.assertEqual(len(game_list), 0)

    # UC 10.3
    def test_update_ongoing_game_events(self):

        # Referee get list of games to choose from
        game_list = self.match_controller.show_ongoing_games_by_referee(
            self.main_referee.user_id)
        game_chosen = game_list[0]

        # Referee gets a list of game events to choose from
        game_events_list = game_chosen.events
        self.assertEqual(len(game_events_list), 1)
        game_event_chosen = self.match_controller.get_event(
            game_events_list[0])

        # Update game event by user input
        self.match_controller.edit_event(
            game_event_chosen.event_id,
            event_description='Red card for Oscar',
            event_type=EventTypeEnum.RED_CARD,
            date=datetime.now(),
            min_in_game=20)

        self.assertEqual(
            self.match_controller.get_event(
                self.game_event.event_id).event_description,
            'Red card for Oscar')
        self.assertEqual(
            self.match_controller.get_event(
                self.game_event.event_id).min_in_game, 20)

        # --- Referee trying to add game event to ongoing game without being assigned to one ---

        # Referee get list of games to choose from
        game_list = self.match_controller.show_ongoing_games_by_referee(
            self.referee2.user_id)
        self.assertEqual(len(game_list), 0)

    # UC 10.4
    def test_update_finished_game_events(self):
        self.match_controller.end_game(self.game1.game_id)

        # Main referee get list of games to choose from
        game_list = self.match_controller.show_games_by_referee(
            self.main_referee.user_id)
        game_chosen = game_list[0]

        # Main referee gets a list of game events to choose from
        game_events_list = game_chosen.events
        self.assertEqual(len(game_events_list), 1)
        game_event_chosen = self.match_controller.get_event(
            game_events_list[0])

        # Update game event by user input
        self.match_controller.edit_event(
            game_event_chosen.event_id,
            event_type=EventTypeEnum.YELLOW_CARD,
            event_description='Yellow card for Shahar',
            date=self.d_now,
            min_in_game=50)
        self.assertEqual(
            self.match_controller.get_event(
                game_event_chosen.event_id).event_description,
            'Yellow card for Shahar')
        self.assertEqual(
            self.match_controller.get_event(
                game_event_chosen.event_id).min_in_game, 50)

        # --- Normal referee trying to edit finished game events ---

        # Referee get list of games to choose from
        game_list = self.match_controller.show_games_by_referee(
            self.referee.user_id)
        self.assertEqual(len(game_list), 0)
class AcceptanceTestsOwnerManager(TestCase):
    def setUp(self):
        # Preparation
        self.team_db = MongoTeamDB()
        self.user_db = MongoUserDB()
        self.team_control = TeamManagementController(self.team_db,
                                                     self.user_db)
        self.user_controller = SignedUserController(self.user_db)

        self.user_controller.add_team_owner('user_nam2', 'password', 'NameB',
                                            date.datetime(1993, 1, 12))
        self.owner = self.user_controller.get_user_by_name('user_nam2')
        self.user_controller.add_team_owner('user_nam3', 'password', 'NameC',
                                            date.datetime(1993, 1, 12))
        self.add_owner = self.user_controller.get_user_by_name('user_nam3')
        self.user_controller.add_team_owner('owner_with_team', 'password',
                                            'owner', date.datetime(1993, 1, 1))
        self.owner_with_team = self.user_controller.get_user_by_name(
            'owner_with_team')

        self.user_controller.add_team_manager('user_nam1', 'password', 'nameA',
                                              date.datetime(1993, 1, 1))
        self.manager = self.user_controller.get_user_by_name('user_nam1')
        self.user_controller.add_team_manager('manager_with_team', 'password',
                                              'manager',
                                              date.datetime(1993, 1, 1))
        self.manager_with_team = self.user_controller.get_user_by_name(
            'manager_with_team')

        self.user_controller.add_player('user_nam4', 'password', 'NameD',
                                        date.datetime(1993, 1, 12))
        self.p1 = self.user_controller.get_user_by_name('user_nam4')
        self.user_controller.add_player('user_nam5', 'password', 'NameE',
                                        date.datetime(1993, 1, 12))
        self.p2 = self.user_controller.get_user_by_name('user_nam5')

        self.team_control.open_new_team("Barca", self.owner.user_id)
        self.team_control.open_new_team("ajax", self.owner_with_team.user_id)

        self.team_control.add_manager_to_team('ajax',
                                              self.manager_with_team.user_id)

    def tearDown(self):

        self.team_control.delete_team('Barca')
        self.team_control.delete_team('ajax')

        self.user_controller.delete_signed_user(self.owner.user_id)
        self.user_controller.delete_signed_user(self.add_owner.user_id)
        self.user_controller.delete_signed_user(self.owner_with_team.user_id)

        self.user_controller.delete_signed_user(self.manager.user_id)
        self.user_controller.delete_signed_user(self.manager_with_team.user_id)

        self.user_controller.delete_signed_user(self.p1.user_id)
        self.user_controller.delete_signed_user(self.p2.user_id)

    """ Testing adding a new team member,list of members
       and  deletion of list and one member"""

    # UC 6.1.1
    """Testing adding player info"""

    def test_add_team_member_to_team(self):
        # acceptance
        test_team = self.team_control.get_team('Barca')
        # add player
        self.team_control.add_team_member_to_team("Barca", self.p1.user_id)
        test_team = self.team_control.get_team('Barca')
        self.assertTrue(self.p1.user_id in test_team.team_members)
        # Message presented

        # not acceptance
        # add player not correct input will be will be in the GUI
        # Message presented that values incorrect

        # not acceptance
        # adding team member already in a team
        self.assertRaises(ValueError,
                          self.team_control.add_team_member_to_team, "Barca",
                          self.p1.user_id)

    # UC 6.1.2
    """Testing edit player info"""

    def test_update_asset_acceptance(self):
        # acceptance
        # Owner chose update a coach or player:
        # The owner can update only attribute effected by the team
        # owner choose edit certain team member
        # Message presented are you sure
        # If agrees updates
        self.team_control.set_number_to_player(self.p1.user_id, "9")
        self.p1 = self.user_controller.get_user_by_id(self.p1.user_id)
        self.assertTrue(self.p1.role.number == "9")
        self.team_control.set_position_to_player(self.p1.user_id, "9")
        self.p1 = self.user_controller.get_user_by_id(self.p1.user_id)
        self.assertTrue(self.p1.role.position == "9")

        self.team_control.set_stadium_to_team("Barca", "Camp")
        self.assertTrue(self.team_control.get_team("Barca").stadium == "Camp")
        # Message presented

        # not acceptance
        # owner choose edit certain team member
        # Message presented are you sure
        # owner disagree nothing happened

    # UC 6.1.3
    """Testing remove asset """

    def test_remove_team_asset(self):
        # acceptance
        # add player
        self.team_control.add_team_member_to_team("Barca", self.p2.user_id)
        # preparation for UC
        self.assertTrue(self.p2.user_id in self.team_control.get_team(
            "Barca").team_members)
        # owner goes to remove member
        # Gui Ask if he is sure
        # owner agree ,remove player
        self.team_control.remove_team_member_from_team("Barca",
                                                       self.p2.user_id)
        self.assertFalse(self.p2.user_id in self.team_control.get_team(
            "Barca").team_members)

        # not acceptance
        self.team_control.add_team_member_to_team("Barca", self.p2.user_id)
        # preparation for UC
        self.assertTrue(self.p2.user_id in self.team_control.get_team(
            "Barca").team_members)
        # owner goes to remove member
        # Gui Ask if he is sure
        # owner disagree
        self.assertTrue(self.p2.user_id in self.team_control.get_team(
            "Barca").team_members)
        # nothing happens

    # UC 6.2 add Set team additional owner
    def test_add_team_owner(self):
        self.assertEqual(1, len(self.team_control.get_team_owners('Barca')))
        # owner choose to add owner to the team
        # user accept
        self.team_control.add_owner_to_team("Barca", self.add_owner.user_id)
        # message presented by gui
        self.assertEqual(2, len(self.team_control.get_team_owners('Barca')))
        # not acceptance
        # manager trying to add owner that already in a team
        self.assertRaises(ValueError, self.team_control.add_owner_to_team,
                          "Barca", self.owner_with_team.user_id)
        # message presented

    # UC 6.3 remove additional owner
    def test_remove_owner_acceptance(self):
        # preparation for UC
        self.team_control.add_owner_to_team("Barca", self.add_owner.user_id)
        # owner choose team manager in the team
        # Gui ask if he is sure
        self.team_control.remove_owner_from_team("Barca",
                                                 self.add_owner.user_id)
        self.assertEqual(1, len(self.team_control.get_team_owners("Barca")))

    def test_remove_owner_not_acceptance(self):
        # Manager try to delete team without add owner
        self.assertRaises(Exception, self.team_control.remove_owner_from_team,
                          "Barca", self.owner.user_id)
        # Get Gui message says there is no manager to delete

    # UC 6.4 add Set team Manager
    def test_add_team_manager_acceptance(self):
        # owner choose to add manager to the team
        # user accept
        self.team_control.add_manager_to_team("Barca", self.manager.user_id)
        # message presented by gui
        self.assertEqual(1, len(self.team_control.get_team_managers('Barca')))

    def test_add_team_manager_not_acceptance(self):
        # owner choose to add manager already has a Manager /owner role in a team
        self.assertRaises(ValueError, self.team_control.add_manager_to_team,
                          "Barca", self.manager_with_team.user_id)
        # The system dont allow to add the manager and present message

    # UC 6.5 remove Team manager
    def test_remove_team_manager_acceptance(self):
        # preparation for UC
        self.team_control.add_manager_to_team("Barca", self.manager.user_id)
        # owner choose team manager in the team
        # Gui ask if he is sure
        self.team_control.remove_manager_from_team("Barca",
                                                   self.manager.user_id)
        self.assertEqual(0, len(self.team_control.get_team_managers("Barca")))

    def test_remove_team_manager_not_acceptance(self):
        # Manager try to delete team without manger
        self.assertRaises(ValueError,
                          self.team_control.remove_manager_from_team, "Barca",
                          self.manager.user_id)
        # Get Gui message says there is no manager to delete

    # UC 6.6.1 Close Team
    def test_close_team_acceptance(self):
        # Owner chose close team
        test_team = self.team_control.get_team("Barca")
        self.assertTrue(test_team.is_open)
        # chose option to close
        # GUI ask if you sure
        self.team_control.close_team("Barca")
        test_team = self.team_control.get_team("Barca")
        self.assertFalse(test_team.is_open)
        # message presented
        # all the team get notify

    def test_close_team_not_acceptance(self):
        # Owner chose  close team
        test_team = self.team_control.get_team("Barca")
        self.assertTrue(test_team.is_open)
        # chose option to close
        # GUI ask if you sure
        # owner choose not to close
        # nothing happen

        # UC 6.6.1 Close Team

    def test_open_team_acceptance(self):
        # prepertion
        self.team_control.close_team("Barca")
        # Owner open  close team
        test_team = self.team_control.get_team("Barca")
        self.assertFalse(test_team.is_open)
        # chose option to open
        # GUI ask if you sure
        self.team_control.reopen_team("Barca")
        test_team = self.team_control.get_team("Barca")
        self.assertTrue(test_team.is_open)
        # message presented
        # all the team get notify

    def test_open_team_not_acceptance(self):
        # prepertion
        self.team_control.close_team("Barca")
        # Owner open  close team
        test_team = self.team_control.get_team("Barca")
        self.assertFalse(test_team.is_open)
        # chose option to open
        # GUI ask if you sure
        # owner choose not to open
        # nothing happen

    # UC 6.7.1 Add expanse
    def test_add_income_acceptance(self):
        # Owner chose add income
        # fill in correct input
        self.team_control.add_income_to_team("Barca", 500, "Sponsorship")
        self.assertTrue("+,500, Sponsorship" in
                        self.team_control.get_team_incomes("Barca"))
        # Message presented by GUI

    def test_add_income_not_acceptance(self):
        # Owner chose add income
        # fill in incorrect input
        self.assertRaises(ValueError, self.team_control.add_income_to_team,
                          "Barca", -500, "Sponsorship")
        # Message presented by GUI

    # UC 6.7.2 Add expanse
    def test_add_expanse_acceptance(self):
        # Owner chose add expanse
        # fill in incorrect input
        self.team_control.add_income_to_team("Barca", 500, "Sponsorship")
        self.team_control.add_expanse_to_team("Barca", 499, "Sponsorship")
        self.assertTrue("-,499, Sponsorship" in
                        self.team_control.get_team_expanses("Barca"))
        # Message presented by GUI

    def test_add_expanse_not_acceptance(self):
        # Owner chose add expanse
        # fill in incorrect input
        self.assertRaises(ValueError, self.team_control.add_expanse_to_team,
                          "Barca", -500, "Sponsorship")
Пример #24
0
class AcceptanceTestsFan(TestCase):

    # Preparation

    user_db = MongoUserDB()
    user_controller = SignedUserController(user_db)
    page_db = MongoPageDB()
    page_controller = PageController(page_db)
    game_db = MongoGameDB()
    game_event_db = MongoGameEventDB()
    team_db = MongoTeamDB()
    team_controller = TeamManagementController(team_db, user_db)
    match_controller = MatchController(game_db, user_db, game_event_db,
                                       team_db)
    complaint_db = MongoComplaintDB()
    complaint_controller = ComplaintController(complaint_db, user_db)
    notification_controller = NotificationController(user_db, game_db)

    team_owner1 = None
    team_owner2 = None
    referee = None
    fan = None
    game = None
    page = None
    team1 = None
    team2 = None

    def setUp(self):

        self.user_controller.add_team_owner('owner', '1234', 'name',
                                            date.datetime.now())
        self.user_controller.add_team_owner('owner2', '1234', 'othername',
                                            date.datetime.now())
        self.user_controller.add_referee(RefereeQualificationEnum.MAIN,
                                         'referee', '1234', 'referee',
                                         date.datetime.now())

        self.team_owner1 = self.user_controller.get_user_by_name('owner')
        self.team_owner2 = self.user_controller.get_user_by_name('owner2')
        self.referee = self.user_controller.get_user_by_name('referee')

        self.team_controller.open_new_team('Hapoel beer sheva',
                                           self.team_owner1.user_id)
        self.team_controller.open_new_team('Maccabi Tel Aviv',
                                           self.team_owner2.user_id)

        self.match_controller.add_game('Hapoel beer sheva', 'Maccabi Tel Aviv',
                                       date.datetime(2020, 4, 23), "",
                                       self.referee.user_id)
        self.game = self.match_controller.get_game(
            self.game_db.get_id_counter() - 1)

        self.user_controller.add_fan('fan', '1234', 'fan',
                                     date.datetime(2020, 4, 23))
        self.fan = self.user_controller.get_user_by_name('fan')

        self.page_controller.add_page('MaorMelikson')
        self.page = self.page_controller.get_page(
            self.page_db.get_id_counter() - 1)

    def tearDown(self):

        self.team_controller.delete_team('Hapoel beer sheva')
        self.team_controller.delete_team('Maccabi Tel Aviv')
        self.user_controller.delete_signed_user(self.fan.user_id)
        self.match_controller.remove_game(self.game.game_id)
        self.page_controller.remove_page(self.page.page_id)
        self.user_controller.delete_signed_user(self.team_owner1.user_id)
        self.user_controller.delete_signed_user(self.team_owner2.user_id)
        self.user_controller.delete_signed_user(self.referee.user_id)

    # UC 3.2
    # TODO: Implement and test
    # def test_follow_page(self):
    #     # fan looks for the page MaorMelikson and the system retrieves it
    #     page = self.page_controller.search_personal_page('MaorMelikson')
    #     # fan follows the page
    #     self.fan.follow_page(page.page_id)
    #     self.assertEqual(page.page_id, self.fan.followed_pages[0])
    #
    #     # the fan looks for the page GilSasover which is not in the page DB
    #     self.assertRaises(ValueError, self.page_controller.search_personal_page, 'GilSasover')

    # UC 3.3 -> game status is missing in order to check this UC
    def test_follow_game(self):
        # fan looks for a game to follow and the system retrieves it
        games = self.match_controller.all_games()
        self.assertEqual(1, len(games))

        # fan follows the chosen game
        self.notification_controller.add_fan_follower_to_game(
            self.fan.user_id, self.game.game_id)

        # trying to follow same game twice
        self.assertRaises(
            ValueError, self.notification_controller.add_fan_follower_to_game,
            self.fan.user_id, self.game.game_id)

        self.fan = self.user_controller.get_user_by_id(self.fan.user_id)
        self.assertEqual(self.game.game_id, self.fan.followed_games[0])

    # UC 3.4
    def test_complain(self):

        self.complaint_controller.new_complaint('RoniLevi page is not correct',
                                                self.fan.user_id)
        self.fan = self.user_controller.get_user_by_id(self.fan.user_id)
        self.assertEqual(self.fan.complaints[0],
                         self.complaint_db.get_id_counter() - 1)

    # UC 3.5 -> no search history in fan yet
    def test_show_history(self):
        pass

    # UC 3.6
    def test_edit_personal_info(self):

        # fan wants to edit his personal information
        self.user_controller.edit_personal_data(self.fan.user_id,
                                                'new_user_name', 'new_pass',
                                                'idan',
                                                date.datetime(2000, 1, 1))
        self.fan = self.user_controller.get_user_by_id(self.fan.user_id)
        self.assertEqual(self.fan.user_name, 'new_user_name')
        self.assertEqual(self.fan.name, 'idan')
        self.assertEqual(self.fan.birth_date, date.datetime(2000, 1, 1))
Пример #25
0
 def test_get_user(self):
     signed_user_controller = SignedUserController()
     d1 = datetime.datetime(2020, 4, 23)
     s = SignedUser("name_u1", "1234", "ro", d1, "0.0.0.5", 23)
     signed_user_controller.add_user(s)
     self.assertEqual(s, signed_user_controller.get_user(s.user_name))
Пример #26
0
class AcceptanceTestsSystemAdmin(TestCase):
    # Preparation
    user_db = MongoUserDB()
    team_db = MongoTeamDB()
    complaint_db = MongoComplaintDB()
    user_controller = SignedUserController(user_db)
    complaint_controller = ComplaintController(complaint_db, user_db)
    team_controller = TeamManagementController(team_db, user_db)

    fan = None
    team_owner = None
    system_admin = None
    complaint = None
    answer = 'complaint ans'

    def setUp(self):

        self.user_controller.add_team_owner('user_name', 'password', 'name',
                                            date.datetime(1980, 5, 5))
        self.team_owner = self.user_controller.get_user_by_name('user_name')
        self.user_controller.add_fan('fan', '1234', 'name',
                                     date.datetime(1993, 1, 9))
        self.fan = self.user_controller.get_user_by_name('fan')
        self.team_controller.open_new_team('Tiberias', self.team_owner.user_id)
        self.complaint_controller.new_complaint('first comp', self.fan.user_id)
        self.complaint = self.complaint_controller.get_complaint(
            self.complaint_db.get_id_counter() - 1)

    def tearDown(self):

        self.team_controller.delete_team('Tiberias')
        self.user_controller.delete_signed_user(self.team_owner.user_id)
        self.user_controller.delete_signed_user(self.fan.user_id)
        self.complaint_controller.delete_complaint(self.complaint.complaint_id)

    # UC 1.1
    def test_init_system(self):
        """we init the DataBase in set up function ^ """
        d2 = date.datetime(1998, 4, 23)
        self.user_controller.add_system_admin("admin", "1234", "ro", d2)
        admin = self.user_controller.get_user_by_name('admin')
        self.assertTrue(self.user_controller.confirm_user('admin', '1234'))
        self.assertRaises(AssertionError,
                          self.user_controller.delete_signed_user,
                          admin.user_id)
        self.user_db.delete_user(admin.user_id)

    def test_init_system_no_acceptance(self):
        """we init the DataBase in set up function ^ """
        d2 = date.datetime(1998, 4, 23)
        self.assertRaises(ValueError, self.user_controller.add_system_admin,
                          "", "1234", "ro", d2)

    # UC 8.1
    def test_close_team(self):
        """admin is connected and chose what team he wants to close"""
        all_teams = self.team_controller.get_all_teams()
        self.assertEqual(len(all_teams), 1)
        """admin see only the team that in the system"""
        """if admin want to exit he press on exit and stop here"""
        self.team_controller.close_team("Tiberias")
        self.assertFalse(self.team_controller.get_team("Tiberias").is_open)

    #UC 8.2
    def test_remove_signed_user(self):
        """ Admin in connected and want to close team """
        d1 = date.datetime(2020, 4, 23)
        d2 = date.datetime(1998, 4, 23)
        self.user_controller.add_fan("name_u1", "1234", "ro", d1)
        self.user_controller.add_fan("admin", "1234", "ro", d2)
        fan = self.user_controller.get_user_by_name('name_u1')
        fan2 = self.user_controller.get_user_by_name('admin')
        self.user_controller.delete_signed_user(fan.user_id)
        self.assertFalse(self.user_controller.confirm_user('name_u1', '1234'))
        self.assertTrue(self.user_controller.confirm_user('admin', '1234'))
        self.user_controller.delete_signed_user(fan2.user_id)

    # UC 8.3
    def test_show_complaint_and_respond(self):
        # admin wants to see all user complaints
        complaints = self.complaint_controller.show_complaints()
        com = self.complaint_db.get_all()
        self.assertEqual(com[0].answer, complaints[0].answer)
        # admin chooses a complaint to answer on
        self.complaint = self.complaint_controller.get_complaint(
            complaints[0].complaint_id)
        # admin responds to the complaint as he should
        self.complaint_controller.respond_to_complaint(
            self.answer, complaints[0].complaint_id)
        self.complaint = self.complaint_controller.get_complaint(
            complaints[0].complaint_id)
        self.assertEqual(self.complaint.answer, self.answer)