Files
notifications-api/tests/app/db.py
Leo Hemsted aeb79a0de9 refactor sample_user to create a new create_user function
this create_user function can be imported for use in creating specific
users in your tests, for example

```
from tests.app.db import create_user
def test_create_user_persists_to_database(notify_db_session):
    user = create_user()
    assert User.query.count() == 1
```

this has the benefit of not requiring you to pass the notify_db and
notify_db_session fixtures around, and separating custom object
creation from the fixture dependency trees to aid clarity

I started with sample_user since it has no downstream dependencies, but
the intention is to push this out to all db fixtures eventually. This
is a total conversion, but can be rolled out in a non-breaking manner
by keeping arguments in the fixture, and passing them through to the
new db function - then tests can be updated to use the create_* instead
of sample_* functions as and when you want to
2017-01-10 15:04:28 +00:00

18 lines
491 B
Python

from app.models import User
from app.dao.users_dao import save_model_user
def create_user(mobile_number="+447700900986", email="notify@digital.cabinet-office.gov.uk"):
data = {
'name': 'Test User',
'email_address': email,
'password': 'password',
'mobile_number': mobile_number,
'state': 'active'
}
usr = User.query.filter_by(email_address=email).first()
if not usr:
usr = User(**data)
save_model_user(usr)
return usr