def get_property_by_id(self, id: int): data = self.properties.ix[int(id)].to_dict() property = Property(**data) property.id = id return property
def add_property(self, property: Property): property.provinces = [province.name for province in self.property_provinces(property)]; dict = property.__dict__ data = DataFrame([dict], columns=dict.keys()) self.properties = self.properties.append([data], ignore_index=True) index = self.properties.index[-1] property.id = index
def get_properties(self, area: Area = None) -> List[Property]: if area is not None: properties = self.properties.query('%d < x < %d and %d > y > %d' % (area.ax, area.bx, area.ay, area.by)) else: properties = self.properties return [Property(**property.to_dict()).with_id(int(index)) for index, property in properties.iterrows()]
def post(self): "register a Spotippos property" try: property = Property(**api.payload) container.world_service.add_property(property) except ValueError as error: return 400, str(error) return property
def test_should_search_properties(self): property = Property( title='foo', x=500, y=600, price=120000, beds=2, baths=2, description='some bar', squareMeters=200, ) container.world_service.add_property(property) self.assertEqual(property.provinces, ['Gode', 'Ruja']) property.x = 520 container.world_service.add_property(property) properties = container.world_service.get_properties( Area(0, 1000, 600, 500)) self.assertEqual(len(properties), 2)
def test_should_add_properties(self): property = Property( title='foo', x=100, y=100, price=120000, beds=2, baths=2, description='some bar', squareMeters=200, ) container.world_service.add_property(property) self.assertEqual(property.provinces, ['Scavy'])
def test_should_validate_property(self): with self.assertRaises(AssertionError): property = Property( title='foo', x=1500, y=600, price=120000, beds=2, baths=2, description='some bar', squareMeters=200, ) with self.assertRaises(AssertionError): property = Property( title='foo', x=1300, y=1200, price=120000, beds=2, baths=2, description='some bar', squareMeters=200, )