Completed
Push — master ( 33e372...3f47a5 )
by Vijay
10s
created

test_org_edit_flow()   F

Complexity

Conditions 9

Size

Total Lines 77

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 9
dl 0
loc 77
rs 3.9059
c 1
b 0
f 1

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, created_by=user)
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
84
85
def test_org_edit_flow(base_url, browser, outbox):
86
    user = f.create_user()
87
    user.set_password('123123')
88
    user.save()
89
    url = base_url + '/accounts/login/'
90
    browser.visit(url)
91
    browser.fill('login', user.email)
92
    browser.fill('password', '123123')
93
    browser.find_by_css('[type=submit]')[0].click()
94
    assert len(outbox) == 1
95
    mail = outbox[0]
96
    confirm_link = re.findall(r'http.*/accounts/.*/', mail.body)
97
    assert confirm_link
98
    browser.visit(confirm_link[0])
99
    assert browser.title, "Confirm E-mail Address"
100
    browser.find_by_css('[type=submit]')[0].click()
101
102
    poc_type = f.create_usertype(slug='poc', display_name='poc')
103
    user.profile.usertype.add(poc_type)
104
    user.save()
105
106
    location1 = f.create_locaiton(name='location1')
107
108
    browser.fill('login', user.email)
109
    browser.fill('password', '123123')
110
    browser.find_by_css('[type=submit]')[0].click()
111
112
    url = base_url + '/organisation/'
113
    browser.visit(url)
114
    org_create_link = browser.find_by_text('Add Organisation')[0]
115
    assert org_create_link
116
    org_create_link.click()
117
    browser.select('organisation_type', 1)
118
    browser.fill('name', 'Org2')
119
    browser.fill('description', 'Description')
120
    browser.select('location', location1.id)
121
    browser.fill('organisation_role', 'Role1')
122
    browser.find_by_css('[type=submit]')[0].click()
123
124
    org = f.create_organisation(location=location1, created_by=user)
125
    org.save()
126
127
    user2 = f.create_user()
128
    user2.set_password('123123')
129
    user2.save()
130
131
    # login
132
    url = base_url + '/accounts/logout/'
133
    browser.visit(url)
134
135
    url = base_url + '/accounts/login/'
136
    browser.visit(url)
137
    browser.fill('login', user2.email)
138
    browser.fill('password', '123123')
139
    browser.find_by_css('[type=submit]')[0].click()
140
    assert len(outbox) == 4
141
    mail = outbox[3]
142
    confirm_link = re.findall(r'http.*/accounts/.*/', mail.body)
143
    assert confirm_link
144
    browser.visit(confirm_link[0])
145
    assert browser.title, "Confirm E-mail Address"
146
    browser.find_by_css('[type=submit]')[0].click()
147
148
    poc_type = f.create_usertype(slug='poc', display_name='poc')
149
    user2.profile.usertype.add(poc_type)
150
    user2.save()
151
152
    org.user.add(user2)
153
    org.save()
154
155
    url = base_url + '/organisation/'
156
    browser.fill('login', user2.email)
157
    browser.fill('password', '123123')
158
    browser.find_by_css('[type=submit]')[0].click()
159
    browser.visit(url)
160
    browser.find_by_text(org.name)[0].click()
161
    assert not browser.find_by_text('Edit')
162