Skip to content
This repository has been archived by the owner on Dec 19, 2021. It is now read-only.

Commit

Permalink
Create separate seed file for system testing (#389)
Browse files Browse the repository at this point in the history
This seeds the db with only an admin user for system testing.
This should also speed up the system tests on the CI.
  • Loading branch information
NickSchimek committed Oct 17, 2021
1 parent 30c8943 commit beb4451
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/system_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Seed db
run: |
pipenv run flask db create
pipenv run flask db seed
pipenv run flask db minimal_seed
- name: Start Server
run: pipenv run flask run &
Expand Down
29 changes: 18 additions & 11 deletions data/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,15 @@


class Seed:
def minimal_data(self):
self.create_admin()

def data(self):
print("Seeding the db... This may take a few minutes.")
self.faker = Faker()
self.rand = random.Random()

Admin.create(
schema=UserSchema,
payload={
"email": "user1@dwellingly.org",
"role": RoleEnum.ADMIN.value,
"firstName": "user1",
"lastName": "tester",
"password": "1234",
"phone": "555-555-5555",
},
)
self.create_admin()

# Create some admins
for _ in range(7):
Expand Down Expand Up @@ -239,6 +233,19 @@ def data(self):
print("\n")
print("#####################################")

def create_admin(self):
Admin.create(
schema=UserSchema,
payload={
"email": "user1@dwellingly.org",
"role": RoleEnum.ADMIN.value,
"firstName": "user1",
"lastName": "tester",
"password": "1234",
"phone": "555-555-5555",
},
)

def user_attributes(self, role=None, archived=False):
attrs = {
"email": self.faker.unique.email(),
Expand Down
7 changes: 7 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ def seed():
Seed().data()


@dbsetup.cli.command("minimal_seed")
def minimal_seed():
from data.seed import Seed

Seed().minimal_data()


@dbsetup.cli.command("create")
def create():
"""Creates database tables"""
Expand Down

0 comments on commit beb4451

Please sign in to comment.