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 |
||
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 |