diff --git a/src/velofy/db/grids.py b/src/velofy/db/grids.py index f035174..dae6013 100644 --- a/src/velofy/db/grids.py +++ b/src/velofy/db/grids.py @@ -74,7 +74,9 @@ class Grid(meta.Base): Returns: grid: including `grid.pixels` with the associated `city.addresses` """ - grid = cls(city=city, side_length=side_length) + grid = cls(side_length=side_length) + + city.grids.append(grid) # `Pixel`s grouped by `.n_x`-`.n_y` coordinates. pixels = {} @@ -102,7 +104,9 @@ class Grid(meta.Base): n_x, n_y = address.x // side_length, address.y // side_length # ... and create a new `Pixel` object if necessary. if (n_x, n_y) not in pixels: - pixels[(n_x, n_y)] = db.Pixel(grid=grid, n_x=n_x, n_y=n_y) + pixels[(n_x, n_y)] = db.Pixel(n_x=n_x, n_y=n_y) + grid.pixels.append(pixels[(n_x, n_y)]) + pixel = pixels[(n_x, n_y)] # Create an association between the `address` and `pixel`. diff --git a/tests/db/fake_data/fixture_makers.py b/tests/db/fake_data/fixture_makers.py index 570e63c..571e506 100644 --- a/tests/db/fake_data/fixture_makers.py +++ b/tests/db/fake_data/fixture_makers.py @@ -13,7 +13,11 @@ def make_address(city): def func(**kwargs): """Create an `Address` object in the `city`.""" - return factories.AddressFactory.build(city=city, **kwargs) + address = factories.AddressFactory.build(**kwargs) + + city.addresses.append(address) + + return address return func @@ -58,7 +62,11 @@ def make_restaurant(make_address): if address is None: address = make_address() - return factories.RestaurantFactory.build(address=address, **kwargs) + restaurant = factories.RestaurantFactory.build(**kwargs) + + address.restaurants.append(restaurant) + + return restaurant return func @@ -93,15 +101,18 @@ def make_order(make_address, make_courier, make_customer, make_restaurant): if courier is None: courier = make_courier() - return factory_cls.build( + order = factory_cls.build( customer=make_customer(), # assume a unique `Customer` per order - restaurant=restaurant, courier=courier, pickup_address=restaurant.address, # no `Address` history delivery_address=make_address(), # unique `Customer` => new `Address` **kwargs, ) + restaurant.orders.append(order) + + return order + return func