~homeworkprod/byceps

ref: 43bf3630475839afde6e691f0ac561dcb01aaba6 byceps/testfixtures/user.py -rw-r--r-- 1.4 KiB
43bf3630 — Jochen Kupperschmidt Upgrade pytest on Travis CI to get v3.3 rather than v3.0 provided by default 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
testfixtures.user
~~~~~~~~~~~~~~~~~

:Copyright: 2006-2017 Jochen Kupperschmidt
:License: Modified BSD, see LICENSE for details.
"""

from datetime import date

from byceps.database import generate_uuid
from byceps.services.user.models.detail import UserDetail
from byceps.services.user import creation_service as user_creation_service


def create_user(screen_name='Faith', *, email_address=None, enabled=True):
    user_id = generate_uuid()

    if not email_address:
        email_address = 'user{}@example.com'.format(user_id)

    user = user_creation_service.build_user(screen_name, email_address)
    user.id = user_id
    user.enabled = enabled

    return user


def create_user_with_detail(screen_name='Faith', *,
                            email_address=None,
                            enabled=True,
                            first_names='John Joseph',
                            last_name='Doe',
                            date_of_birth=None):
    user = create_user(screen_name, email_address=email_address,
                       enabled=enabled)

    detail = UserDetail(user=user)
    detail.first_names = first_names
    detail.last_name = last_name
    detail.date_of_birth = (date_of_birth if date_of_birth else date(1993, 2, 15))
    detail.country = 'State of Mind'
    detail.zip_code = '31337'
    detail.city = 'Atrocity'
    detail.street = 'Elite Street 1337'

    return user