Completed
Push — master ( 1b8e23...81a01d )
by Vijay
9s
created

test_org_edit_flow()   F

Complexity

Conditions 9

Size

Total Lines 81

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 9
c 1
b 0
f 1
dl 0
loc 81
rs 3.7342

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
    f.create_usertype(slug='tutor', display_name='tutor')
7
    user = f.create_user()
8
    user.set_password('123123')
9
    user.save()
10
    url = base_url + '/accounts/login/'
11
    browser.visit(url)
12
    browser.fill('login', user.email)
13
    browser.fill('password', '123123')
14
    browser.find_by_css('[type=submit]')[0].click()
15
    assert len(outbox) == 1
16
    mail = outbox[0]
17
    confirm_link = re.findall(r'http.*/accounts/.*/', mail.body)
18
    assert confirm_link
19
    browser.visit(confirm_link[0])
20
    assert browser.title, "Confirm E-mail Address"
21
    browser.find_by_css('[type=submit]')[0].click()
22
    location1 = f.create_locaiton(name='location1')
23
    poc_type = f.create_usertype(slug='poc', display_name='poc')
24
    user.profile.usertype.add(poc_type)
25
    user.profile.location = location1
26
    user.profile.save()
27
    user.save()
28
    url = base_url + '/organisation/'
29
    browser.fill('login', user.email)
30
    browser.fill('password', '123123')
31
    browser.find_by_css('[type=submit]')[0].click()
32
    browser.visit(url)
33
    org_create_link = browser.find_by_text('Add Organisation')[0]
34
    assert org_create_link
35
    org_create_link.click()
36
    browser.select('organisation_type', 1)
37
    browser.fill('name', 'Org1')
38
    browser.fill('description', 'Description')
39
    browser.select('location', location1.id)
40
    browser.fill('organisation_role', 'Role1')
41
    browser.find_by_css('[type=submit]')[0].click()
42
    # browser.find_by_css('[clickable-row]')[0].click()
43
    browser.find_by_text('Org1')[0].click()
44
45
    browser.find_by_text('Edit')[0].click()
46
    browser.fill('organisation_role', 'Role updated')
47
    browser.find_by_css('[type=submit]')[0].click()
48
    browser.find_by_text('Org1')[0].click()
49
    browser.find_by_text('Delete')[0].click()
50
    org = f.create_organisation(location=location1, created_by=user)
51
    org.user.add(user)
52
    org.save()
53
    url = base_url + '/organisation/{}/edit/'.format(org.id)
54
    browser.visit(url)
55
    browser.fill('organisation_role', 'Role updated')
56
    browser.find_by_css('[type=submit]')[0].click()
57
58
    url = base_url + '/organisation/{}/'.format(org.id)
59
    browser.visit(url)
60
    delete_org_link = browser.find_by_text('Delete')[0]
61
    assert delete_org_link
62
    delete_org_link.click()
63
64
    # for Exceptions
65
66
    url = base_url + '/organisation/create/'
67
    browser.visit(url)
68
    browser.select('organisation_type', 1)
69
    browser.fill('name', 'Org22')
70
    browser.fill('description', 'Description22')
71
    # browser.select('location', location1.id)
72
    browser.fill('organisation_role', 'Role1')
73
    browser.find_by_css('[type=submit]')[0].click()
74
    assert browser.find_by_text('This field is required.')[0]
75
76
    # user as regional lead
77
    lead_type = f.create_usertype(slug='lead', display_name='lead')
78
    user.profile.usertype.remove(poc_type)
79
    user.profile.usertype.add(lead_type)
80
    user.save()
81
    url = base_url + '/organisation/'
82
    browser.visit(url)
83
    org_leadview_link = browser.find_by_text('My Organisations')[0]
84
    assert org_leadview_link
85
86
87
def test_org_edit_flow(base_url, browser, outbox):
88
    f.create_usertype(slug='tutor', display_name='tutor')
89
    user = f.create_user()
90
    user.set_password('123123')
91
    user.save()
92
    url = base_url + '/accounts/login/'
93
    browser.visit(url)
94
    browser.fill('login', user.email)
95
    browser.fill('password', '123123')
96
    browser.find_by_css('[type=submit]')[0].click()
97
    assert len(outbox) == 1
98
    mail = outbox[0]
99
    confirm_link = re.findall(r'http.*/accounts/.*/', mail.body)
100
    assert confirm_link
101
    browser.visit(confirm_link[0])
102
    assert browser.title, "Confirm E-mail Address"
103
    browser.find_by_css('[type=submit]')[0].click()
104
105
    location1 = f.create_locaiton(name='location1')
106
107
    poc_type = f.create_usertype(slug='poc', display_name='poc')
108
    user.profile.usertype.add(poc_type)
109
    user.profile.location = location1
110
    user.profile.save()
111
    user.save()
112
    browser.fill('login', user.email)
113
    browser.fill('password', '123123')
114
    browser.find_by_css('[type=submit]')[0].click()
115
116
    url = base_url + '/organisation/'
117
    browser.visit(url)
118
    org_create_link = browser.find_by_text('Add Organisation')[0]
119
    assert org_create_link
120
    org_create_link.click()
121
    browser.select('organisation_type', 1)
122
    browser.fill('name', 'Org2')
123
    browser.fill('description', 'Description')
124
    browser.select('location', location1.id)
125
    browser.fill('organisation_role', 'Role1')
126
    browser.find_by_css('[type=submit]')[0].click()
127
128
    org = f.create_organisation(location=location1, created_by=user)
129
    org.save()
130
131
    user2 = f.create_user()
132
    user2.set_password('123123')
133
    user2.save()
134
135
    # login
136
    url = base_url + '/accounts/logout/'
137
    browser.visit(url)
138
139
    url = base_url + '/accounts/login/'
140
    browser.visit(url)
141
    browser.fill('login', user2.email)
142
    browser.fill('password', '123123')
143
    browser.find_by_css('[type=submit]')[0].click()
144
    assert len(outbox) == 4
145
    mail = outbox[3]
146
    confirm_link = re.findall(r'http.*/accounts/.*/', mail.body)
147
    assert confirm_link
148
    browser.visit(confirm_link[0])
149
    assert browser.title, "Confirm E-mail Address"
150
    browser.find_by_css('[type=submit]')[0].click()
151
152
    poc_type = f.create_usertype(slug='poc', display_name='poc')
153
    user2.profile.usertype.add(poc_type)
154
    user2.profile.location = location1
155
    user2.profile.save()
156
    user2.save()
157
158
    org.user.add(user2)
159
    org.save()
160
161
    url = base_url + '/organisation/'
162
    browser.fill('login', user2.email)
163
    browser.fill('password', '123123')
164
    browser.find_by_css('[type=submit]')[0].click()
165
    browser.visit(url)
166
    browser.find_by_text(org.name)[0].click()
167
    assert not browser.find_by_text('Edit')
168