Completed
Push — master ( 442380...a5ee20 )
by Vijay
9s
created

test_signup_college_poc_flow()   F

Complexity

Conditions 11

Size

Total Lines 80

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 80
rs 3.1764
cc 11

How to fix   Long Method    Complexity   

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:

Complexity

Complex classes like test_signup_college_poc_flow() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import re
2
3
import pytest
4
5
from .. import factories as f
6
7
pytestmark = pytest.mark.django_db
8
9
10
def test_signup_college_poc_flow(base_url, browser, outbox):
11
    f.create_usertype(slug='tutor', display_name='tutor')
12
    user = f.create_user()
13
    user.set_password('123123')
14
    user.save()
15
    url = base_url + '/workshop/'
16
    browser.visit(url)
17
    browser.fill('login', user.email)
18
    browser.fill('password', '123123')
19
    browser.find_by_css('[type=submit]')[0].click()
20
    assert len(outbox) == 1
21
    mail = outbox[0]
22
    confirm_link = re.findall(r'http.*/accounts/.*/', mail.body)
23
    assert confirm_link
24
    browser.visit(confirm_link[0])
25
    assert browser.title, "Confirm E-mail Address"
26
    browser.find_by_css('[type=submit]')[0].click()
27
28
    assert "Login" in browser.title
29
30
    browser.fill('login', user.email)
31
    browser.fill('password', '123123')
32
    browser.find_by_css('[type=submit]')[0].click()
33
34
    assert browser.is_text_present("Dashboard")
35
36
    poc_type = f.create_usertype(slug='poc', display_name='College POC')
37
    user.profile.usertype.clear()
38
    user.profile.usertype.add(poc_type)
39
    user.profile.save()
40
    user.save()
41
    section1 = f.create_workshop_section(name='section1')
42
43
    location1 = f.create_locaiton(name='location1')
44
    state1 = f.create_state(name='state1')
45
46
    # mobile number chechk
47
    url = base_url + '/profile/' + user.username + '/edit'
48
    browser.visit(url)
49
    browser.fill('mobile', '')
50
    browser.select('interested_sections', section1.id)
51
    browser.select('location', location1.id)
52
    browser.select('interested_states', state1.id)
53
    browser.find_by_css('[type=submit]')[0].click()
54
    assert browser.is_text_present('This field is required.')
55
56
    # interested state check
57
    browser.visit(url)
58
    browser.fill('mobile', '1234567890')
59
    browser.select('location', location1.id)
60
    browser.select('interested_states', state1.id)
61
    browser.find_by_css('[type=submit]')[0].click()
62
    assert browser.is_text_present('This field is required.')
63
64
    # location check
65
    browser.visit(url)
66
    browser.fill('mobile', '1234567890')
67
    browser.select('interested_sections', section1.id)
68
    browser.select('interested_states', state1.id)
69
    browser.find_by_css('[type=submit]')[0].click()
70
    assert browser.is_text_present('This field is required.')
71
72
    browser.visit(url)
73
    browser.fill('mobile', '1234567890')
74
    browser.select('interested_sections', section1.id)
75
    browser.select('interested_states', state1.id)
76
    browser.select('location', location1.id)
77
    browser.find_by_css('[type=submit]')[0].click()
78
    assert browser.is_text_present('This field is required.')
79
80
    browser.visit(url)
81
    browser.fill('mobile', '1234567890')
82
    browser.select('interested_sections', section1.id)
83
    browser.select('interested_states', state1.id)
84
    browser.select('location', location1.id)
85
    # browser.fill('github', 'https://github.com')
86
    browser.fill('first_name', 'First Name')
87
    browser.fill('last_name', 'Last Name')
88
    browser.find_by_css('[type=submit]')[0].click()
89
    assert browser.is_text_present('Deactive Account')
90
91
92
def test_signup_tutor_flow(base_url, browser, outbox):
93
    tutor_type = f.create_usertype(slug='tutor', display_name='tutor')
94
    user = f.create_user()
95
    user.set_password('123123')
96
    user.save()
97
    url = base_url + '/workshop/'
98
    browser.visit(url)
