Skip to content

Commit

Permalink
Generate consistent data for browser tests
Browse files Browse the repository at this point in the history
Also reorganised factories a bit so the generation of all the
other objects is inside the location/resource factories instead
of the management command.

Fixes embassynetwork#376
  • Loading branch information
bfirsh authored and jonathan-s committed Feb 27, 2019
1 parent 9cf2515 commit f5394e7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 43 deletions.
42 changes: 41 additions & 1 deletion core/factory_apps/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
52 changes: 12 additions & 40 deletions core/management/commands/generate_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'))
4 changes: 2 additions & 2 deletions cypress/integration/booking_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5394e7

Please sign in to comment.