Esempio n. 1
0
 def test_buy_building_with_higher_level_than_0(self):
     self.company.balance = self.land.buy_cost + 1
     self.land.purchase_landscape(self.company)
     restaurant: BuildingType = BuildingType.objects.get_building_by_type('restaurant')
     self.company.balance = restaurant.get_buy_cost(1)
     with self.assertRaises(UnableToConstructBuilding):
         BuildingBuilder.construct("restaurant", 'myfirstbuilding', self.company,
                                   'buy', 1, self.land)
Esempio n. 2
0
 def test_build_fake_building(self):
     self.company.balance = self.land.buy_cost + 1
     self.land.purchase_landscape(self.company)
     restaurant: BuildingType = BuildingType.objects.get_building_by_type('market')
     self.company.balance = restaurant.get_rent_cost(0)
     with self.assertRaises(UnableToConstructBuilding):
         BuildingBuilder.construct("fakebuilding", 'myfirstbuilding', self.company,
                                   'buy', 1, self.land)
Esempio n. 3
0
 def test_rent_building_at_negative_level_than_land(self):
     self.company.balance = self.land.buy_cost + 1
     self.land.purchase_landscape(self.company)
     restaurant: BuildingType = BuildingType.objects.get_building_by_type('market')
     self.company.balance = restaurant.get_rent_cost(-1)
     with self.assertRaises(UnableToConstructBuilding):
         BuildingBuilder.construct("market", 'mymarket', self.company,
                                   'rent', -1, self.land)
Esempio n. 4
0
 def purchase_building(self):
     mine: BuildingType = BuildingType.objects.get_building_by_type(
         'supreme mine')
     self.company.balance = mine.get_buy_cost()
     building = BuildingBuilder.construct(mine.name, 'myfirstbuilding',
                                          self.company, 'buy', 0, self.land)
     return building
Esempio n. 5
0
 def test_build_with_storage(self):
     mine: BuildingType = BuildingType.objects.get_building_by_type('supreme mine')
     self.company.balance = mine.get_buy_cost()
     building = BuildingBuilder.construct(mine.name, 'myfirstbuilding', self.company,
                                          'buy', 0, self.land)
     self.assertEqual(building.storage.current_capacity, 0)
     
Esempio n. 6
0
 def test_building_belong_to(self):
     self.company.balance = self.land.buy_cost + 1
     self.land.purchase_landscape(self.company)
     restaurant: BuildingType = BuildingType.objects.get_building_by_type('restaurant')
     self.company.balance = restaurant.get_buy_cost()
     building = BuildingBuilder.construct("restaurant", 'myfirstbuilding', self.company,
                                          'buy', 0, self.land)
     self.assertEqual(building.belongs_to(self.land), True)
Esempio n. 7
0
 def test_rent_building_at_equal_land_level(self):
     self.company.balance = self.land.buy_cost + 1
     self.land.purchase_landscape(self.company)
     market: BuildingType = BuildingType.objects.get_building_by_type('market')
     self.company.balance = market.get_rent_cost(self.land.level)
     building = BuildingBuilder.construct("market", 'mymarket', self.company,
                                          'rent', self.land.level, self.land)
     
     self.assertEqual(building.building_name, 'mymarket')
Esempio n. 8
0
 def test_rent_building_at_0(self):
     self.company.balance = self.land.buy_cost + 1
     self.land.purchase_landscape(self.company)
     restaurant: BuildingType = BuildingType.objects.get_building_by_type('market')
     self.company.balance = restaurant.get_rent_cost(0)
     building = BuildingBuilder.construct("market", 'mymarket', self.company,
                                          'rent', 0, self.land)
     
     self.assertEqual(building.building_name, 'mymarket')
Esempio n. 9
0
    def post(self, request: HttpRequest, land_id):
        building_level = request.POST.get("level", 1)
        building_type = request.POST.get("buildingType", None)
        building_name = request.POST.get("buildingName", None)
        method = request.POST.get("method", None)

        try:
            landscape: Landscape = Landscape.objects.get(land_id=land_id)

        except Landscape.DoesNotExist:
            data = {'error': True, 'message': 'Land id not found'}
            return JsonResponse(data)

        builder = BuildingBuilder(landscape, building_level, building_type,
                                  building_name)
        try:
            builder.construct_building(request.company, method)
        except UnableToConstructBuilding:
            data = {
                'error': True,
                'message': 'Error occured while constructing building'
            }
            return JsonResponse(data)
Esempio n. 10
0
 def setUp(self):
     self.load_data()
     self.land: Landscape = Landscape.objects.create_land()
     self.user: User = User.objects.create_user('johnyTest',
                                                '*****@*****.**',
                                                'johnpassword')
     self.company: Company = Company.objects.create_company(
         'johnCompany', self.user)
     self.company.balance = self.land.buy_cost + 1
     self.land.purchase_landscape(self.company)
     building: BuildingType = BuildingType.objects.get_building_by_type(
         'supreme mine')
     self.company.balance = building.get_rent_cost(0)
     self.building = BuildingBuilder.construct("supreme mine", 'mymine',
                                               self.company, 'rent', 0,
                                               self.land)