Ejemplo n.º 1
0
 def test_create_player_stat(self):
     TestTime.set_app_time(datetime.datetime(2015, 8, 1))
     DatabaseUtils.recreate_database(DatabaseUtils.get_db_connection())
     conn = DatabaseUtils.get_db_connection()
     player_data = {
         'clan_id': 1,
         'account_id': 777,
         'account_name': 'test player',
         'total_resources_earned': 1200,
         'stronghold_skirmish_battles': 100,
         'stronghold_defense_battles': 10,
         'seven_day_resources_earned': 320,
         'thirty_day_resources_earned': 320,
         'last_update': AppTime.get_now(),
         'thirty_day_defense_battles': 0,
         'thirty_day_skirmish_battles': 0,
         'clan_battles': 10,
         'thirty_day_clan_battles': 5,
         'all_battles': 100,
         'thirty_day_all_battles': 50
     }
     controller = ClanController()
     controller.create_player_stat(conn, player_data)
     row = PlayerRepository.get_player(conn, player_data['clan_id'],
                                       player_data['account_id'])
     player_stat_dict = dict(zip(row.keys(), row))
     expected = {
         'clan_id': 1,
         'account_id': 777,
         'account_name': u'test player',
         'total_resources_earned': 1200,
         'stronghold_skirmish_battles': 100,
         'thirty_day_skirmish_battles': 0,
         'stronghold_defense_battles': 10,
         'thirty_day_defense_battles': 0,
         'seven_day_resources_earned': 320,
         'thirty_day_resources_earned': 320,
         'clan_battles': 10,
         'thirty_day_clan_battles': 5,
         'all_battles': 100,
         'thirty_day_all_battles': 50,
         'last_update': str(AppTime.get_now())
     }
     self.assertEqual(expected, player_stat_dict)
     from_date = AppTime.get_now()
     to_date = from_date - datetime.timedelta(days=30)
     rows = PlayerRepository.get_player_stats(conn, player_data['clan_id'],
                                              player_data['account_id'],
                                              from_date, to_date)
     self.assertEqual(1, len(rows))
     player_stat_snapshot_dict = dict(zip(rows[0].keys(), rows[0]))
     expected = {
         'stronghold_defense_battles': 10,
         'account_id': 777,
         'stronghold_skirmish_battles': 100,
         'clan_id': 1,
         'total_resources_earned': 1200,
         'created_date': str(AppTime.get_now())
     }
     self.assertEqual(expected, player_stat_snapshot_dict)
Ejemplo n.º 2
0
 def test_player_requires_calculation(self):
     TestTime.set_app_time(datetime.datetime(2015, 8, 1))
     player_data = {'last_update': datetime.datetime(2015, 7, 31)}
     controller = ClanController()
     result = controller.requires_recalculation(player_data)
     expected = True
     self.assertEqual(expected, result)
Ejemplo n.º 3
0
 def test_player_requires_calculation(self):
     TestTime.set_app_time(datetime.datetime(2015, 8, 1))
     player_data = {'last_update': datetime.datetime(2015, 7, 31)}
     controller = ClanController()
     result = controller.requires_recalculation(player_data)
     expected = True
     self.assertEqual(expected, result)
Ejemplo n.º 4
0
 def test_player_does_not_require_calculation(self):
     TestTime.set_app_time(datetime.datetime(2015, 8, 1, 12, 0, 0))
     player_data = {'last_update': AppTime.get_now()}
     controller = ClanController()
     result = controller.requires_recalculation(player_data)
     expected = False
     self.assertEqual(expected, result)
Ejemplo n.º 5
0
 def test_player_does_not_require_calculation(self):
     TestTime.set_app_time(datetime.datetime(2015, 8, 1, 12, 0, 0))
     player_data = {'last_update': AppTime.get_now()}
     controller = ClanController()
     result = controller.requires_recalculation(player_data)
     expected = False
     self.assertEqual(expected, result)
