def test_merge_list_empty(self): old_list = [Item(0), Item(1), Item(2)] new_list = [] assert model.merge_list(old_list, new_list) == old_list old_list = [] new_list = [Item(0), Item(1), Item(2)] assert model.merge_list(old_list, new_list) == new_list
def update_master(self, request, response): # TODO: Refactor this method. As the master information is now shipped # with /api_start2, there's no need to care if there is already a # member data there. mission_to_progress = {} for mission in self.missions: if mission.undertaking_fleet: mission_to_progress[mission.id] = [mission.undertaking_fleet, mission.eta] missions = [] for data in response.api_data.api_mst_mission: mission = Mission( id=data.api_id, name=data.api_name, description=data.api_details, difficulty=data.api_difficulty, maparea=data.api_maparea_id, state=Mission.STATE_COMPLETE, time=data.api_time, consumption=resource.ResourcePercentage(fuel=float(data.api_use_fuel), ammo=float(data.api_use_bull)), rewards=MISSION_REWARDS.get(data.api_id, {}), ) progress = mission_to_progress.get(mission.id) if progress: mission.undertaking_fleet = progress[0] mission.eta = progress[1] missions.append(mission) missions.sort(lambda x, y: x.id - y.id) self.missions = model.merge_list(self.missions, missions)
def update(self, api_name, request, response, objects, debug): super(QuestList, self).update(api_name, request, response, objects, debug) now = datetime.datetime.now() refresh_datetime = datetime.datetime.combine( now.date(), QuestList.REFRESH_TIME) if (self.last_update and self.last_update < refresh_datetime and now >= refresh_datetime): logger.info('Clearing the quest list.') logger.debug('Last quest update: {}'.format(self.last_update)) logger.debug('Quest refresh: {}'.format(refresh_datetime)) logger.debug('Now: {}'.format(now)) self.quests = [] self.last_update = now if api_name == '/api_get_member/questlist': data = response.api_data # If the last one quest in the page is compelted, a reponse with an # empty list could be returned. Just ignore such one. if not data.api_list: return self.count = data.api_count self.count_undertaken = data.api_exec_count quests = [] for quest_data in data.api_list: if quest_data == -1: continue progress = (0, 50, 80)[quest_data.api_progress_flag] if quest_data.api_state == Quest.STATE_COMPLETE: progress = 100 quests.append(Quest( id=quest_data.api_no, name=quest_data.api_title, description=quest_data.api_detail, category=quest_data.api_category, state=quest_data.api_state, progress=progress, bonus_type=quest_data.api_bonus_flag, cycle=quest_data.api_type, rewards=resource.Resource( fuel=quest_data.api_get_material[0], ammo=quest_data.api_get_material[1], steel=quest_data.api_get_material[2], bauxite=quest_data.api_get_material[3]))) quests.sort(lambda x, y: x.id - y.id) self.quests = model.merge_list(self.quests, quests) elif api_name == '/api_req_quest/clearitemget': self.remove_quest(int(request.api_quest_id))
def test_merge_list_reverse_interpolate(self): old_list = [Item(1, 'bar'), Item(2, 'baz')] new_list = [Item(0, 'foo'), Item(3, 'qux')] assert (model.merge_list(old_list, new_list) == [Item(0, 'foo'), Item(1, 'bar'), Item(2, 'baz'), Item(3, 'qux')])
def test_merge_list_partial_rewrite(self): old_list = [Item(0, 'foo'), Item(1, 'bar')] new_list = [Item(1, 'baz'), Item(2, 'qux')] assert (model.merge_list(old_list, new_list) == [Item(0, 'foo'), Item(1, 'baz'), Item(2, 'qux')])
def test_merge_list_rewrite(self): old_list = [Item(0, 'foo')] new_list = [Item(0, 'bar')] assert model.merge_list(old_list, new_list) == new_list
def test_merge_list_extend(self): old_list = [Item(0), Item(1)] new_list = [Item(2), Item(3)] assert model.merge_list(old_list, new_list) == old_list + new_list