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