Ejemplo n.º 6
0
 def test_create_player_stat(self):
     TestTime.set_app_time(datetime.datetime(2015, 8, 1))
     DatabaseUtils.recreate_database(DatabaseUtils.get_db_connection())
     conn = DatabaseUtils.get_db_connection()
     player_data = {'clan_id': 1,
                    'account_id': 777,
                    'account_name': 'test player',
                    'total_resources_earned': 1200,
                    'stronghold_skirmish_battles': 100,
                    'stronghold_defense_battles': 10,
                    'seven_day_resources_earned': 320,
                    'thirty_day_resources_earned': 320,
                    'last_update': AppTime.get_now(),
                    'thirty_day_defense_battles': 0,
                    'thirty_day_skirmish_battles': 0,
                    'clan_battles': 10,
                    'thirty_day_clan_battles': 5,
                    'all_battles': 100,
                    'thirty_day_all_battles': 50}
     controller = ClanController()
     controller.create_player_stat(conn, player_data)
     row = PlayerRepository.get_player(conn, player_data['clan_id'], player_data['account_id'])
     player_stat_dict = dict(zip(row.keys(), row))
     expected = {'clan_id': 1,
                 'account_id': 777,
                 'account_name': u'test player',
                 'total_resources_earned': 1200,
                 'stronghold_skirmish_battles': 100,
                 'thirty_day_skirmish_battles': 0,
                 'stronghold_defense_battles': 10,
                 'thirty_day_defense_battles': 0,
                 'seven_day_resources_earned': 320,
                 'thirty_day_resources_earned': 320,
                 'clan_battles': 10,
                 'thirty_day_clan_battles': 5,
                 'all_battles': 100,
                 'thirty_day_all_battles': 50,
                 'last_update': str(AppTime.get_now())}
     self.assertEqual(expected, player_stat_dict)
     from_date = AppTime.get_now()
     to_date = from_date - datetime.timedelta(days=30)
     rows = PlayerRepository.get_player_stats(conn, player_data['clan_id'], player_data['account_id'], from_date,
                                              to_date)
     self.assertEqual(1, len(rows))
     player_stat_snapshot_dict = dict(zip(rows[0].keys(), rows[0]))
     expected = {'stronghold_defense_battles': 10,
                 'account_id': 777,
                 'stronghold_skirmish_battles': 100,
                 'clan_id': 1,
                 'total_resources_earned': 1200,
                 'created_date': str(AppTime.get_now())}
     self.assertEqual(expected, player_stat_snapshot_dict)
Ejemplo n.º 7
0
 def test_get_player_data_that_is_not_in_database(self):
     TestTime.set_app_time(datetime.datetime(2015, 8, 1))
     conn = DatabaseUtils.get_db_connection()
     DatabaseUtils.recreate_database(conn)
     conn = DatabaseUtils.get_db_connection()
     controller = ClanController()
     controller._retrieve_account_stats = lambda account_id, app_id: AccountStatsFixtures.standard_accounts_record(
     )
     controller._retrieve_personal_stats = lambda account_id, app_id: AccountStatsFixtures.personal_data_response(
     )
     player_data = controller.get_player_data(conn, 'app_id', 500050913,
                                              512841364, 'test_player')
     expected = {
         "clan_id": 500050913,
         "account_id": 512841364,
         "account_name": 'test_player',
         "total_resources_earned": 5002,
         "stronghold_defense_battles": 9,
         "thirty_day_defense_battles": 0,
         "stronghold_skirmish_battles": 731,
         "thirty_day_skirmish_battles": 0,
         "seven_day_resources_earned": 0,
         "thirty_day_resources_earned": 0,
         'clan_battles': 46,
         'thirty_day_clan_battles': 0,
         'all_battles': 25346,
         'thirty_day_all_battles': 0,
         "last_update": AppTime.get_now()
     }
     self.maxDiff = None
     self.assertEqual(expected, player_data)
     from_date = AppTime.get_now()
     to_date = from_date - datetime.timedelta(days=30)
     rows = PlayerRepository.get_player_stats(conn, player_data['clan_id'],
                                              player_data['account_id'],
                                              from_date, to_date)
     self.assertEqual(1, len(rows))
     player_stat_snapshot_dict = dict(zip(rows[0].keys(), rows[0]))
     expected = {
         'stronghold_defense_battles': 9,
         'account_id': 512841364,
         'stronghold_skirmish_battles': 731,
         'clan_id': 500050913,
         'total_resources_earned': 5002,
         'created_date': str(AppTime.get_now())
     }
     self.assertEqual(expected, player_stat_snapshot_dict)
 def test_normal_data(self):
     TestTime.set_app_time(datetime.datetime(2015, 8, 1))
     player_data = AccountStatsToPlayerDataMapper.map(AccountStatsFixtures.standard_accounts_record(),
                                                      512841364, 'test_player')
     expected = {
         "clan_id": 500050913,
         "account_id": 512841364,
         "account_name": 'test_player',
         "total_resources_earned": 5002,
         "stronghold_defense_battles": 9,
         "thirty_day_defense_battles": 0,
         "stronghold_skirmish_battles": 731,
         "thirty_day_skirmish_battles": 0,
         "seven_day_resources_earned": 0,
         "thirty_day_resources_earned": 0,
         "last_update": AppTime.get_now()
     }
     self.assertEqual(expected, player_data)
 def test_normal_data(self):
     TestTime.set_app_time(datetime.datetime(2015, 8, 1))
     player_data = AccountStatsToPlayerDataMapper.map(
         AccountStatsFixtures.standard_accounts_record(), 512841364,
         'test_player')
     expected = {
         "clan_id": 500050913,
         "account_id": 512841364,
         "account_name": 'test_player',
         "total_resources_earned": 5002,
         "stronghold_defense_battles": 9,
         "thirty_day_defense_battles": 0,
         "stronghold_skirmish_battles": 731,
         "thirty_day_skirmish_battles": 0,
         "seven_day_resources_earned": 0,
         "thirty_day_resources_earned": 0,
         "last_update": AppTime.get_now()
     }
     self.assertEqual(expected, player_data)
