def test_unhunger(self): settlement = Settlement.objects.get(name="Small Valley") settlement.population_default = 10 granary = settlement.get_default_granary() bushels = granary.get_public_bushels_object() bushels.quantity = 20 bushels.save() initialize_settlement(settlement) settlement.npc_set.all().update(hunger=2) self.assertEqual(settlement.npc_set.filter(hunger=2).count(), 10) do_settlement_food_consumption(settlement) bushels.refresh_from_db() self.assertEqual(bushels.quantity, 10) self.assertEqual(settlement.npc_set.filter(hunger=1).count(), 10) do_settlement_food_consumption(settlement) bushels.refresh_from_db() self.assertEqual(bushels.quantity, 0) self.assertEqual(settlement.npc_set.filter(hunger=0).count(), 10)
def test_guild_restrict(self): initialize_settlement(self.settlement) settlement_job_updates(self.settlement) guild = self.settlement.building_set.get(type=Building.GUILD) for worker in list(self.settlement.get_residents().filter( workplace__type=Building.GRAIN_FIELD))[:30]: worker.workplace = guild worker.save() self.assertEqual( self.settlement.get_residents().filter( workplace__type=Building.GUILD).count(), 30) self.settlement.guilds_setting = Settlement.GUILDS_RESTRICT self.settlement.save() settlement_job_updates(self.settlement) self.assertTrue( self.settlement.get_residents().filter( workplace__type=Building.GRAIN_FIELD).exists()) self.assertTrue( self.settlement.get_residents().filter( workplace__type=Building.GUILD).exists()) self.assertTrue( 0 < self.settlement.get_residents().filter( workplace__type=Building.GUILD).count() <= 20)
def test_barbarian_creation_in_barbaric_settlement(self): settlement = Settlement.objects.get(name="Small Shaax") initialize_settlement(settlement) do_settlement_barbarian_generation(settlement) self.assertTrue( settlement.worldunit_set.filter( owner_character__isnull=True).exists())
def test_barbarian_non_creation_in_occupied_settlement(self): settlement = Settlement.objects.get(name="Small Fynkah") initialize_settlement(settlement) for unit in settlement.worldunit_set.all(): initialize_unit(unit) do_settlement_barbarian_generation(settlement) self.assertFalse( settlement.worldunit_set.filter( owner_character__isnull=True).exists())
def test_guild_default(self): initialize_settlement(self.settlement) settlement_job_updates(self.settlement) self.assertEqual( self.settlement.guilds_setting, Settlement.GUILDS_KEEP) self.assertTrue( self.settlement.get_residents().filter( workplace__type=Building.GRAIN_FIELD).exists()) self.assertFalse( self.settlement.get_residents().filter( workplace__type=Building.GUILD).exists())
def test_bureaucratic_work_does_not_fail(self): initialize_settlement(self.character.location) previous_po = self.character.location.public_order = 500 self.character.location.save() response = self.client.post(reverse('character:bureaucratic_work'), data={'hours': 50}, follow=True) self.assertRedirects(response, reverse('character:bureaucratic_work')) self.character.location.refresh_from_db() self.assertLess(previous_po, self.character.location.public_order)
def test_guild_promote(self): self.settlement.guilds_setting = Settlement.GUILDS_PROMOTE self.settlement.save() initialize_settlement(self.settlement) settlement_job_updates(self.settlement) self.assertTrue( self.settlement.get_residents().filter( workplace__type=Building.GRAIN_FIELD).exists()) self.assertTrue( self.settlement.get_residents().filter( workplace__type=Building.GUILD).exists()) self.assertEqual( self.settlement.get_residents().filter( workplace__type=Building.GUILD).count(), 10)
def test_food_consumption(self): settlement = Settlement.objects.get(name="Small Valley") settlement.population_default = 100 granary = settlement.get_default_granary() bushels = granary.get_public_bushels_object() bushels.quantity = 200 bushels.save() initialize_settlement(settlement) do_settlement_food_consumption(settlement) bushels.refresh_from_db() self.assertEqual(bushels.quantity, 100)
def test_max_conscription(self): character = Character.objects.get(id=6) initialize_settlement(character.location) # Don't raise test_if_hero_can_recruit_soldier_quantity( character, character.max_amount_of_conscripted_soldiers()) # Raise self.assertRaises( RecruitmentFailure, test_if_hero_can_recruit_soldier_quantity( character, character.max_amount_of_conscripted_soldiers() + 1))
def test_battle_with_barbarians(self): world = World.objects.get(id=2) unit_of_kingrom_member = WorldUnit.objects.get(id=4) initialize_unit(unit_of_kingrom_member) kingdom_member = unit_of_kingrom_member.owner_character settlement = kingdom_member.location initialize_settlement(settlement) generate_barbarian_unit(30, settlement) worldwide_trigger_battles(world) self.assertTrue(settlement.tile.get_current_battles().exists()) battle = settlement.tile.get_current_battles()[0] start_battle(battle) battle_tick(battle) generate_barbarian_unit(30, settlement) battle_joins(battle) battle_tick(battle)
def test_guild_prohibit(self): initialize_settlement(self.settlement) turn_processor = TurnProcessor(self.settlement.tile.world) turn_processor.do_settlement_job_updates(self.settlement) guild = self.settlement.building_set.get(type=Building.GUILD) for worker in list(self.settlement.get_residents().filter( workplace__type=Building.GRAIN_FIELD))[:30]: worker.workplace = guild worker.save() self.assertEqual( self.settlement.get_residents().filter( workplace__type=Building.GUILD).count(), 30) self.settlement.guilds_setting = Settlement.GUILDS_PROHIBIT self.settlement.save() turn_processor.do_settlement_job_updates(self.settlement) self.assertTrue( self.settlement.get_residents().filter( workplace__type=Building.GRAIN_FIELD).exists()) self.assertFalse( self.settlement.get_residents().filter( workplace__type=Building.GUILD).exists())