Completed
Push — master ( d1f8e5...fb0636 )
by Vijay
01:00
created

test_organisation_flow()   D

Complexity

Conditions 8

Size

Total Lines 78

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 78
rs 4.7899
cc 8

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
import re
2
from .. import factories as f
3
4
5
def test_organisation_flow(base_url, browser, outbox):
6
    user = f.create_user()
7
    user.set_password('123123')
8
    user.save()
9
    url = base_url + '/accounts/login/'
10
    browser.visit(url)
11
    browser.fill('login', user.email)
12
    browser.fill('password', '123123')
13
    browser.find_by_css('[type=submit]')[0].click()
14
    assert len(outbox) == 1
15
    mail = outbox[0]
16
    confirm_link = re.findall(r'http.*/accounts/.*/', mail.body)
17
    assert confirm_link
18
    browser.visit(confirm_link[0])
19
    assert browser.title, "Confirm E-mail Address"
20
    browser.find_by_css('[type=submit]')[0].click()
21
22
    poc_type = f.create_usertype(slug='poc', display_name='poc')
23
    user.profile.usertype.add(poc_type)
24
    user.save()
25
    location1 = f.create_locaiton(name='location1')
26
27
    url = base_url + '/organisation/'
28
    browser.fill('login', user.email)
29
    browser.fill('password', '123123')
30
    browser.find_by_css('[type=submit]')[0].click()
31
    browser.visit(url)
32
    org_create_link = browser.find_by_text('Add Organisation')[0]
33
    assert org_create_link
34
    org_create_link.click()
35
    browser.select('organisation_type', 1)
36
    browser.fill('name', 'Org1')
37
    browser.fill('description', 'Description')
38
    browser.select('location', location1.id)
39
    browser.fill('organisation_role', 'Role1')
40
    browser.find_by_css('[type=submit]')[0].click()
41
    # browser.find_by_css('[clickable-row]')[0].click()
42
    browser.find_by_text('Org1')[0].click()
43
    browser.find_by_text('Edit')[0].click()
44
    browser.fill('organisation_role', 'Role updated')
45
    browser.find_by_css('[type=submit]')[0].click()
46
    browser.find_by_text('Org1')[0].click()
47
    browser.find_by_text('Delete')[0].click()
48
    org = f.create_organisation(location=location1)
49
    org.user.add(user)
50
    org.save()
51
    url = base_url + '/organisation/{}/edit/'.format(org.id)
52
    browser.visit(url)
53
    browser.fill('organisation_role', 'Role updated')
54
    browser.find_by_css('[type=submit]')[0].click()
55
56
    url = base_url + '/organisation/{}/'.format(org.id)
57
    browser.visit(url)
58
    delete_org_link = browser.find_by_text('Delete')[0]
59
    assert delete_org_link
60
    delete_org_link.click()
61
62
    # for Exceptions
63
64
    url = base_url + '/organisation/create/'
65
    browser.visit(url)
66
    browser.select('organisation_type', 1)
67
    browser.fill('name', 'Org22')
68
    browser.fill('description', 'Description22')
69
    # browser.select('location', location1.id)
70
    browser.fill('organisation_role', 'Role1')
71
    browser.find_by_css('[type=submit]')[0].click()
72
    assert browser.find_by_text('This field is required.')[0]
73
74
    # user as regional lead
75
    lead_type = f.create_usertype(slug='lead', display_name='lead')
76
    user.profile.usertype.remove(poc_type)
77
    user.profile.usertype.add(lead_type)
78
    user.save()
79
    url = base_url + '/organisation/'
80
    browser.visit(url)
81
    org_leadview_link = browser.find_by_text('My Organisations')[0]
82
    assert org_leadview_link
83