Ejemplo n.º 10
0
 def test_get_player_data_that_is_not_in_database(self):
     TestTime.set_app_time(datetime.datetime(2015, 8, 1))
     conn = DatabaseUtils.get_db_connection()
     DatabaseUtils.recreate_database(conn)
     conn = DatabaseUtils.get_db_connection()
     controller = ClanController()
     controller._retrieve_account_stats = lambda account_id, app_id: AccountStatsFixtures.standard_accounts_record()
     controller._retrieve_personal_stats = lambda account_id, app_id: AccountStatsFixtures.personal_data_response()
     player_data = controller.get_player_data(conn, 'app_id', 500050913, 512841364, 'test_player')
     expected = {
         "clan_id": 500050913,
         "account_id": 512841364,
         "account_name": 'test_player',
         "total_resources_earned": 5002,
         "stronghold_defense_battles": 9,
         "thirty_day_defense_battles": 0,
         "stronghold_skirmish_battles": 731,
         "thirty_day_skirmish_battles": 0,
         "seven_day_resources_earned": 0,
         "thirty_day_resources_earned": 0,
         'clan_battles': 46,
         'thirty_day_clan_battles': 0,
         'all_battles': 25346,
         'thirty_day_all_battles': 0,
         "last_update": AppTime.get_now()
     }
     self.maxDiff = None
     self.assertEqual(expected, player_data)
     from_date = AppTime.get_now()
     to_date = from_date - datetime.timedelta(days=30)
     rows = PlayerRepository.get_player_stats(conn, player_data['clan_id'], player_data['account_id'], from_date,
                                              to_date)
     self.assertEqual(1, len(rows))
     player_stat_snapshot_dict = dict(zip(rows[0].keys(), rows[0]))
     expected = {'stronghold_defense_battles': 9,
                 'account_id': 512841364,
                 'stronghold_skirmish_battles': 731,
                 'clan_id': 500050913,
                 'total_resources_earned': 5002,
                 'created_date': str(AppTime.get_now())}
     self.assertEqual(expected, player_stat_snapshot_dict)
