Completed
Push — master ( 86e229...33e372 )
by Vijay
9s
created

test_add_existing_member_flow()   C

Complexity

Conditions 7

Size

Total Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 7
c 1
b 0
f 1
dl 0
loc 69
rs 5.7452

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_add_new_member_flow(base_url, browser, outbox):
6
    # -------------------------------------- creating new user ------------------------------------
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
23
    # -------------------------------------- add user type ----------------------------------------
24
    poc_type = f.create_usertype(slug='poc', display_name='poc')
25
    user.profile.usertype.add(poc_type)
26
    user.save()
27
28
    # location
29
    location1 = f.create_locaiton(name='location1')
30
31
    # -------------------------------------- creating organisation --------------------------------
32
    url = base_url + '/organisation/'
33
    browser.fill('login', user.email)
34
    browser.fill('password', '123123')
35
    browser.find_by_css('[type=submit]')[0].click()
36
    browser.visit(url)
37
    org_create_link = browser.find_by_text('Add Organisation')[0]
38
    assert org_create_link
39
    org_create_link.click()
40
    browser.select('organisation_type', 1)
41
    browser.fill('name', 'Org1')
42
    browser.fill('description', 'Description')
43
    browser.select('location', location1.id)
44
    browser.fill('organisation_role', 'Role1')
45
    browser.find_by_css('[type=submit]')[0].click()
46
47
    org = f.create_organisation(location=location1)
48
    org.user.add(user)
49
    org.save()
50
51
    # -------------------------------------- Adding member ----------------------------------------
52
    # existing user
53
    browser.find_by_text('Org1')[0].click()
54
55
    # add to org
56
    browser.find_by_text('Add Users')[0].click()
57
    browser.fill('new_user', '[email protected]')
58
    browser.find_by_css('[type=submit]')[0].click()
59
    org.user.add(user)
60
    org.save()
61
62
    # invite mail
63
    assert len(outbox) == 6
64
    mail = outbox[3]
65
    invite_link = re.findall(r'http.*/invitation/.*/', mail.body)
66
    assert invite_link
67
    browser.visit(invite_link[0])
68
    assert 'Signup' in browser.title  # asserting if it's the signup page or not
69
70
    # fill sign up form
71
    browser.fill('first_name', 'random')
72
    browser.fill('last_name', 'person')
73
    browser.fill('username', 'randomnessprevails')
74
    browser.fill('password', 'secretpassword')
75
    browser.fill('password_confirm', 'secretpassword')
76
    browser.find_by_css('[type=submit]')[0].click()
77
78
    # check user was added
79
    browser.find_by_text('Org1')[0].click()
80
    user_list = browser.find_by_css('.list-silent')
81
    assert '[email protected]' in user_list[0].text
82
83
    # logout and login again to activate user
84
    logout_url = base_url + "/accounts/logout"
85
    browser.visit(logout_url)
86
87
    login_url = base_url + '/accounts/login/'
88
    browser.visit(login_url)
89
    browser.fill('login', '[email protected]')
90
    browser.fill('password', 'secretpassword')
91
    browser.find_by_css('[type=submit]')[0].click()
92
93
    # confirmation email sent
94
    assert browser.is_text_present('We have sent an e-mail to you for verification')
95
    assert len(outbox) == 7
96
    mail = outbox[6]
97
98
    activate_link = re.findall(r'http.*/accounts/confirm-email/.*/', mail.body)
99
    assert activate_link
100
101
    # confirmation dialogue
102
    browser.visit(activate_link[0])
103
    assert "Confirm E-mail Address" in browser.title
104
    browser.find_by_css('[type=submit]')[0].click()
105
106
    # login
107
    assert "Login" in browser.title
108
    browser.fill('login', '[email protected]')
109
    browser.fill('password', 'secretpassword')
110
    browser.find_by_css('[type=submit]')[0].click()
111
112
    # edit profile
113
    assert browser.is_text_present("Edit Profile")
114
115
    poc_type = f.create_usertype(slug='dummy', display_name='College POC')
116
    section1 = f.create_workshop_section(name='section1')
117
    location2 = f.create_locaiton(name='location2')
118
119
    url = base_url + '/profile/randomnessprevails/edit'
120
    browser.visit(url)
121
122
    browser.fill('mobile', '0812739120')
123
    browser.select('usertype', poc_type.id)
124
    browser.select('interested_sections', section1.id)
125
    browser.select('interested_locations', location1.id)
126
    browser.select('location', location2.id)
127
    browser.find_by_css('[type=submit]')[0].click()
128
129
    assert browser.is_text_present('My Profile')
130
    assert browser.is_text_present('Graph')
131
132
    # Logging Out
133
    url = base_url + '/accounts/logout/'
134
    browser.visit(url)
135
    assert 'Home | PythonExpress' in browser.title
136
137
138
def test_add_existing_member_flow(base_url, browser, outbox):
139
    # -------------------------------------- creating new user ------------------------------------
140
    user = f.create_user()
141
    user.set_password('123123')
142
    user.save()
143
    url = base_url + '/accounts/login/'
144
    browser.visit(url)
145
    browser.fill('login', user.email)
146
    browser.fill('password', '123123')
147
    browser.find_by_css('[type=submit]')[0].click()
148
    assert len(outbox) == 1
149
    mail = outbox[0]
150
    confirm_link = re.findall(r'http.*/accounts/.*/', mail.body)
151
    assert confirm_link
152
    browser.visit(confirm_link[0])
153
    assert browser.title, "Confirm E-mail Address"
154
    browser.find_by_css('[type=submit]')[0].click()
155
156
    # -------------------------------------- add user type ----------------------------------------
157
    poc_type = f.create_usertype(slug='poc', display_name='poc')
158
    user.profile.usertype.add(poc_type)
159
    user.save()
160
161
    # location
162
    location1 = f.create_locaiton(name='location1')
163
164
    # -------------------------------------- creating organisation --------------------------------
165
    url = base_url + '/organisation/'
166
    browser.fill('login', user.email)
167
    browser.fill('password', '123123')
168
    browser.find_by_css('[type=submit]')[0].click()
169
    browser.visit(url)
170
    org_create_link = browser.find_by_text('Add Organisation')[0]
171
    assert org_create_link
172
    org_create_link.click()
173
    browser.select('organisation_type', 1)
174
    browser.fill('name', 'Org1')
175
    browser.fill('description', 'Description')
176
    browser.select('location', location1.id)
177
    browser.fill('organisation_role', 'Role1')
178
    browser.find_by_css('[type=submit]')[0].click()
179
180
    org = f.create_organisation(location=location1)
181
    org.user.add(user)
182
    org.save()
183
184
    # -------------------------------------- Adding member ----------------------------------------
185
186
    # create user
187
    user2 = f.create_user(is_active=True)
188
    user2.set_password('123123')
189
    user2.save()
190
    user2.profile.usertype.add(poc_type)
191
    user2.save()
192
193
    # add to org
194
    browser.find_by_text('Org1')[0].click()
195
    browser.find_by_text('Add Users')[0].click()
196
    browser.select_by_text('existing_user', user2.username)
197
    browser.find_by_css('[type=submit]')[0].click()
198
    org.user.add(user2)
199
    org.save()
200
201
    # check user was added
202
    browser.find_by_text('Org1')[0].click()
203
    user_list = browser.find_by_css('.list-silent')
204
    assert user2.email in user_list[0].text
205
206
    assert 'Organisation | PythonExpress' in browser.title
207