Conditions | 11 |
Total Lines | 133 |
Lines | 0 |
Ratio | 0 % |
Changes | 10 | ||
Bugs | 0 | Features | 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_workshop_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 | from datetime import datetime, timedelta |
||
76 | def test_workshop_flow(base_url, browser, outbox): |
||
77 | tutor_type = f.create_usertype(slug='tutor', display_name='tutor') |
||
78 | poc_type = f.create_usertype(slug='poc', display_name='poc') |
||
79 | wr1 = f.create_workshop_rating() |
||
80 | wr2 = f.create_workshop_rating() |
||
81 | wr3 = f.create_workshop_rating() |
||
82 | wr4 = f.create_workshop_rating() |
||
83 | state1 = f.create_state(name='state1') |
||
84 | state2 = f.create_state(name='state2') |
||
85 | |||
86 | user = f.create_user() |
||
87 | user.set_password('123123') |
||
88 | user.save() |
||
89 | url = base_url + '/workshop/' |
||
90 | browser.visit(url) |
||
91 | browser.fill('login', user.email) |
||
92 | browser.fill('password', '123123') |
||
93 | browser.find_by_css('[type=submit]')[0].click() |
||
94 | assert len(outbox) == 1 |
||
95 | mail = outbox[0] |
||
96 | confirm_link = re.findall(r'http.*/accounts/.*/', mail.body) |
||
97 | assert confirm_link |
||
98 | browser.visit(confirm_link[0]) |
||
99 | assert browser.title, "Confirm E-mail Address" |
||
100 | browser.find_by_css('[type=submit]')[0].click() |
||
101 | |||
102 | user.profile.usertype.clear() |
||
103 | user.profile.usertype.add(poc_type) |
||
104 | user.save() |
||
105 | location = f.create_locaiton(state=state1) |
||
106 | org = f.create_organisation(location=location) |
||
107 | org.user.add(user) |
||
108 | user.profile.interested_locations.add(org.location) |
||
109 | user.profile.location = org.location |
||
110 | user.profile.occupation = 'occupation' |
||
111 | user.profile.work_location = 'work_location' |
||
112 | user.profile.work_experience = 1 |
||
113 | user.profile.save() |
||
114 | org.save() |
||
115 | |||
116 | workshop = f.create_workshop( |
||
117 | requester=org, |
||
118 | status=WorkshopStatus.REQUESTED) |
||
119 | |||
120 | workshop.expected_date = datetime.now() + timedelta(days=20) |
||
121 | workshop.presenter.add(user) |
||
122 | workshop.save() |
||
123 | url = base_url + '/workshop/update/{}/'.format(workshop.id) |
||
124 | browser.visit(url) |
||
125 | browser.fill('login', user.email) |
||
126 | browser.fill('password', '123123') |
||
127 | browser.find_by_css('[type=submit]')[0].click() |
||
128 | |||
129 | section1 = f.create_workshop_section(name='section1') |
||
130 | location = org.location |
||
131 | |||
132 | user.profile.usertype.clear() |
||
133 | user.profile.usertype.add(tutor_type) |
||
134 | |||
135 | user.profile.location = location |
||
136 | user.profile.interested_states.add(state2) |
||
137 | user.profile.interested_states.add(state1) |
||
138 | user.profile.mobile = '1234567890' |
||
139 | user.profile.interested_sections.add(section1) |
||
140 | user.profile.interested_level = 1 |
||
141 | user.profile.github = 'https://github.com' |
||
142 | user.profile.occupation = 'occupation' |
||
143 | user.profile.work_location = 'work_location' |
||
144 | user.profile.work_experience = 1 |
||
145 | user.profile.save() |
||
146 | user.save() |
||
147 | |||
148 | url = base_url + '/workshop/{}/'.format(workshop.id) |
||
149 | browser.visit(url) |
||
150 | |||
151 | accept_workshop_link = browser.find_by_text('Accept')[0] |
||
152 | assert accept_workshop_link |
||
153 | accept_workshop_link.click() |
||
154 | |||
155 | user.profile.usertype.clear() |
||
156 | user.profile.usertype.add(poc_type) |
||
157 | user.profile.save() |
||
158 | user.save() |
||
159 | |||
160 | # checking to move requested workshop in hold state |
||
161 | url = base_url + '/workshop/{}/'.format(workshop.id) |
||
162 | browser.visit(url) |
||
163 | hold_workshop_link = browser.find_by_text('Hold')[0] |
||
164 | assert hold_workshop_link |
||
165 | hold_workshop_link.click() |
||
166 | |||
167 | # checking to move on hold workshop into requested state |
||
168 | browser.visit(url) |
||
169 | publish_workshop_link = browser.find_by_text('Publish/Request')[0] |
||
170 | assert publish_workshop_link |
||
171 | publish_workshop_link.click() |
||
172 | |||
173 | browser.visit(url) |
||
174 | # browser.screenshot() |
||
175 | hold_workshop_link = browser.find_by_text('Hold')[0] |
||
176 | assert hold_workshop_link |
||
177 | hold_workshop_link.click() |
||
178 | |||
179 | browser.visit(url) |
||
180 | publish_workshop_link = browser.find_by_text('Publish/Request')[0] |
||
181 | assert publish_workshop_link |
||
182 | publish_workshop_link.click() |
||
183 | |||
184 | browser.visit(url) |
||
185 | accept_workshop_link = browser.find_by_text('Accept')[0] |
||
186 | assert accept_workshop_link |
||
187 | accept_workshop_link.click() |
||
188 | |||
189 | # print(datetime.now() + timedelta(days=-10)) |
||
190 | workshop.expected_date = datetime.now() + timedelta(days=-60) |
||
191 | # workshop.status = WorkshopStatus.FEEDBACK_PENDING |
||
192 | workshop.save() |
||
193 | |||
194 | browser.visit(url) |
||
195 | print(wr1) |
||
196 | print('{}-{}'.format(wr1.id, wr1.feedback_type)) |
||
197 | print(wr2) |
||
198 | print(wr3) |
||
199 | print(wr4) |
||
200 | url = base_url + '/workshop/feedback/{}'.format(workshop.id) |
||
201 | browser.visit(url) |
||
202 | for wr in [wr1, wr2, wr3, wr4]: |
||
203 | id = '{}-{}'.format(wr1.feedback_type, wr1.id) |
||
204 | browser.check(id) |
||
205 | # browser.check('3-1') |
||
206 | browser.fill('comment', "Testing comments") |
||
207 | |||
208 | browser.find_by_css('[type=submit]')[0].click() |
||
209 |