99
    browser.fill('login', user.email)
100
    browser.fill('password', '123123')
101
    browser.find_by_css('[type=submit]')[0].click()
102
    assert len(outbox) == 1
103
    mail = outbox[0]
104
    confirm_link = re.findall(r'http.*/accounts/.*/', mail.body)
105
    assert confirm_link
106
    browser.visit(confirm_link[0])
107
    assert browser.title, "Confirm E-mail Address"
108
    browser.find_by_css('[type=submit]')[0].click()
109
110
    assert "Login" in browser.title
111
112
    browser.fill('login', user.email)
113
    browser.fill('password', '123123')
114
    browser.find_by_css('[type=submit]')[0].click()
115
116
    assert browser.is_text_present("Dashboard")
117
118
    poc_type = f.create_usertype(slug='poc', display_name='College POC')
119
    user.profile.usertype.clear()
120
    user.profile.usertype.add(tutor_type)
121
    user.profile.usertype.add(poc_type)
122
    user.profile.save()
123
    user.save()
124
    section1 = f.create_workshop_section(name='section1')
125
    location1 = f.create_locaiton(name='location1')
126
    state1 = f.create_state(name='state1')
127
128
    # mobile number chechk
129
    url = base_url + '/profile/' + user.username + '/edit'
130
    browser.visit(url)
131
    browser.fill('mobile', '')
132
    browser.select('usertype', tutor_type.id)
133
    browser.select('interested_sections', section1.id)
134
    browser.select('location', location1.id)
135
    browser.select('interested_states', state1.id)
136
    browser.find_by_css('[type=submit]')[0].click()
137
    assert browser.is_text_present('This field is required.')
138
139
    # interested state check
140
    browser.visit(url)
141
    browser.fill('mobile', '1234567890')
142
    browser.select('location', location1.id)
143
    browser.select('interested_states', state1.id)
144
    browser.find_by_css('[type=submit]')[0].click()
145
    assert browser.is_text_present('This field is required.')
146
147
    # location check
148
    browser.visit(url)
149
    browser.fill('mobile', '1234567890')
150
    browser.select('interested_sections', section1.id)
151
    browser.select('interested_states', state1.id)
152
    browser.find_by_css('[type=submit]')[0].click()
153
    assert browser.is_text_present('This field is required.')
154
155
    # Github check
156
    browser.visit(url)
157
    browser.fill('mobile', '1234567890')
158
    browser.select('interested_sections', section1.id)
159
    browser.select('interested_states', state1.id)
160
    browser.select('location', location1.id)
161
    browser.find_by_css('[type=submit]')[0].click()
162
    assert browser.is_text_present('Github or LinkedIn field is mandatory')
163
164
    browser.visit(url)
165
    browser.fill('mobile', '1234567890')
166
    browser.select('interested_sections', section1.id)
167
    browser.select('interested_states', state1.id)
168
    browser.select('location', location1.id)
169
    browser.fill('github', 'https://github.com')
170
    browser.find_by_css('[type=submit]')[0].click()
171
172
    assert browser.is_text_present(
173
        'Interested workshop level field is mandatory')
174
175
    browser.visit(url)
176
    browser.fill('mobile', '1234567890')
177
    browser.select('interested_sections', section1.id)
178
    browser.select('interested_states', state1.id)
179
    browser.select('interested_level', 1)
180
    browser.select('location', location1.id)
181
    browser.fill('github', 'https://github.com')
182
    browser.find_by_css('[type=submit]')[0].click()
183
    assert browser.is_text_present('This field is required.')
184
185
    browser.visit(url)
186
    browser.fill('first_name', 'First Name')
187
    browser.fill('last_name', 'Last Name')
188
    browser.fill('mobile', '1234567890')
189
    browser.select('interested_sections', section1.id)
190
    browser.select('interested_states', state1.id)
191
    browser.select('interested_level', 1)
192
    browser.select('location', location1.id)
193
    browser.fill('github', 'https://github.com')
194
    browser.find_by_css('[type=submit]')[0].click()
195
    assert browser.is_text_present('Deactive Account')
196