Completed
Push — master ( 45f0c4...1295f2 )
by Vijay
9s
created

test_signup_college_poc_flow()   D

Complexity

Conditions 10

Size

Total Lines 71

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 71
rs 4.186
cc 10

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.fill('github', 'https://github.com')
78
    browser.find_by_css('[type=submit]')[0].click()
79
80
    assert browser.is_text_present('Deactive Account')
81
82
83
def test_signup_tutor_flow(base_url, browser, outbox):
84
    tutor_type = f.create_usertype(slug='tutor', display_name='tutor')
85
    user = f.create_user()
86
    user.set_password('123123')
87
    user.save()
88
    url = base_url + '/workshop/'
89
    browser.visit(url)
90
    browser.fill('login', user.email)
91
    browser.fill('password', '123123')
92
    browser.find_by_css('[type=submit]')[0].click()
93
    assert len(outbox) == 1
94
    mail = outbox[0]
95
    confirm_link = re.findall(r'http.*/accounts/.*/', mail.body)
96
    assert confirm_link
97
    browser.visit(confirm_link[0])
98
    assert browser.title, "Confirm E-mail Address"
99
    browser.find_by_css('[type=submit]')[0].click()
100
101
    assert "Login" in browser.title
102
103
    browser.fill('login', user.email)
104
    browser.fill('password', '123123')
105
    browser.find_by_css('[type=submit]')[0].click()
106
107
    assert browser.is_text_present("Dashboard")
108
109
    poc_type = f.create_usertype(slug='poc', display_name='College POC')
110
    user.profile.usertype.clear()
111
    user.profile.usertype.add(tutor_type)
112
    user.profile.usertype.add(poc_type)
113
    user.profile.save()
114
    user.save()
115
    section1 = f.create_workshop_section(name='section1')
116
    location1 = f.create_locaiton(name='location1')
117
    state1 = f.create_state(name='state1')
118
119
    # mobile number chechk
120
    url = base_url + '/profile/' + user.username + '/edit'
121
    browser.visit(url)
122
    browser.fill('mobile', '')
123
    browser.select('usertype', tutor_type.id)
124
    browser.select('interested_sections', section1.id)
125
    browser.select('location', location1.id)
126
    browser.select('interested_states', state1.id)
127
    browser.find_by_css('[type=submit]')[0].click()
128
    assert browser.is_text_present('This field is required.')
129
130
    # interested state check
131
    browser.visit(url)
132
    browser.fill('mobile', '1234567890')
133
    browser.select('location', location1.id)
134
    browser.select('interested_states', state1.id)
135
    browser.find_by_css('[type=submit]')[0].click()
136
    assert browser.is_text_present('This field is required.')
137
138
    # location check
139
    browser.visit(url)
140
    browser.fill('mobile', '1234567890')
141
    browser.select('interested_sections', section1.id)
142
    browser.select('interested_states', state1.id)
143
    browser.find_by_css('[type=submit]')[0].click()
144
    assert browser.is_text_present('This field is required.')
145
146
    # Github check
147
    browser.visit(url)
148
    browser.fill('mobile', '1234567890')
149
    browser.select('interested_sections', section1.id)
150
    browser.select('interested_states', state1.id)
151
    browser.select('location', location1.id)
152
    browser.find_by_css('[type=submit]')[0].click()
153
    assert browser.is_text_present('Github or LinkedIn field is mandatory')
154
155
    browser.visit(url)
156
    browser.fill('mobile', '1234567890')
157
    browser.select('interested_sections', section1.id)
158
    browser.select('interested_states', state1.id)
159
    browser.select('location', location1.id)
160
    browser.fill('github', 'https://github.com')
161
    browser.find_by_css('[type=submit]')[0].click()
162
163
    assert browser.is_text_present(
164
        'Interested workshop level field is mandatory')
165
166
    browser.visit(url)
167
    browser.fill('mobile', '1234567890')
168
    browser.select('interested_sections', section1.id)
169
    browser.select('interested_states', state1.id)
170
    browser.select('interested_level', 1)
171
    browser.select('location', location1.id)
172
    browser.fill('github', 'https://github.com')
173
    browser.find_by_css('[type=submit]')[0].click()
174
175
    assert browser.is_text_present('Deactive Account')
176