def test_school_update_year(self): homepage = Homepage(self.browser, self.live_server_url) homepage.navigate("/main/") self.assertIn("Login", self.browser.title) login_page = LoginPage(self.browser, self.live_server_url) login_page.login(username=self.user.username, password="******") self.assertTrue(User.objects.latest("id").is_authenticated) self.assertIn("Miasto {}".format(self.city.name), self.browser.title) main_view = MainView(self.browser, self.live_server_url) e = Education.objects.create( cur_year_of_learning=0, max_year_of_learning=8, citizen=self.f, name=ELEMENTARY, ) self.f.school_object = self.school self.f.save() self.profile.current_turn = 6 self.profile.save() RC = RootClass(self.city, self.user) self.assertEqual(RC.citizens_in_city[self.f].current_education, e) main_view.next_turns(4) self.assertEqual(Education.objects.all().count(), 1) self.f = Citizen.objects.get(id=self.f.id) e = Education.objects.get(id=e.id) RC = RootClass(self.city, self.user) self.assertEqual(RC.citizens_in_city[self.f].current_education, e) self.assertEqual(e.cur_year_of_learning, 1) self.assertEqual(e.max_year_of_learning, 8)
def test_born_child_failed(self): field = list(Field.objects.all()) s = StandardLevelResidentialZone.objects.create( city=self.city, if_under_construction=False, city_field=field.pop()) s.self__init(2) s.save() family = Family.objects.create(city=self.city, surname="01") self.f = Citizen.objects.create( city=self.city, age=21, month_of_birth=2, cash=400, health=5, name="AnonKA", surname="FeSurname", sex=FEMALE, resident_object=s, family=family, ) self.m = Citizen.objects.create( city=self.city, age=21, month_of_birth=2, cash=400, health=5, name="AnON", surname="MaSurname", sex=MALE, resident_object=s, family=family, ) self.f.partner_id = self.m.id self.m.partner_id = self.f.id self.m.save() self.f.save() self.assertEqual(self.f.partner_id, self.m.id) self.assertEqual(self.m.partner_id, self.f.id) self.assertEqual(self.m.resident_object, s) self.assertEqual(self.f.resident_object, s) homepage = Homepage(self.browser, self.live_server_url) homepage.navigate("/main/") self.assertIn("Login", self.browser.title) login_page = LoginPage(self.browser, self.live_server_url) login_page.login(username=self.user.username, password="******") self.assertTrue(User.objects.latest("id").is_authenticated) self.assertIn("Miasto {}".format(self.city.name), self.browser.title) main_view = MainView(self.browser, self.live_server_url) self.user.profile.if_social_enabled = True self.user.profile.chance_to_born_baby_percent = 1.00 self.user.profile.save() self.assertEqual(self.user.profile.chance_to_born_baby_percent, 1.00) self.assertTrue(self.user.profile.if_social_enabled) self.assertEqual(s.max_population, 2) self.assertEqual(Citizen.objects.count(), 2) self.assertEqual(Family.objects.all().count(), 1) main_view.next_turns(5)
def test_school_assign(self): homepage = Homepage(self.browser, self.live_server_url) homepage.navigate("/main/") self.assertIn("Login", self.browser.title) login_page = LoginPage(self.browser, self.live_server_url) login_page.login(username=self.user.username, password="******") self.assertTrue(User.objects.latest("id").is_authenticated) self.assertIn("Miasto {}".format(self.city.name), self.browser.title) s = Citizen.objects.create( city=self.city, age=8, month_of_birth=2, cash=100, health=5, name="0", surname="2", sex=FEMALE, education="None", resident_object=self.r1, ) e2 = Education.objects.create(cur_year_of_learning=4, max_year_of_learning=8, citizen=s, name=ELEMENTARY) main_view = MainView(self.browser, self.live_server_url) self.profile.current_turn = 6 self.profile.save() self.assertTrue(self.profile.if_social_enabled) self.assertEqual(Citizen.objects.count(), 2) self.assertEqual(self.f.school_object, None) self.assertEqual(Education.objects.all().count(), 1) RC = RootClass(self.city, self.user) self.assertEqual(RC.citizens_in_city[self.f].current_education, None) self.assertNotEqual(RC.citizens_in_city[s].current_education, None) main_view.next_turns(4) e1 = Education.objects.get(citizen_id=self.f.id) e2 = Education.objects.get(id=e2.id) RC = RootClass(self.city, self.user) self.assertEqual(RC.citizens_in_city[self.f].current_education, e1) self.assertEqual(RC.citizens_in_city[s].current_education, e2) self.assertEqual(e1.cur_year_of_learning, 0) self.assertEqual(e1.max_year_of_learning, 8) self.assertEqual(e2.cur_year_of_learning, 4) self.assertEqual(e2.max_year_of_learning, 8) self.assertEqual(Education.objects.all().count(), 2) self.f = Citizen.objects.get(id=self.f.id) s = Citizen.objects.get(id=s.id) self.assertEqual(self.f.school_object, self.school) self.assertEqual(s.school_object, self.school)
def test_find_home_failed(self): self.r1 = StandardLevelResidentialZone.objects.latest("id") self.r1.max_population = 0 self.r1.save() she_family = Family.objects.create(city=self.city, surname="00") he_family = Family.objects.create(city=self.city, surname="01") self.f = Citizen.objects.create( city=self.city, age=21, month_of_birth=2, cash=100, health=5, name="AnonKA", surname="FeSurname", sex=FEMALE, family=she_family, ) self.m = Citizen.objects.create( city=self.city, age=21, month_of_birth=2, cash=100, health=5, name="AnON", surname="MaSurname", sex=MALE, family=he_family, ) homepage = Homepage(self.browser, self.live_server_url) homepage.navigate("/main/") self.assertIn("Login", self.browser.title) login_page = LoginPage(self.browser, self.live_server_url) login_page.login(username=self.user.username, password="******") self.assertTrue(User.objects.latest("id").is_authenticated) self.assertIn("Miasto {}".format(self.city.name), self.browser.title) main_view = MainView(self.browser, self.live_server_url) self.profile.if_social_enabled = True self.profile.chance_to_marriage_percent = 1.00 self.profile.save() self.assertEqual(self.profile.chance_to_marriage_percent, 1.00) self.assertTrue(self.profile.if_social_enabled) self.assertEqual(Citizen.objects.count(), 2) self.assertEqual( StandardLevelResidentialZone.objects.latest("id").resident.count(), 0) self.assertEqual(Family.objects.all().count(), 2) main_view.next_turn() self.m = Citizen.objects.get(id=self.m.id) self.f = Citizen.objects.get(id=self.f.id) self.assertEqual( StandardLevelResidentialZone.objects.latest("id").resident.count(), 0) self.assertEqual(Family.objects.all().count(), 2) self.assertEqual(self.m.resident_object, None) self.assertEqual(self.f.resident_object, None)
def test_born_child(self): family = Family.objects.create(city=self.city, surname="01") self.f = Citizen.objects.create( city=self.city, age=21, month_of_birth=2, cash=100, health=5, name="AnonKA", surname="FeSurname", sex=FEMALE, resident_object=StandardLevelResidentialZone.objects.latest("id"), family=family, ) self.m = Citizen.objects.create( city=self.city, age=21, month_of_birth=2, cash=100, health=5, name="AnON", surname="MaSurname", sex=MALE, resident_object=StandardLevelResidentialZone.objects.latest("id"), family=family, ) self.f.partner_id = self.m.id self.m.partner_id = self.f.id self.m.save() self.f.save() self.assertEqual(self.f.partner_id, self.m.id) self.assertEqual(self.m.partner_id, self.f.id) homepage = Homepage(self.browser, self.live_server_url) homepage.navigate("/main/") self.assertIn("Login", self.browser.title) login_page = LoginPage(self.browser, self.live_server_url) login_page.login(username=self.user.username, password="******") self.assertTrue(User.objects.latest("id").is_authenticated) self.assertIn("Miasto {}".format(self.city.name), self.browser.title) main_view = MainView(self.browser, self.live_server_url) self.profile.if_social_enabled = True self.profile.chance_to_born_baby_percent = 1.00 self.profile.save() self.assertEqual(self.profile.chance_to_born_baby_percent, 1.00) self.assertTrue(self.profile.if_social_enabled) self.assertEqual(Citizen.objects.count(), 2) self.assertEqual(Family.objects.all().count(), 1) main_view.next_turn() self.assertEqual(Citizen.objects.count(), 3) born = Citizen.objects.latest("id") self.assertEqual(born.age, 1) self.assertEqual(born.father_id, self.m.id) self.assertEqual(born.mother_id, self.f.id) self.assertEqual(born.city, self.city)
def test_signup_two_players(self): home_page = Homepage(self.browser, self.live_server_url) home_page.navigate("") self.assertIn("Strona główna", self.browser.title) home_page.click_registration_button() self.assertIn("Rejestracja", self.browser.title) signup_page = SignupPage(self.browser, self.live_server_url) signup_page.create_account( city_name=self.city_one_name, username=self.player_one, password=self.password_one, ) self.assertIn("Miasto {}".format(self.city_one_name), self.browser.title) self.assertEqual( Field.objects.filter(city=City.objects.get( name=self.city_one_name)).count(), HEX_NUM, ) main_view = MainView(self.browser, self.live_server_url) main_view.logout() self.assertIn("Strona główna", self.browser.title) home_page = Homepage(self.browser, self.live_server_url) home_page.click_registration_button() self.assertIn("Rejestracja", self.browser.title) signup_page.create_account( city_name=self.city_two_name, username=self.player_two, password=self.password_two, ) self.assertIn("Miasto {}".format(self.city_two_name), self.browser.title) self.assertEqual( Field.objects.filter(city=City.objects.get( name=self.city_two_name)).count(), HEX_NUM, )
def test_choose_better_workplace(self): homepage = Homepage(self.browser, self.live_server_url) homepage.navigate("/main/") self.assertIn("Login", self.browser.title) login_page = LoginPage(self.browser, self.live_server_url) login_page.login(username=self.user.username, password="******") self.assertTrue(User.objects.latest("id").is_authenticated) self.assertIn("Miasto {}".format(self.city.name), self.browser.title) main_view = MainView(self.browser, self.live_server_url) self.assertTrue(self.profile.if_social_enabled) self.assertEqual(Citizen.objects.count(), 2) self.employee = Citizen.objects.get(id=self.employee.id) self.m = Citizen.objects.get(id=self.m.id) self.assertEqual(self.employee.workplace_object, None) self.assertEqual(self.m.workplace_object, None) self.assertEqual(Profession.objects.all().count(), 0) main_view.next_turns(3) self.assertEqual(Profession.objects.all().count(), 2) RC = RootClass(self.city, self.user) self.employee = Citizen.objects.get(id=self.employee.id) self.m = Citizen.objects.get(id=self.m.id) self.assertNotEqual(self.employee.workplace_object, None) self.assertNotEqual( RC.citizens_in_city[self.employee].current_profession.education, self.employee.edu_title, ) self.assertEqual( RC.citizens_in_city[self.m].current_profession.education, self.m.edu_title) ps = PrimarySchool.objects.create( city=self.city, city_field=Field.objects.latest("id"), if_under_construction=False, ) main_view.next_turns(2) self.assertEqual(Profession.objects.all().count(), 3) self.employee = Citizen.objects.get(id=self.employee.id) self.m = Citizen.objects.get(id=self.m.id) RC = RootClass(self.city, self.user) self.assertEqual(len(RC.citizens_in_city[self.employee].professions), 2) self.assertEqual( len([ x for x in RC.citizens_in_city[self.employee].professions if x.if_current is True ]), 1, ) self.assertEqual(len(RC.citizens_in_city[self.m].professions), 1) self.assertEqual(self.employee.workplace_object, ps) self.assertNotEqual(self.m.workplace_object, ps)
def test_mass_collector(self): MassConventer.objects.create( city=self.city, city_field=Field.objects.latest("id"), if_under_construction=False, ) homepage = Homepage(self.browser, self.live_server_url) homepage.navigate("/main/") self.assertIn("Login", self.browser.title) login_page = LoginPage(self.browser, self.live_server_url) login_page.login(username=self.user.username, password="******") self.assertTrue(User.objects.latest("id").is_authenticated) self.assertIn("Miasto {}".format(self.city.name), self.browser.title) main_view = MainView(self.browser, self.live_server_url) self.assertEqual(MassConventer.objects.all().count(), 1) rc = RootClass(self.city, self.user) self.assertEqual(rc.market.resources.get(Mass), None) main_view.next_turns(3) for x in Education.objects.all(): x.effectiveness = 0.1 x.save() main_view.next_turns(3) for x in Education.objects.all(): x.effectiveness = 0.9 x.save() main_view.next_turns(3) mc = MassConventer.objects.latest("id") self.assertEqual(mc.employee.all().count(), mc.elementary_employee_needed) self.assertEqual(Mass.objects.count(), 3) rc = RootClass(self.city, self.user) self.assertEqual(len(rc.market.resources[Mass].instances), 3) self.assertEqual(rc.market.resources[Mass].total_size, 9) self.assertEqual(round(rc.market.resources[Mass].avg_quality), 17) self.assertEqual(round(rc.market.resources[Mass].avg_price), 164)
def test_trashcollector_build(self): self.create_first_user() LoginPage(self.browser, self.live_server_url).navigate_to_main_throught_login( user=self.user_one, username=self.player_one, password=self.password_one, city=self.city_one, assertIn=self.assertIn, assertTrue=self.assertTrue, ) main_view = MainView(self.browser, self.live_server_url) main_view.build_the_building_from_single_choice("DumpingGround", "11") main_view.build_the_building_from_single_choice("WindPlant", "10") self.assertEquals( WindPlant.objects.filter(city=self.city_one).count(), 1) self.assertEquals( DumpingGround.objects.filter(city=self.city_one).count(), 1)
def test_trade_district(self): TestHelper(city=self.city, user=self.user).populate_city() homepage = Homepage(self.browser, self.live_server_url) homepage.navigate("/main/") self.assertIn("Login", self.browser.title) login_page = LoginPage(self.browser, self.live_server_url) login_page.login(username=self.user.username, password="******") self.assertTrue(User.objects.latest("id").is_authenticated) self.assertIn("Miasto {}".format(self.city.name), self.browser.title) main_view = MainView(self.browser, self.live_server_url) rc = RootClass(self.city, self.user) self.assertEqual(Mass.objects.count(), 1) self.assertEqual(Food.objects.count(), 0) self.assertEqual(len(rc.market.resources[Mass].instances), 1) self.assertEqual(rc.companies[self.fc].goods.get(Food), None) main_view.next_turn() rc = RootClass(self.city, self.user) self.assertEqual(Mass.objects.count(), 0) self.assertEqual(Food.objects.count(), 1) self.assertEqual(rc.market.resources.get(Mass), None) self.assertEqual(len(rc.companies[self.fc].goods[Food].instances), 1) self.assertEqual(rc.companies[self.fc].goods[Food].total_size, 60) self.assertEqual(rc.companies[self.fc].goods[Food].avg_price, 1.50) self.assertEqual(rc.companies[self.fc].goods[Food].avg_quality, 5) Mass.objects.create(size=60, quality=50, market=self.market, price=2) main_view.next_turn() rc = RootClass(self.city, self.user) self.assertEqual(len(rc.companies[self.fc].goods[Food].instances), 2) self.assertEqual(rc.companies[self.fc].goods[Food].total_size, 120) self.assertEqual(rc.companies[self.fc].goods[Food].avg_price, 1.75) self.assertEqual(rc.companies[self.fc].goods[Food].avg_quality, 9) first = rc.companies[self.fc].goods[Food].instances[0] self.assertEqual(float(first.price), 1.50) self.assertEqual(first.quality, 5) second = rc.companies[self.fc].goods[Food].instances[1] self.assertEqual(float(second.price), 2) self.assertEqual(second.quality, 13)
def test_resources_view_for_two_players(self): self.create_first_user() cf_id = Field.objects.latest("id").id SewageWorks.objects.create(city=self.city_one, city_field=Field.objects.get(id=cf_id)) WaterTower.objects.create(city=self.city_one, city_field=Field.objects.get(id=cf_id - 1)) s1 = StandardLevelResidentialZone.objects.create( city=self.city_one, city_field=Field.objects.get(id=cf_id - 2), max_population=30, ) s2 = StandardLevelResidentialZone.objects.create( city=self.city_one, city_field=Field.objects.get(id=cf_id - 3), max_population=30, ) WaterTower.objects.create(city=self.city_one, city_field=Field.objects.get(id=cf_id - 4)) WindPlant.objects.create(city=self.city_one, city_field=Field.objects.get(id=cf_id - 5)) WindPlant.objects.create(city=self.city_one, city_field=Field.objects.get(id=cf_id - 6)) WindPlant.objects.create(city=self.city_one, city_field=Field.objects.get(id=cf_id - 7)) PotatoFarm.objects.create(city=self.city_one, city_field=Field.objects.get(id=cf_id - 8)) LettuceFarm.objects.create(city=self.city_one, city_field=Field.objects.get(id=cf_id - 9)) BeanFarm.objects.create(city=self.city_one, city_field=Field.objects.get(id=cf_id - 10)) f = CattleFarm.objects.create(city=self.city_one, city_field=Field.objects.get(id=cf_id - 11)) Cattle.objects.create(farm=f, size=30, price=20) s1.self__init(30) s2.self__init(30) s1.save() s2.save() self.create_second_user() TestHelper(self.city_one, User.objects.latest("id")).populate_city() LoginPage(self.browser, self.live_server_url).navigate_to_main_throught_login( user=self.user_one, username=self.player_one, password=self.password_one, city=self.city_one, assertIn=self.assertIn, assertTrue=self.assertTrue, ) main_view = MainView(self.browser, self.live_server_url) main_view.next_turns(8) bean = Bean.objects.latest("id") potato = Potato.objects.latest("id") lettuce = Lettuce.objects.latest("id") rc = RootClass(self.city_one, self.user_one) resources = rc.market.resources self.assertEqual(Bean.objects.count(), 1) self.assertEqual(bean.size, 705) self.assertEqual(int(bean.price), 36) self.assertEqual(bean.quality, 33) self.assertEqual(len(resources[Bean].instances), 1) self.assertEqual(resources[Bean].total_size, 705) self.assertEqual(resources[Bean].avg_quality, 33) self.assertEqual(int(resources[Bean].avg_price), 36) self.assertEqual(Lettuce.objects.count(), 1) self.assertEqual(lettuce.size, 349) self.assertEqual(int(lettuce.price), 18) self.assertEqual(lettuce.quality, 33) self.assertEqual(len(resources[Lettuce].instances), 1) self.assertEqual(resources[Lettuce].total_size, 349) self.assertEqual(resources[Lettuce].avg_quality, 33) self.assertEqual(int(resources[Lettuce].avg_price), 18) self.assertEqual(Potato.objects.count(), 1) self.assertEqual(potato.size, 695) self.assertEqual(int(potato.price), 37) self.assertEqual(potato.quality, 33) self.assertEqual(len(resources[Potato].instances), 1) self.assertEqual(resources[Potato].total_size, 695) self.assertEqual(resources[Potato].avg_quality, 33) self.assertEqual(int(resources[Potato].avg_price), 37) self.assertEqual(Milk.objects.count(), 1) main_view.logout() LoginPage(self.browser, self.live_server_url).navigate_to_main_throught_login( user=self.user_two, username=self.player_two, password=self.password_two, city=self.city_two, assertIn=self.assertIn, assertTrue=self.assertTrue, ) main_view = MainView(self.browser, self.live_server_url) main_view.next_turns(8) main_view.get_resources_view() self.assertEqual( "{}/main/resources/".format(self.live_server_url), str(self.browser.current_url), ) self.assertIn("Surowce", self.browser.title) rc2 = RootClass(self.city_two, self.user_two) self.assertEqual( Bean.objects.filter(market=self.market_two).count(), 0) self.assertEqual( Potato.objects.filter(market=self.market_two).count(), 0) self.assertEqual( Lettuce.objects.filter(market=self.market_two).count(), 0) self.assertEqual(rc2.market.resources.get(Potato), None) self.assertEqual(rc2.market.resources.get(Bean), None) self.assertEqual(rc2.market.resources.get(Lettuce), None)
def test_garbage_management(self): self.create_first_user() LoginPage(self.browser, self.live_server_url).navigate_to_main_throught_login( user=self.user_one, username=self.player_one, password=self.password_one, city=self.city_one, assertIn=self.assertIn, assertTrue=self.assertTrue, ) main_view = MainView(self.browser, self.live_server_url) cf_id = Field.objects.latest("id").id SewageWorks.objects.create( city=self.city_one, city_field=Field.objects.get(id=cf_id), if_under_construction=False, ) WaterTower.objects.create( city=self.city_one, city_field=Field.objects.get(id=cf_id - 1), if_under_construction=False, ) WaterTower.objects.create( city=self.city_one, city_field=Field.objects.get(id=cf_id - 2), if_under_construction=False, ) WindPlant.objects.create( city=self.city_one, city_field=Field.objects.get(id=cf_id - 3), if_under_construction=False, ) WindPlant.objects.create( city=self.city_one, city_field=Field.objects.get(id=cf_id - 4), if_under_construction=False, ) dg = DumpingGround.objects.create( city=self.city_one, city_field=Field.objects.get(id=cf_id - 5), if_under_construction=False, ) DustCart.objects.create(dumping_ground=dg) StandardLevelResidentialZone.objects.create( city=self.city_one, city_field=Field.objects.get(id=cf_id - 6), max_population=30, if_under_construction=False, ) StandardLevelResidentialZone.objects.create( city=self.city_one, city_field=Field.objects.get(id=cf_id - 7), max_population=30, if_under_construction=False, ) TestHelper(city=self.city_one, user=User.objects.latest("id")).populate_city() dumping_ground = DumpingGround.objects.latest("id") dust_cart = DustCart.objects.latest("id") self.assertEqual(dumping_ground.current_space_for_trash, 0) self.assertEqual(dumping_ground.employee.count(), 5) self.assertEqual(dust_cart.employee.count(), 3) # self.assertGreater(sum([trash.size for trash in self.list_of_all_trashes_in_city()]), 18) main_view.next_turns(7) dumping_ground = DumpingGround.objects.latest("id") dust_cart = DustCart.objects.latest("id") self.assertEqual(dumping_ground.employee.count(), 5) self.assertGreater(dumping_ground.current_space_for_trash, 100) self.assertEqual(dust_cart.employee.count(), 3) self.assertGreater( Field.objects.filter(city=self.city_one).aggregate( Sum("pollution"))["pollution__sum"], 36, )
def test_born_child_failed(self): self.r1 = StandardLevelResidentialZone.objects.latest("id") self.r1.self__init(2) self.r1.save() family = Family.objects.create(city=self.city, surname="01") self.f = Citizen.objects.create( city=self.city, age=21, month_of_birth=2, cash=400, health=5, name="AnonKA", surname="FeSurname", sex=FEMALE, resident_object=self.r1, family=family, ) self.m = Citizen.objects.create( city=self.city, age=21, month_of_birth=2, cash=400, health=5, name="AnON", surname="MaSurname", sex=MALE, resident_object=self.r1, family=family, ) self.f.partner_id = self.m.id self.m.partner_id = self.f.id self.m.save() self.f.save() self.assertEqual(self.f.partner_id, self.m.id) self.assertEqual(self.m.partner_id, self.f.id) self.assertEqual(self.m.resident_object, self.r1) self.assertEqual(self.f.resident_object, self.r1) homepage = Homepage(self.browser, self.live_server_url) homepage.navigate("/main/") self.assertIn("Login", self.browser.title) login_page = LoginPage(self.browser, self.live_server_url) login_page.login(username=self.user.username, password="******") self.assertTrue(User.objects.latest("id").is_authenticated) self.assertIn("Miasto {}".format(self.city.name), self.browser.title) main_view = MainView(self.browser, self.live_server_url) self.profile.if_social_enabled = True self.profile.chance_to_born_baby_percent = 1.00 self.profile.save() self.assertEqual(self.profile.chance_to_born_baby_percent, 1.00) self.assertTrue(self.profile.if_social_enabled) self.assertEqual(self.r1.max_population, 2) self.assertEqual(Citizen.objects.count(), 2) self.assertEqual(Family.objects.all().count(), 1) main_view.next_turn() self.assertEqual( RootClass(self.city, User.objects.latest("id")).families[family].cash, 718) self.assertEqual(float(City.objects.latest("id").cash), 9480.82) self.assertEqual( float(StandardLevelResidentialZone.objects.latest("id").cash), 81.18) main_view.next_turn() self.assertEqual( int( RootClass(self.city, User.objects.latest("id")).families[family].cash), 638) self.assertEqual(int(City.objects.latest("id").cash), 9481) self.assertEqual( int(StandardLevelResidentialZone.objects.latest("id").cash), 162) main_view.next_turn() self.assertEqual( RootClass(self.city, User.objects.latest("id")).families[family].cash, 554) self.assertEqual(int(City.objects.latest("id").cash), 9482) self.assertEqual( int(StandardLevelResidentialZone.objects.latest("id").cash), 243) main_view.next_turn() self.assertEqual( RootClass(self.city, User.objects.latest("id")).families[family].cash, 472) self.assertEqual(int(City.objects.latest("id").cash), 9483) self.assertEqual( int(StandardLevelResidentialZone.objects.latest("id").cash), 324) self.assertEqual(Citizen.objects.count(), 2)
def test_create_building_for_two_accounts(self): self.create_first_user() LoginPage(self.browser, self.live_server_url).navigate_to_main_throught_login( user=self.user_one, username=self.player_one, password=self.password_one, city=self.city_one, assertIn=self.assertIn, assertTrue=self.assertTrue, ) main_view = MainView(self.browser, self.live_server_url) main_view.build_the_building_from_single_choice("SewageWorks", "00") main_view.build_the_building_from_single_choice("WaterTower", "01") main_view.build_the_building_from_single_choice( "StandardLevelResidentialZone", "02") main_view.build_the_building_from_single_choice("DumpingGround", "03") main_view.build_the_building_from_single_choice( "ProductionBuilding", "10") main_view.build_the_building_from_single_choice("WindPlant", "11") main_view.build_the_building_from_single_choice("RopePlant", "12") main_view.build_the_building_from_single_choice("CoalPlant", "13") main_view.build_the_building_from_single_choice("PotatoFarm", "20") main_view.build_the_building_from_single_choice("LettuceFarm", "21") main_view.build_the_building_from_single_choice("BeanFarm", "22") main_view.build_the_building_from_single_choice("CattleFarm", "23") main_view.build_the_building_from_single_choice("MassConventer", "30") main_view.build_the_building_from_single_choice("TradeDistrict", "31") main_view.build_the_building_from_single_choice("PrimarySchool", "32") for building_sublcass in RootClass( self.city_one, self.user_one).get_subclasses_of_all_buildings(): self.assertEqual( building_sublcass.objects.filter(city=self.city_one).count(), 1) for building in [ b for b in RootClass(self.city_one, self.user_one).list_of_buildings if not isinstance(b, TradeDistrict) ]: self.assertTrue(building.if_under_construction) main_view.next_turns(5) for building in RootClass(self.city_one, self.user_one).list_of_buildings: self.assertFalse(building.if_under_construction) main_view.logout() self.create_second_user() LoginPage(self.browser, self.live_server_url).navigate_to_main_throught_login( user=self.user_two, username=self.player_two, password=self.password_two, city=self.city_two, assertIn=self.assertIn, assertTrue=self.assertTrue, ) main_view = MainView(self.browser, self.live_server_url) main_view.build_the_building_from_single_choice("SewageWorks", "00") main_view.build_the_building_from_single_choice("WaterTower", "01") main_view.build_the_building_from_single_choice( "StandardLevelResidentialZone", "02") main_view.build_the_building_from_single_choice("DumpingGround", "03") main_view.build_the_building_from_single_choice( "ProductionBuilding", "10") main_view.build_the_building_from_single_choice("WindPlant", "11") main_view.build_the_building_from_single_choice("RopePlant", "12") main_view.build_the_building_from_single_choice("CoalPlant", "13") main_view.build_the_building_from_single_choice("PotatoFarm", "20") main_view.build_the_building_from_single_choice("LettuceFarm", "21") main_view.build_the_building_from_single_choice("BeanFarm", "22") main_view.build_the_building_from_single_choice("CattleFarm", "23") main_view.build_the_building_from_single_choice("MassConventer", "30") main_view.build_the_building_from_single_choice("TradeDistrict", "31") main_view.build_the_building_from_single_choice("PrimarySchool", "32") for building_sublcass in RootClass( self.city_two, self.user_two).get_subclasses_of_all_buildings(): self.assertEqual( building_sublcass.objects.filter(city=self.city_two).count(), 1) for building in [ b for b in RootClass(self.city_two, self.user_two).list_of_buildings if not isinstance(b, TradeDistrict) ]: self.assertTrue(building.if_under_construction) main_view.next_turns(5) for building in RootClass(self.city_two, self.user_two).list_of_buildings: self.assertFalse(building.if_under_construction)
def test_citizen_allocation(self): self.create_first_user() LoginPage(self.browser, self.live_server_url).navigate_to_main_throught_login( user=self.user_one, username=self.player_one, password=self.password_one, city=self.city_one, assertIn=self.assertIn, assertTrue=self.assertTrue, ) main_view = MainView(self.browser, self.live_server_url) main_view.build_the_building_from_single_choice("WaterTower", "10") main_view.build_the_building_from_single_choice("WaterTower", "12") main_view.build_the_building_from_single_choice("WindPlant", "11") main_view.build_the_building_from_single_choice("WindPlant", "23") main_view.next_turns(3) self.assertEqual( WindPlant.objects.filter(city=self.city_one).count(), 2) self.assertEqual( WaterTower.objects.filter(city=self.city_one).count(), 2) main_view.build_the_building_from_single_choice( "StandardLevelResidentialZone", "02") main_view.next_turns(3) for wind_plant in WindPlant.objects.filter(city=self.city_one): assert wind_plant.employee.count( ) <= wind_plant.elementary_employee_needed for water_tower in WaterTower.objects.filter(city=self.city_one): assert (water_tower.employee.count() <= water_tower.elementary_employee_needed)
def test_school_assign(self): homepage = Homepage(self.browser, self.live_server_url) homepage.navigate("/main/") self.assertIn("Login", self.browser.title) login_page = LoginPage(self.browser, self.live_server_url) login_page.login(username=self.user.username, password="******") self.assertTrue(User.objects.latest("id").is_authenticated) self.assertIn("Miasto {}".format(self.city.name), self.browser.title) main_view = MainView(self.browser, self.live_server_url) self.profile.current_turn = 7 self.profile.save() self.assertTrue(self.profile.if_social_enabled) self.assertEqual(Citizen.objects.count(), 3) self.assertEqual(self.student_one.school_object, None) self.assertEqual(self.student_two.school_object, None) self.assertEqual(self.teacher.workplace_object, None) self.assertEqual(Education.objects.all().count(), 2) RC = RootClass(self.city, self.user) self.assertEqual(RC.citizens_in_city[self.student_one].current_education, None) self.assertEqual(RC.citizens_in_city[self.student_two].current_education, None) self.assertEqual(RC.citizens_in_city[self.teacher].current_education, None) self.assertEqual(RC.citizens_in_city[self.teacher].current_profession, None) self.assertEqual(len(RC.citizens_in_city[self.student_one].educations), 0) self.assertEqual(len(RC.citizens_in_city[self.student_two].educations), 0) self.assertEqual(len(RC.citizens_in_city[self.teacher].educations), 2) self.assertEqual(RC.citizens_in_city[self.student_one].ci.cash, 0) self.assertEqual(RC.citizens_in_city[self.student_two].ci.cash, 0) self.assertEqual( RC.citizens_in_city[self.teacher].ci.cash, decimal.Decimal(100.00) ) self.assertEqual(City.objects.latest("id").cash, decimal.Decimal(9480.00)) main_view.next_turns(2) RC = RootClass(self.city, self.user) self.assertNotEqual( RC.citizens_in_city[self.student_one].current_education, None ) self.assertNotEqual( RC.citizens_in_city[self.student_two].current_education, None ) self.assertNotEqual(RC.citizens_in_city[self.teacher].current_profession, None) self.teacher = Citizen.objects.get(id=self.teacher.id) self.assertEqual(self.teacher.workplace_object, self.school) self.assertEqual(self.student_one.workplace_object, None) self.assertEqual(self.student_two.workplace_object, None) self.assertEqual(RC.citizens_in_city[self.teacher].salary_expectation, 164.83) self.assertEqual(RC.citizens_in_city[self.student_one].salary_expectation, 0) self.assertEqual(RC.citizens_in_city[self.student_two].salary_expectation, 0) self.assertEqual( RC.citizens_in_city[self.student_one].current_education.effectiveness, 0 ) self.assertEqual( RC.citizens_in_city[self.student_two].current_education.effectiveness, 0 ) self.assertEqual( RC.citizens_in_city[self.teacher].current_profession.proficiency, 0.02 ) self.assertEqual( RC.citizens_in_city[self.teacher].current_profession.job_grade, TRAINEE ) self.assertEqual(RC.citizens_in_city[self.student_one].ci.cash, 0) self.assertEqual(RC.citizens_in_city[self.student_two].ci.cash, 0) self.assertEqual(float(RC.citizens_in_city[self.teacher].ci.cash), 261.60) self.assertEqual(float(City.objects.latest("id").cash), 9318.40) self.profile.current_turn = 1 self.profile.save() main_view.next_turns(1) RC = RootClass(self.city, self.user) self.assertEqual( RC.citizens_in_city[self.student_one].current_education.effectiveness, 0.000416, ) self.assertEqual( RC.citizens_in_city[self.student_two].current_education.effectiveness, 0.000416, ) self.assertEqual( RC.citizens_in_city[self.teacher].current_profession.proficiency, 0.04 ) self.assertEqual( RC.citizens_in_city[self.teacher].current_profession.job_grade, TRAINEE ) self.assertEqual(RC.citizens_in_city[self.teacher].salary_expectation, 168.06) self.assertEqual(RC.citizens_in_city[self.student_one].salary_expectation, 0) self.assertEqual(RC.citizens_in_city[self.student_two].salary_expectation, 0) self.assertEqual(RC.citizens_in_city[self.student_one].ci.cash, 0) self.assertEqual(RC.citizens_in_city[self.student_two].ci.cash, 0) self.assertEqual(float(RC.citizens_in_city[self.teacher].ci.cash), 426.43) self.assertEqual(float(City.objects.latest("id").cash), 9153.57) main_view.next_turns(1) RC = RootClass(self.city, self.user) self.assertEqual( RC.citizens_in_city[self.student_one].current_education.effectiveness, 0.00104, ) self.assertEqual( RC.citizens_in_city[self.student_two].current_education.effectiveness, 0.00104, ) self.assertEqual( RC.citizens_in_city[self.teacher].current_profession.proficiency, 0.06 ) self.assertEqual( RC.citizens_in_city[self.teacher].current_profession.job_grade, TRAINEE ) self.assertEqual(RC.citizens_in_city[self.teacher].salary_expectation, 171.3) self.assertEqual(RC.citizens_in_city[self.student_one].salary_expectation, 0) self.assertEqual(RC.citizens_in_city[self.student_two].salary_expectation, 0) self.assertEqual(RC.citizens_in_city[self.student_one].ci.cash, 0) self.assertEqual(RC.citizens_in_city[self.student_two].ci.cash, 0) self.assertEqual(float(RC.citizens_in_city[self.teacher].ci.cash), 594.49) self.assertEqual(float(City.objects.latest("id").cash), 8985.51) main_view.next_turns(1) RC = RootClass(self.city, self.user) self.assertEqual( RC.citizens_in_city[self.student_one].current_education.effectiveness, 0.001872, ) self.assertEqual( RC.citizens_in_city[self.student_two].current_education.effectiveness, 0.001872, ) self.assertEqual( RC.citizens_in_city[self.teacher].current_profession.proficiency, 0.08 ) self.assertEqual( RC.citizens_in_city[self.teacher].current_profession.job_grade, TRAINEE ) self.assertEqual(RC.citizens_in_city[self.teacher].salary_expectation, 174.53) self.assertEqual(RC.citizens_in_city[self.student_one].salary_expectation, 0) self.assertEqual(RC.citizens_in_city[self.student_two].salary_expectation, 0) self.assertEqual(RC.citizens_in_city[self.student_one].ci.cash, 0) self.assertEqual(RC.citizens_in_city[self.student_two].ci.cash, 0) self.assertEqual(float(RC.citizens_in_city[self.teacher].ci.cash), 765.79) self.assertEqual(float(City.objects.latest("id").cash), 8814.21) main_view.next_turns(1) RC = RootClass(self.city, self.user) self.assertEqual( RC.citizens_in_city[self.student_one].current_education.effectiveness, 0.002912, ) self.assertEqual( RC.citizens_in_city[self.student_two].current_education.effectiveness, 0.002912, ) self.assertEqual( RC.citizens_in_city[self.teacher].current_profession.proficiency, 0.1 ) self.assertEqual( RC.citizens_in_city[self.teacher].current_profession.job_grade, TRAINEE ) self.assertEqual(RC.citizens_in_city[self.teacher].salary_expectation, 177.76) self.assertEqual(RC.citizens_in_city[self.student_one].salary_expectation, 0) self.assertEqual(RC.citizens_in_city[self.student_two].salary_expectation, 0) self.assertEqual(RC.citizens_in_city[self.student_one].ci.cash, 0) self.assertEqual(RC.citizens_in_city[self.student_two].ci.cash, 0) self.assertEqual(float(RC.citizens_in_city[self.teacher].ci.cash), 940.32) self.assertEqual(float(City.objects.latest("id").cash), 8639.68) main_view.next_turns(1) RC = RootClass(self.city, self.user) self.assertEqual( RC.citizens_in_city[self.student_one].current_education.effectiveness, 0.00416, ) self.assertEqual( RC.citizens_in_city[self.student_two].current_education.effectiveness, 0.00416, ) self.assertEqual( RC.citizens_in_city[self.teacher].current_profession.proficiency, 0.12 ) self.assertEqual( RC.citizens_in_city[self.teacher].current_profession.job_grade, JUNIOR ) self.assertEqual(RC.citizens_in_city[self.teacher].salary_expectation, 180.99) self.assertEqual(RC.citizens_in_city[self.student_one].salary_expectation, 0) self.assertEqual(RC.citizens_in_city[self.student_two].salary_expectation, 0) self.assertEqual(RC.citizens_in_city[self.student_one].ci.cash, 0) self.assertEqual(RC.citizens_in_city[self.student_two].ci.cash, 0) self.assertEqual(float(RC.citizens_in_city[self.teacher].ci.cash), 1118.08) self.assertEqual(float(City.objects.latest("id").cash), 8461.92)