Conditions | 7 |
Total Lines | 69 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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:
1 | import re |
||
141 | def test_add_existing_member_flow(base_url, browser, outbox): |
||
142 | # ------------------creating new user ---------------------- |
||
143 | f.create_usertype(slug='tutor', display_name='tutor') |
||
144 | user = f.create_user() |
||
145 | user.set_password('123123') |
||
146 | user.save() |
||
147 | url = base_url + '/accounts/login/' |
||
148 | browser.visit(url) |
||
149 | browser.fill('login', user.email) |
||
150 | browser.fill('password', '123123') |
||
151 | browser.find_by_css('[type=submit]')[0].click() |
||
152 | assert len(outbox) == 1 |
||
153 | mail = outbox[0] |
||
154 | confirm_link = re.findall(r'http.*/accounts/.*/', mail.body) |
||
155 | assert confirm_link |
||
156 | browser.visit(confirm_link[0]) |
||
157 | assert browser.title, "Confirm E-mail Address" |
||
158 | browser.find_by_css('[type=submit]')[0].click() |
||
159 | location1 = f.create_locaiton(name='location1') |
||
160 | # ---------------------add user type ----------------------- |
||
161 | poc_type = f.create_usertype(slug='poc', display_name='poc') |
||
162 | user.profile.usertype.add(poc_type) |
||
163 | user.profile.location = location1 |
||
164 | user.profile.save() |
||
165 | user.save() |
||
166 | |||
167 | # -------------------creating organisation -------------------- |
||
168 | url = base_url + '/organisation/' |
||
169 | browser.fill('login', user.email) |
||
170 | browser.fill('password', '123123') |
||
171 | browser.find_by_css('[type=submit]')[0].click() |
||
172 | browser.visit(url) |
||
173 | org_create_link = browser.find_by_text('Add Organisation')[0] |
||
174 | assert org_create_link |
||
175 | org_create_link.click() |
||
176 | browser.select('organisation_type', 1) |
||
177 | browser.fill('name', 'Org1') |
||
178 | browser.fill('description', 'Description') |
||
179 | browser.select('location', location1.id) |
||
180 | browser.fill('organisation_role', 'Role1') |
||
181 | browser.find_by_css('[type=submit]')[0].click() |
||
182 | |||
183 | org = f.create_organisation(location=location1) |
||
184 | org.user.add(user) |
||
185 | org.save() |
||
186 | |||
187 | # -------------- Adding member ------------------------ |
||
188 | |||
189 | # create user |
||
190 | user2 = f.create_user(is_active=True) |
||
191 | user2.set_password('123123') |
||
192 | user2.save() |
||
193 | user2.profile.usertype.add(poc_type) |
||
194 | user2.save() |
||
195 | |||
196 | # add to org |
||
197 | browser.find_by_text('Org1')[0].click() |
||
198 | browser.find_by_text('Add Users')[0].click() |
||
199 | browser.select_by_text('existing_user', user2.username) |
||
200 | browser.find_by_css('[type=submit]')[0].click() |
||
201 | org.user.add(user2) |
||
202 | org.save() |
||
203 | |||
204 | # check user was added |
||
205 | browser.find_by_text('Org1')[0].click() |
||
206 | user_list = browser.find_by_css('.list-silent') |
||
207 | assert user2.email in user_list[0].text |
||
208 | |||
209 | assert 'Organisation | PythonExpress' in browser.title |
||
210 |