Ejemplo n.º 11
0
    def test_one_month_of_updates(self):
        """"
            Adds stats for a month
            Starts with:
            "total_resources_earned": 5002
            "week_resources_earned": 0
            "battles": 731

            It should end up with:
            "total_resources_earned": 5002 + 65 = 5067
            "week_resources_earned": 20
            30 day = 65
        """ ""
        TestTime.set_app_time(datetime.datetime(2015, 8, 1))
        account_stats = AccountStatsFixtures.standard_accounts_record()
        player_stats = AccountStatsFixtures.personal_data_response()
        conn = DatabaseUtils.get_db_connection()
        DatabaseUtils.recreate_database(conn)
        conn = DatabaseUtils.get_db_connection()
        controller = ClanController()
        controller._retrieve_account_stats = lambda account_id, app_id: account_stats
        controller._retrieve_personal_stats = lambda account_id, app_id: player_stats
        members = [{'account_id': 512841364, 'account_name': 'test_player'}]
        players_data = controller.get_players_data(conn, 123, 123, members)
        self.assertEqual(1, len(players_data))
        TestTime.set_app_time(datetime.datetime(2015, 8, 5))
        self._amend_accounts_stats(account_stats, 10, 1, 10)
        controller.get_players_data(conn, 123, 500050913, members)
        TestTime.set_app_time(datetime.datetime(2015, 8, 10))
        self._amend_accounts_stats(account_stats, 35, 2, 45)
        controller.get_players_data(conn, 123, 500050913, members)
        TestTime.set_app_time(datetime.datetime(2015, 8, 15))
        self._amend_accounts_stats(account_stats, 0, 2, 35)
        controller.get_players_data(conn, 123, 500050913, members)
        TestTime.set_app_time(datetime.datetime(2015, 8, 25))
        self._amend_accounts_stats(account_stats, 20, 1, 20, 10)
        self._amend_player_stats(player_stats, 21, 10)
        controller.get_players_data(conn, 123, 500050913, members)
        TestTime.set_app_time(datetime.datetime(2015, 8, 31))
        players_data = controller.get_players_data(conn, 123, 500050913,
                                                   members)
        expected = {
            "clan_id": 500050913,
            "account_id": 512841364,
            "account_name": 'test_player',
            'all_battles': 25367,
            'clan_battles': 46,
            "total_resources_earned": 5067,
            "stronghold_defense_battles": 19,
            "thirty_day_defense_battles": 10,
            "stronghold_skirmish_battles": 737,
            "thirty_day_skirmish_battles": 6,
            "seven_day_resources_earned": 20,
            "thirty_day_resources_earned": 65,
            'thirty_day_clan_battles': 0,
            'thirty_day_all_battles': 21,
            "last_update": AppTime.get_now()
        }
        self.maxDiff = None
        self.assertEqual(expected, players_data[0])
    def test_one_month_of_updates(self):
        """"
            Adds stats for a month
            Starts with:
            "total_resources_earned": 5002
            "week_resources_earned": 0
            "battles": 731

            It should end up with:
            "total_resources_earned": 5002 + 65 = 5067
            "week_resources_earned": 20
            30 day = 65
        """""
        TestTime.set_app_time(datetime.datetime(2015, 8, 1))
        account_stats = AccountStatsFixtures.standard_accounts_record()
        player_stats = AccountStatsFixtures.personal_data_response()
        conn = DatabaseUtils.get_db_connection()
        DatabaseUtils.recreate_database(conn)
        conn = DatabaseUtils.get_db_connection()
        controller = ClanController()
        controller._retrieve_account_stats = lambda account_id, app_id: account_stats
        controller._retrieve_personal_stats = lambda account_id, app_id: player_stats
        members = [{'account_id': 512841364, 'account_name': 'test_player'}]
        players_data = controller.get_players_data(conn, 123, 123, members)
        self.assertEqual(1, len(players_data))
        TestTime.set_app_time(datetime.datetime(2015, 8, 5))
        self._amend_accounts_stats(account_stats, 10, 1, 10)
        controller.get_players_data(conn, 123, 500050913, members)
        TestTime.set_app_time(datetime.datetime(2015, 8, 10))
        self._amend_accounts_stats(account_stats, 35, 2, 45)
        controller.get_players_data(conn, 123, 500050913, members)
        TestTime.set_app_time(datetime.datetime(2015, 8, 15))
        self._amend_accounts_stats(account_stats, 0, 2, 35)
        controller.get_players_data(conn, 123, 500050913, members)
        TestTime.set_app_time(datetime.datetime(2015, 8, 25))
        self._amend_accounts_stats(account_stats, 20, 1, 20, 10)
        self._amend_player_stats(player_stats, 21, 10)
        controller.get_players_data(conn, 123, 500050913, members)
        TestTime.set_app_time(datetime.datetime(2015, 8, 31))
        players_data = controller.get_players_data(conn, 123, 500050913, members)
        expected = {
            "clan_id": 500050913,
            "account_id": 512841364,
            "account_name": 'test_player',
            'all_battles':25367,
            'clan_battles': 46,
            "total_resources_earned": 5067,
            "stronghold_defense_battles": 19,
            "thirty_day_defense_battles": 10,
            "stronghold_skirmish_battles": 737,
            "thirty_day_skirmish_battles": 6,
            "seven_day_resources_earned": 20,
            "thirty_day_resources_earned": 65,
            'thirty_day_clan_battles': 0,
            'thirty_day_all_battles': 21,
            "last_update": AppTime.get_now()
        }
        self.maxDiff = None
        self.assertEqual(expected, players_data[0])