Conditions | 18 |
Total Lines | 134 |
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:
Complex classes like test_add_new_member_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 |
||
5 | def test_add_new_member_flow(base_url, browser, outbox): |
||
6 | # ----------------- creating new user ------------------------ |
||
7 | f.create_usertype(slug='tutor', display_name='tutor') |
||
8 | user = f.create_user() |
||
9 | user.set_password('123123') |
||
10 | user.save() |
||
11 | url = base_url + '/accounts/login/' |
||
12 | browser.visit(url) |
||
13 | browser.fill('login', user.email) |
||
14 | browser.fill('password', '123123') |
||
15 | browser.find_by_css('[type=submit]')[0].click() |
||
16 | assert len(outbox) == 1 |
||
17 | mail = outbox[0] |
||
18 | confirm_link = re.findall(r'http.*/accounts/.*/', mail.body) |
||
19 | assert confirm_link |
||
20 | browser.visit(confirm_link[0]) |
||
21 | assert browser.title, "Confirm E-mail Address" |
||
22 | browser.find_by_css('[type=submit]')[0].click() |
||
23 | location1 = f.create_locaiton(name='location1') |
||
24 | |||
25 | # ----------------------add user type ------------------- |
||
26 | poc_type = f.create_usertype(slug='poc', display_name='poc') |
||
27 | user.profile.usertype.add(poc_type) |
||
28 | user.profile.location = location1 |
||
29 | user.profile.save() |
||
30 | user.save() |
||
31 | |||
32 | # -----------------------creating organisation --------------------- |
||
33 | url = base_url + '/organisation/' |
||
34 | browser.fill('login', user.email) |
||
35 | browser.fill('password', '123123') |
||
36 | browser.find_by_css('[type=submit]')[0].click() |
||
37 | browser.visit(url) |
||
38 | org_create_link = browser.find_by_text('Add Organisation')[0] |
||
39 | assert org_create_link |
||
40 | org_create_link.click() |
||
41 | browser.select('organisation_type', 1) |
||
42 | browser.fill('name', 'Org1') |
||
43 | browser.fill('description', 'Description') |
||
44 | browser.select('location', location1.id) |
||
45 | browser.fill('organisation_role', 'Role1') |
||
46 | browser.find_by_css('[type=submit]')[0].click() |
||
47 | |||
48 | org = f.create_organisation(location=location1) |
||
49 | org.user.add(user) |
||
50 | org.save() |
||
51 | |||
52 | # -------------------Adding member ------------------------ |
||
53 | # existing user |
||
54 | browser.find_by_text('Org1')[0].click() |
||
55 | |||
56 | # add to org |
||
57 | browser.find_by_text('Add Users')[0].click() |
||
58 | browser.fill('new_user', '[email protected]') |
||
59 | browser.find_by_css('[type=submit]')[0].click() |
||
60 | org.user.add(user) |
||
61 | org.save() |
||
62 | |||
63 | # invite mail |
||
64 | assert len(outbox) == 6 |
||
65 | mail = outbox[3] |
||
66 | invite_link = re.findall(r'http.*/invitation/.*/', mail.body) |
||
67 | assert invite_link |
||
68 | browser.visit(invite_link[0]) |
||
69 | # asserting if it's the signup page or not |
||
70 | assert 'Signup' in browser.title |
||
71 | |||
72 | # fill sign up form |
||
73 | browser.fill('first_name', 'random') |
||
74 | browser.fill('last_name', 'person') |
||
75 | browser.fill('username', 'randomnessprevails') |
||
76 | browser.fill('password', 'secretpassword') |
||
77 | browser.fill('password_confirm', 'secretpassword') |
||
78 | browser.find_by_css('[type=submit]')[0].click() |
||
79 | |||
80 | # check user was added |
||
81 | browser.find_by_text('Org1')[0].click() |
||
82 | user_list = browser.find_by_css('.list-silent') |
||
83 | assert '[email protected]' in user_list[0].text |
||
84 | |||
85 | # logout and login again to activate user |
||
86 | logout_url = base_url + "/accounts/logout" |
||
87 | browser.visit(logout_url) |
||
88 | |||
89 | login_url = base_url + '/accounts/login/' |
||
90 | browser.visit(login_url) |
||
91 | browser.fill('login', '[email protected]') |
||
92 | browser.fill('password', 'secretpassword') |
||
93 | browser.find_by_css('[type=submit]')[0].click() |
||
94 | |||
95 | # confirmation email sent |
||
96 | assert browser.is_text_present( |
||
97 | 'We have sent an e-mail to you for verification') |
||
98 | assert len(outbox) == 7 |
||
99 | mail = outbox[6] |
||
100 | |||
101 | activate_link = re.findall(r'http.*/accounts/confirm-email/.*/', mail.body) |
||
102 | assert activate_link |
||
103 | |||
104 | # confirmation dialogue |
||
105 | browser.visit(activate_link[0]) |
||
106 | assert "Confirm E-mail Address" in browser.title |
||
107 | browser.find_by_css('[type=submit]')[0].click() |
||
108 | |||
109 | # login |
||
110 | assert "Login" in browser.title |
||
111 | browser.fill('login', '[email protected]') |
||
112 | browser.fill('password', 'secretpassword') |
||
113 | browser.find_by_css('[type=submit]')[0].click() |
||
114 | |||
115 | # edit profile |
||
116 | assert browser.is_text_present("Dashboard") |
||
117 | |||
118 | poc_type = f.create_usertype(slug='dummy', display_name='College POC') |
||
119 | section1 = f.create_workshop_section(name='section1') |
||
120 | location2 = f.create_locaiton(name='location2') |
||
121 | |||
122 | url = base_url + '/profile/randomnessprevails/edit' |
||
123 | browser.visit(url) |
||
124 | |||
125 | browser.fill('mobile', '0812739120') |
||
126 | # browser.select('usertype', poc_type.id) |
||
127 | browser.select('interested_sections', section1.id) |
||
128 | browser.select('interested_locations', location1.id) |
||
129 | browser.select('location', location2.id) |
||
130 | browser.find_by_css('[type=submit]')[0].click() |
||
131 | |||
132 | assert browser.is_text_present('My Profile') |
||
133 | assert browser.is_text_present('Graph') |
||
134 | |||
135 | # Logging Out |
||
136 | url = base_url + '/accounts/logout/' |
||
137 | browser.visit(url) |
||
138 | assert 'Home | PythonExpress' in browser.title |
||
139 | |||
210 |