def test_load_zone_from_dict(self): from Zone import ZoneDBFields zd = { ZoneDBFields.DEFINITION_KEY: "gas" } z = Zone.construct_model_from_dict(zd) self.assertEqual(z.get_fullName(),"Gas Planet Orbit")
def zone(self): if not self._zone: if self.get_dbFields().ZONE in self.dict: self._zone = Zone.construct_model_from_dict( self.dict[self.get_dbFields().ZONE]) else: return None return self._zone
def check_in_and_get_notices(heroPk,accountPk,checkinTimeUtc,utcOffset): """ this should be called on page load and should be used to get any notices for the use args: heroPk: we want a pymongo objectId for the hero table accountPk: we want a pymongo objectId for the hero table checkinTimeUtc: this needs to be that the user check in and it needs to be utc utcOffset: the time-zone offset from UTC, in minutes, for the current locale. returns: we return a dict with two elements: 'story' which will be a list of huge things of text and 'zoneChoice' which is a list of dicts each of which contain 'zonePk','description' but zoneChoice may be none. """ from Hero import Hero from Account import Account hero = Hero.construct_model_from_pk(heroPk) account = Account.construct_model_from_pk(accountPk) lastCheckinTime = account.lastCheckInTime account.lastCheckInTime = checkinTimeUtc account.save_changes() if not lastCheckinTime: messages = build_first_time_checkin_messages(hero) hero.save_changes() return messages if hero.isInZoneLimbo: autoPickedZoneDict = random.choice(hero.zone.nextZoneReferenceList) hero.zone = Zone.construct_model_from_dict(autoPickedZoneDict) hero.monster = Monster.construct_new_monster(hero.zone.definitionKey,hero.zone.lvl) timeDiffInDays = (checkinTimeUtc - lastCheckinTime)/(60*60*24) if timeDiffInDays >= 1: pass
def check_in_and_get_notices(heroPk, accountPk, checkinTimeUtc, utcOffset): """ this should be called on page load and should be used to get any notices for the use args: heroPk: we want a pymongo objectId for the hero table accountPk: we want a pymongo objectId for the hero table checkinTimeUtc: this needs to be that the user check in and it needs to be utc utcOffset: the time-zone offset from UTC, in minutes, for the current locale. returns: we return a dict with two elements: 'story' which will be a list of huge things of text and 'zoneChoice' which is a list of dicts each of which contain 'zonePk','description' but zoneChoice may be none. """ from Hero import Hero from Account import Account hero = Hero.construct_model_from_pk(heroPk) account = Account.construct_model_from_pk(accountPk) lastCheckinTime = account.lastCheckInTime account.lastCheckInTime = checkinTimeUtc account.save_changes() if not lastCheckinTime: messages = build_first_time_checkin_messages(hero) hero.save_changes() return messages if hero.isInZoneLimbo: autoPickedZoneDict = random.choice(hero.zone.nextZoneReferenceList) hero.zone = Zone.construct_model_from_dict(autoPickedZoneDict) hero.monster = Monster.construct_new_monster(hero.zone.definitionKey, hero.zone.lvl) timeDiffInDays = (checkinTimeUtc - lastCheckinTime) / (60 * 60 * 24) if timeDiffInDays >= 1: pass
def test_zone_properties_from_dict(self): hpk = dbHelp.setup_test_hero_using_default_values() zd = dbHelp.create_test_zone_dict() testZoneKey = ZoneDefinitionFields.EMPTY_SPACE z = Zone.construct_model_from_dict(zd) self.assertEqual(z.definitionKey, testZoneKey) self.assertEqual(z.get_fullName(), ZoneDefinition.get_name_for_key(testZoneKey) + " Alpha") self.assertEqual(z.suffix,"Alpha") self.assertEqual(z.monstersKilled, 2) self.assertEqual(z.maxMonsters,15) self.assertEqual(z.lvl, 3) self.assertEqual(z.get_description(),ZoneDefinition.get_description_for_key(testZoneKey)) oldCount = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME) z.save_changes(hpk) newCount = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME) self.assertEqual(oldCount +1, newCount) oldCount = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME) z.save_changes(hpk) newCount = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME) self.assertEqual(oldCount, newCount)
def test_zone_properties_from_dict(self): hpk = dbHelp.setup_test_hero_using_default_values() zd = dbHelp.create_test_zone_dict() testZoneKey = ZoneDefinitionFields.EMPTY_SPACE z = Zone.construct_model_from_dict(zd) self.assertEqual(z.definitionKey, testZoneKey) self.assertEqual( z.get_fullName(), ZoneDefinition.get_name_for_key(testZoneKey) + " Alpha") self.assertEqual(z.suffix, "Alpha") self.assertEqual(z.monstersKilled, 2) self.assertEqual(z.maxMonsters, 15) self.assertEqual(z.lvl, 3) self.assertEqual(z.get_description(), ZoneDefinition.get_description_for_key(testZoneKey)) oldCount = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME) z.save_changes(hpk) newCount = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME) self.assertEqual(oldCount + 1, newCount) oldCount = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME) z.save_changes(hpk) newCount = tu.get_record_count_from_table(ZoneDBFields.COLLECTION_NAME) self.assertEqual(oldCount, newCount)
def test_load_zone_from_dict(self): from Zone import ZoneDBFields zd = {ZoneDBFields.DEFINITION_KEY: "gas"} z = Zone.construct_model_from_dict(zd) self.assertEqual(z.get_fullName(), "Gas Planet Orbit")
def create_test_zone_obj(zoneKey=None): zoneDict = create_test_zone_dict(zoneKey) zoneObj = Zone.construct_model_from_dict(zoneDict) return zoneObj
def zone(self, value): self.dict[self.get_dbFields().ZONE] = value.dict self._changes[self.get_dbFields().ZONE] = value.dict self._zone = Zone.construct_model_from_dict( self.dict[self.get_dbFields().ZONE])
def create_test_zone_obj(zoneKey=None): zoneDict = create_test_zone_dict(zoneKey) zoneObj = Zone.construct_model_from_dict(zoneDict) return zoneObj