admin   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 61
rs 10
c 0
b 0
f 0
wmc 6

2 Functions

Rating   Name   Duplication   Size   Complexity  
A step_impl() 0 3 1
A create_user() 0 8 1
1
from behave import when, then, given
2
3
from django.contrib.auth.models import User
4
5
6
ADMIN_USERNAME = 'test'
7
ADMIN_PASSWORD = 'test'
8
ADMIN_EMAIL = '[email protected]'
9
10
11
@given(u'an admin user exists')
12
def create_user(context):
13
    context.admin = User.objects.create_user(
14
        username=ADMIN_USERNAME,
15
        password=ADMIN_PASSWORD,
16
        email=ADMIN_EMAIL,
17
        is_staff=True,
18
        is_superuser=True,
19
    )
20
21
22
@when(u'I go to the admin page')
23
def step_impl(context):
24
    context.get_browser().visit(context.base_url + '/admin')
25
26
27
@when(u'I enter my username and password')
28
def step_impl(context):
29
    browser = context.get_browser()
30
31
    browser.find_by_name('username').fill(ADMIN_USERNAME)
32
    browser.find_by_name('password').fill(ADMIN_PASSWORD)
33
    browser.find_by_value('Log in').first.click()
34
35
36
@when(u'I go to my user page')
37
def step_impl(context):
38
    browser = context.get_browser()
39
40
    browser.click_link_by_text('Users')
41
    browser.click_link_by_text(ADMIN_USERNAME)
42
43
44
@then(u'I should be logged in as an admin')
45
def step_impl(context):
46
    browser = context.get_browser()
47
48
    page_text = browser.find_by_tag('body').first.text
49
50
    assert browser.is_text_present('Django administration')
51
    assert browser.is_text_present(
52
        'Welcome, {}.'.format(ADMIN_USERNAME).upper()
53
    )
54
55
56
@then(u'I should see the email address I chose')
57
def step_impl(context):
58
    browser = context.get_browser()
59
60
    assert ADMIN_EMAIL in browser.find_by_name('email').first.value
61