Conditions | 12 |
Total Lines | 93 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
Complex classes like test_signup_tutor_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 |
||
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 |