Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced Faker with Forgery_py #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions timeclock.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)

if os.getenv('FLASK_ENV') == 'development':
from faker import Faker
import forgery_py
from app.utils import divisions, tags

app = create_app(os.getenv("FLASK_CONFIG") or "default")
Expand Down Expand Up @@ -82,12 +82,16 @@ def setup_roles():
@app.cli.command("create_dev_users")
def create_dev_users():
"""Create users for development."""
from sqlalchemy.exc import IntegrityError
from random import choice, randint

tag_count = Tag.query.count()

# Administrator
faker = Faker()
first_name = faker.first_name()
last_name = faker.last_name()
tag_id = faker.random_int(min=1, max=len(tags) - 1)
division = faker.random_elements(elements=divisions, length=1)[0][0]
first_name = forgery_py.name.first_name()
last_name = forgery_py.name.last_name()
tag_id = randint(1, tag_count - 1)
division = choice(divisions)[0]
administrator = User(
email="{first_initial}{last_name}@{email_domain}".format(
first_initial=first_name[0].lower(),
Expand All @@ -106,10 +110,10 @@ def create_dev_users():
administrator.password_list.update(administrator.password_hash)

# Supervisor
first_name = faker.first_name()
last_name = faker.last_name()
tag_id = faker.random_int(min=1, max=len(tags) - 1)
division = faker.random_elements(elements=divisions, length=1)[0][0]
first_name = forgery_py.name.first_name()
last_name = forgery_py.name.last_name()
tag_id = randint(1, tag_count - 1)
division = choice(divisions)[0]
supervisor = User(
email="{first_initial}{last_name}@{email_domain}".format(
first_initial=first_name[0].lower(),
Expand All @@ -129,10 +133,10 @@ def create_dev_users():

# Users
for i in range(10):
first_name = faker.first_name()
last_name = faker.last_name()
tag_id = faker.random_int(min=1, max=len(tags) - 1)
division = faker.random_elements(elements=divisions, length=1)[0][0]
first_name = forgery_py.name.first_name()
last_name = forgery_py.name.last_name()
tag_id = randint(1, tag_count - 1)
division = choice(divisions)[0]
user = User(
email="{first_initial}{last_name}@{email_domain}".format(
first_initial=first_name[0].lower(),
Expand All @@ -150,4 +154,7 @@ def create_dev_users():
db.session.add(user)
user.password_list.update(user.password_hash)

db.session.commit()
try:
db.session.commit()
except IntegrityError:
db.session.rollback()