def domain_storagerooms(): storageroom_1 = StorageRoom( code='f853578c-fc0f-4e65-81b8-566c5dffa35a', size=215, price=39, longitude='-0.09998975', latitude='51.75436293', ) storageroom_2 = StorageRoom( code='fe2c3195-aeff-487a-a08f-e0bdc0ec6e9a', size=405, price=66, longitude='0.18228006', latitude='51.74640997', ) storageroom_3 = StorageRoom( code='913694c6-435a-4366-ba0d-da5334a611b2', size=56, price=60, longitude='0.27891577', latitude='51.45994069', ) storageroom_4 = StorageRoom( code='eed76e77-55c1-41ce-985d-ca49bf6c0585', size=93, price=48, longitude='0.33894476', latitude='51.39916678', ) return [storageroom_1, storageroom_2, storageroom_3, storageroom_4]
def domain_storagerooms(): storageroom_1 = StorageRoom( code=uuid.uuid4(), size=215, price=39, longitude=-0.09998975, latitude=51.75436293, ) storageroom_2 = StorageRoom( code=uuid.uuid4(), size=405, price=66, longitude=0.18228006, latitude=51.74640997, ) storageroom_3 = StorageRoom( code=uuid.uuid4(), size=56, price=60, longitude=0.27891577, latitude=51.45994069, ) storageroom_4 = StorageRoom( code=uuid.uuid4(), size=93, price=48, longitude=0.33894476, latitude=51.39916678, ) return [storageroom_1, storageroom_2, storageroom_3, storageroom_4]
def test_storageroom_model_comparison(): storageroom_dict = { 'code': uuid.uuid4(), 'size': 200, 'price': 10, 'longitude': -0.09998975, 'latitude': 51.75436293 } storageroom1 = StorageRoom.from_dict(storageroom_dict) storageroom2 = StorageRoom.from_dict(storageroom_dict) assert storageroom1 == storageroom2
def test_storageroom_model_init(): code = uuid.uuid4() storageroom = StorageRoom(code, size=200, price=10, longitude='-0.09998975', latitude='51.75436293') assert storageroom.code == code assert storageroom.size == 200 assert storageroom.price == 10 assert storageroom.longitude == -0.09998975 assert storageroom.latitude == 51.75436293 def test_storageroom_model_from_dict(): code = uuid.uuid4() storageroom = StorageRoom.from_dict({ 'code': code, 'size': 200, 'price': 10, 'longitude': '-0.09998975', 'latitude': '51.75436293' }) assert storageroom.code == code assert storageroom.size == 200 assert storageroom.price == 10 assert storageroom.longitude == -0.09998975 assert storageroom.latitude == 51.75436293
def domain_storagerooms(self): first_storageroom = StorageRoom( code='123', size=100, price=10, longitude='-0.0911111', latitude='51.751111') second_storageroom = StorageRoom( code='456', size=150, price=20, longitude='-0922222', latitude='51.75222') return [first_storageroom, second_storageroom]
def list(self, filters=None): if not filters: return self._entries result = [] result.extend(self._entries) for key, value in filters.items(): result = [e for e in result if self._check(e, key, value)] return [StorageRoom.from_dict(r) for r in result]
def test_storageroom_model_init(): code = uuid.uuid4() storageroom = StorageRoom(code, size=200, price=10, longitude='-0.09998975', latitude='51.75436293') assert storageroom.code == code assert storageroom.size == 200 assert storageroom.price == 10 assert storageroom.longitude == -0.09998975 assert storageroom.latitude == 51.75436293
def test_storageroom_model_from_dict(): code = uuid.uuid4() storageroom = StorageRoom.from_dict({ 'code': code, 'size': 200, 'price': 10, 'longitude': -0.09998975, 'latitude': 51.75436293 }) assert storageroom.code == code assert storageroom.size == 200 assert storageroom.price == 10 assert storageroom.longitude == -0.09998975 assert storageroom.latitude == 51.75436293
def test_serialize_domain_storageroom(): room = StorageRoom('f853578c-fc0f-4e65-81b8-566c5dffa35a', size=200, price=10, longitude='-0.09998975', latitude='51.75436293') expected_json = """ { "code": "f853578c-fc0f-4e65-81b8-566c5dffa35a", "size": 200, "price": 10, "longitude": -0.09998975, "latitude": 51.75436293 } """ assert json.loads(json.dumps( room, cls=srs.StorageRoomEncoder)) == json.loads(expected_json)
def test_serialize_domain_storageroom(): room = StorageRoom('some_uuid', size=200, price=10, longitude='-0.09123', latitude='51.761234') expected_json = ''' { "code": "some_uuid", "size": 200, "price": 10, "longitude": -0.09123, "latitude": 51.761234 } ''' result = json.dumps(room, cls=storageroom_serializer.StorageRoomEncoder) assert json.loads(result) == json.loads(expected_json)
def test_serialize_domain_storageroom(): code = uuid.uuid4() room = StorageRoom(code=code, size=200, price=10, longitude=-0.09998975, latitude=51.75436293) expected_json = """ {{ "code": "{}", "size": 200, "price": 10, "longitude": -0.09998975, "latitude": 51.75436293 }} """.format(code) json_storageroom = json.dumps(room, cls=srs.StorageRoomEncoder) assert json.loads(json_storageroom) == json.loads(expected_json)
import json from unittest import mock from rentomatic.domain.storageroom import StorageRoom from rentomatic.shared import response_object as res first_storageroom_dict = { 'code': '3251a5bd-86be-428d-8ae9-6e51a8048c33', 'size': 200, 'price': 10, 'longitude': -0.09998975, 'latitude': 51.75436293 } first_storageroom_domain_model = StorageRoom.from_dict(first_storageroom_dict) storagerooms = [first_storageroom_domain_model] @mock.patch('rentomatic.use_cases.storageroom_use_cases.StorageRoomListUseCase' ) def test_get(mock_use_case, client): mock_use_case().execute.return_value = res.ResponseSuccess(storagerooms) http_response = client.simulate_get('/storagerooms') assert json.loads( http_response.content.decode('UTF-8')) == [first_storageroom_dict] assert http_response.status_code == 200 assert http_response.headers.get('mimetype') == 'application/json'
import json from unittest import mock from rentomatic.domain.storageroom import StorageRoom from rentomatic.shared import response_object as res storageroom1_dict = { 'code': '3251a5bd-86be-428d-8ae9-6e51a8048c33', 'size': 200, 'price': 10, 'longitude': -0.09998975, 'latitude': 51.75436293 } storageroom1_domain_model = StorageRoom.from_dict(storageroom1_dict) storagerooms = [storageroom1_domain_model] @mock.patch('rentomatic.use_cases.storageroom_use_case.StorageRoomListUseCase') def test_get(mock_use_case, client): mock_use_case().execute.return_value = res.ResponseSuccess(storagerooms) http_response = client.get('/storagerooms') assert json.loads( http_response.data.decode('UTF-8')) == [storageroom1_dict] assert http_response.status_code == 200 assert http_response.mimetype == 'application/json'
def storageroom_model(storageroom_dict): return StorageRoom.from_dict(storageroom_dict)