| Conditions | 10 |
| Total Lines | 76 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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_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 |
||
| 11 | def test_signup_flow(base_url, browser, outbox): |
||
| 12 | f.create_usertype(slug='tutor', display_name='tutor') |
||
| 13 | # Sign-Up option should be present there |
||
| 14 | browser.visit(base_url) |
||
| 15 | sign_up_link = browser.find_by_text('Sign Up')[0] |
||
| 16 | assert sign_up_link |
||
| 17 | |||
| 18 | # On Clicking it, it should open a Sign Up Page |
||
| 19 | sign_up_link.click() |
||
| 20 | # asserting if it's the signup page or not |
||
| 21 | assert 'Signup' in browser.title |
||
| 22 | |||
| 23 | # Now Fill the relevant information |
||
| 24 | |||
| 25 | browser.fill('first_name', 'random') |
||
| 26 | browser.fill('last_name', 'person') |
||
| 27 | browser.fill('mobile', '0812739120') |
||
| 28 | browser.fill('username', 'randomnessprevails') |
||
| 29 | browser.fill('email', '[email protected]') |
||
| 30 | browser.fill('password1', 'secretpassword') |
||
| 31 | browser.fill('password2', 'secretpassword') |
||
| 32 | |||
| 33 | # Click on the Submit Button |
||
| 34 | browser.find_by_css('[type=submit]')[0].click() |
||
| 35 | |||
| 36 | # Check for the text shown in the browser when user hits submit button |
||
| 37 | assert browser.is_text_present( |
||
| 38 | 'We have sent an e-mail to you for verification') |
||
| 39 | |||
| 40 | # Check for the mailbox for the confirmation link |
||
| 41 | |||
| 42 | assert len(outbox) == 1 |
||
| 43 | mail = outbox[0] |
||
| 44 | |||
| 45 | activate_link = re.findall(r'http.*/accounts/confirm-email/.*/', mail.body) |
||
| 46 | assert activate_link |
||
| 47 | |||
| 48 | browser.visit(activate_link[0]) |
||
| 49 | |||
| 50 | assert "Confirm E-mail Address" in browser.title |
||
| 51 | browser.find_by_css('[type=submit]')[0].click() |
||
| 52 | |||
| 53 | # assert "Login" in browser.title |
||
| 54 | |||
| 55 | # browser.fill('login', '[email protected]') |
||
| 56 | # browser.fill('password', 'secretpassword') |
||
| 57 | # browser.find_by_css('[type=submit]')[0].click() |
||
| 58 | |||
| 59 | # assert browser.is_text_present("My Profile") |
||
| 60 | |||
| 61 | u = User.objects.get(email='[email protected]') |
||
| 62 | u.profile.usertype.clear() |
||
| 63 | poc_type = f.create_usertype(slug='poc', display_name='College POC') |
||
| 64 | u.profile.usertype.add(poc_type) |
||
| 65 | section1 = f.create_workshop_section(name='section1') |
||
| 66 | location1 = f.create_locaiton(name='location1') |
||
| 67 | state1 = f.create_state(name='state1') |
||
| 68 | |||
| 69 | url = base_url + '/profile/randomnessprevails/edit' |
||
| 70 | browser.visit(url) |
||
| 71 | |||
| 72 | browser.select('interested_sections', section1.id) |
||
| 73 | browser.select('interested_states', state1.id) |
||
| 74 | browser.select('location', location1.id) |
||
| 75 | browser.fill('occupation', 'occupation') |
||
| 76 | browser.fill('work_location', 'work_location') |
||
| 77 | browser.fill('work_experience', 1) |
||
| 78 | browser.find_by_css('[type=submit]')[0].click() |
||
| 79 | |||
| 80 | assert browser.is_text_present('My Profile') |
||
| 81 | assert browser.is_text_present('Graph') |
||
| 82 | |||
| 83 | # Logging Out |
||
| 84 | url = base_url + '/accounts/logout/' |
||
| 85 | browser.visit(url) |
||
| 86 | assert 'Home | PythonExpress' in browser.title |
||
| 87 |