diff --git a/core/factory_apps/location.py b/core/factory_apps/location.py index 9ec3f4ed..47bb6244 100644 --- a/core/factory_apps/location.py +++ b/core/factory_apps/location.py @@ -99,6 +99,31 @@ def add_backing(self, create, extracted, **kwargs): # users. pass + @factory.post_generation + def add_stuff(self, create, extracted, **kwargs): + # avoid recursive import + from . import events + from . import payment + + LocationFee(location=self) + + # event things + event_admin = events.EventAdminGroupFactory(location=self) + event_series = events.EventSeriesFactory() + events.EventFactory( + location=self, admin=event_admin, series=event_series + ) + events.EventNotificationFactory() + + # flat pages + menu = LocationMenuFactory(location=self) + LocationFlatPageFactory(menu=menu) + + # payments + subscription = payment.SubscriptionFactory(location=self) + payment.SubscriptionBillFactory(subscription=subscription) + + class ResourceFactory(factory.DjangoModelFactory): class Meta: @@ -111,7 +136,22 @@ class Meta: summary = factory.Faker('sentence') cancellation_policy = factory.Faker('text') image = factory.django.ImageField(color='green') - # JKS add backing + + @factory.post_generation + def add_stuff(self, create, extracted, **kwargs): + # avoid recursive import + from . import payment + + CapacityChangeFactory(resource=self) + # generates new users who will also be the location residents + BackingFactory(resource=self) + + # payment + bill = payment.BookingBillFactory() + payment.BillLineItem(bill=bill) + use = payment.UseFactory(location=self.location, resource=self) + payment.BookingFactory(bill=bill, use=use) + payment.PaymentFactory(bill=bill) # Note: this doesn't get used because it's really just an indexing mechanism to diff --git a/core/management/commands/generate_test_data.py b/core/management/commands/generate_test_data.py index dfacf962..b2c86430 100644 --- a/core/management/commands/generate_test_data.py +++ b/core/management/commands/generate_test_data.py @@ -7,12 +7,9 @@ from faker import Faker -from core.factory_apps import location -from core.factory_apps import communication -from core.factory_apps import events -from core.factory_apps import payment -from core.factory_apps import user -from core.models import Currency +from core.factory_apps.communication import EmailtemplateFactory +from core.factory_apps.location import LocationFactory, ResourceFactory +from core.factory_apps.user import SuperUserFactory class Command(BaseCommand): @@ -25,47 +22,22 @@ def handle(self, *args, **options): # create a known super user. this user will also be set as a location admin for # all locations. - user.SuperUserFactory() + SuperUserFactory() # communication. these emails will also generate users. - communication.EmailtemplateFactory() + EmailtemplateFactory() # The email sending tasks expect there to be locations with these slugs - location.LocationFactory(slug="embassysf", name="Embassy SF") - location.LocationFactory(slug="amsterdam", name="Embassy Amsterdam") - location.LocationFactory(slug="redvic", name="The Red Victorian") + location = LocationFactory(slug="embassysf", name="Embassy SF") + ResourceFactory(location=location, name="Batcave") + ResourceFactory(location=location, name="Ada Lovelace") - # Building location specific things - for _ in range(10): - locationobj = location.LocationFactory() - resource = location.ResourceFactory(location=locationobj) - location.LocationFee(location=locationobj) + location = LocationFactory(slug="amsterdam", name="Embassy Amsterdam") + ResourceFactory(location=location, name="Some room") - menu = location.LocationMenuFactory(location=locationobj) - location.LocationFlatPageFactory(menu=menu) + location = LocationFactory(slug="redvic", name="The Red Victorian") + ResourceFactory(location=location, name="Another room") - location.CapacityChangeFactory(resource=resource) - # generates new users who will also be the location residents - backing = location.BackingFactory(resource=resource) - - # event things - event_admin = events.EventAdminGroupFactory(location=locationobj) - event_series = events.EventSeriesFactory() - events.EventFactory( - location=locationobj, admin=event_admin, series=event_series - ) - events.EventNotificationFactory() - - # payment - subscription = payment.SubscriptionFactory(location=locationobj) - payment.SubscriptionBillFactory(subscription=subscription) - - bill = payment.BookingBillFactory() - payment.BillLineItem(bill=bill) - use = payment.UseFactory(location=locationobj, resource=resource) - payment.BookingFactory(bill=bill, use=use) - - payment.PaymentFactory(bill=bill) self.stdout.write(self.style.SUCCESS('Successfully generated testdata')) diff --git a/cypress/integration/booking_spec.js b/cypress/integration/booking_spec.js index 6a478300..47058d45 100644 --- a/cypress/integration/booking_spec.js +++ b/cypress/integration/booking_spec.js @@ -4,9 +4,9 @@ const randomstring = require("randomstring"); describe("Booking a room", function() { it("New user flow", function() { cy.visit("/"); - cy.contains("Mary Pass").click(); + cy.contains("Embassy SF").click(); cy.contains("View all rooms").click(); - cy.contains("Rhonda Hicks").click({ force: true }); + cy.contains("Ada Lovelace").click({ force: true }); cy.get("input[name=arrive]").focus(); // Pick next month so all the dates are available