def test_mismatch_market_type(self): self._formatted_method_name = "Test testing throwing the Flat" \ " Parameter Mismatch Exception if the value" \ " of the market type is incorrect" calc = PricesCalculator("AIzaSyBEmx5P3vl4ox4OU6nPgwTbU9k-_0Zm6Lo") address = Address("", 49.95153, 18.609122) calc.selected_address = address market_type = "pierwotFny" with self.assertRaises( exception.FlatParameterMismatchException) as context: calc.calculate_house_price("blok", market_type, "drewno", 2000, 25, False, False, False, True, True, False, False) self.assertTrue("wskazany rodzaj rynku '" + market_type + "' nie istnieje" in str(context.exception))
def test_too_small_value_of_year(self): self._formatted_method_name = "Test testing throwing the Construction" \ " Year Violation Exception if the value" \ " of the construction year is too low" \ " (less than 1900)" calc = PricesCalculator("AIzaSyBEmx5P3vl4ox4OU6nPgwTbU9k-_0Zm6Lo") address = Address("", 49.95153, 18.609122) calc.selected_address = address with self.assertRaises( exception.ConstructionYearViolationException) as context: calc.calculate_house_price("blok", "pierwotny", "drewno", 1500, 25, False, False, False, True, True, False, False) self.assertTrue('rok budowy nie moze byc mniejszy niz 1900' in str( context.exception))
def test_name_of_reference_city(self): self._formatted_method_name = "Test testing calculating a reference city" \ " called Katowice in the case of providing" \ " coordinates of an apartment located in the" \ " city of Czestochowa" calc = PricesCalculator("AIzaSyBEmx5P3vl4ox4OU6nPgwTbU9k-_0Zm6Lo") address = Address("", 50.8118195, 19.1203094) calc.selected_address = address calculator_result = calc.calculate_house_price("blok", "pierwotny", "drewno", 2000, 25, False, False, False, True, True, False, False) self.assertEqual(calculator_result.nearest_reference_city.name, "Katowice")
def test_too_big_value_of_year(self): self._formatted_method_name = "Test testing throwing the Construction" \ " Year Violation Exception if the value" \ " of the construction year is too high" \ " (more than present)" calc = PricesCalculator("AIzaSyBEmx5P3vl4ox4OU6nPgwTbU9k-_0Zm6Lo") address = Address("", 49.95153, 18.609122) calc.selected_address = address datetime_now_year = datetime.today().year with self.assertRaises( exception.ConstructionYearViolationException) as context: calc.calculate_house_price("blok", "pierwotny", "drewno", datetime_now_year + 1, 25, False, False, False, True, True, False, False) self.assertTrue('rok budowy nie moze byc wiekszy niz obecny' in str( context.exception))
def autocomplete_addresses(self, autocomplete_addresses): if autocomplete_addresses: google_result = self._google_maps.geocode(autocomplete_addresses, language="pl") if google_result: if self._autocomplete_addresses: self._autocomplete_addresses = [] for address in google_result: for address_component in address['address_components']: if address_component['types'][0] == "country": if address_component['long_name'] == "Polska": self._autocomplete_addresses.append( Address( address['formatted_address'], address['geometry']["location"]["lat"], address['geometry']["location"] ["lng"])) break
return "error" display_addresses = str(sys.argv[1]) switch_option = str_to_bool(display_addresses) if switch_option == "": if sys.argv.__len__() != 17: print("Podano niewystarczającą ilość argumentów do " "przeprowadzenia kalkulacji.") sys.exit(1) else: google_api_key = str(sys.argv[2]) try: calc = PricesCalculator(google_api_key) geocoded_address = Address("", float(sys.argv[3]), float(sys.argv[4])) calc.selected_address = geocoded_address calc.calculate_house_price(str(sys.argv[5]), str(sys.argv[6]), str(sys.argv[7]), int(sys.argv[8]), int(sys.argv[9]), bool(str_to_bool(sys.argv[10])), bool(str_to_bool(sys.argv[11])), bool(str_to_bool(sys.argv[12])), bool(str_to_bool(sys.argv[13])), bool(str_to_bool(sys.argv[14])), bool(str_to_bool(sys.argv[15])), bool(str_to_bool(sys.argv[16]))) print("WYNIKI KALKULACJI:") print("\t*miasto odniesiania*") print("\t\t- nazwa: " +