Conditions | 9 |
Total Lines | 81 |
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 |
||
87 | def test_org_edit_flow(base_url, browser, outbox): |
||
88 | f.create_usertype(slug='tutor', display_name='tutor') |
||
89 | user = f.create_user() |
||
90 | user.set_password('123123') |
||
91 | user.save() |
||
92 | url = base_url + '/accounts/login/' |
||
93 | browser.visit(url) |
||
94 | browser.fill('login', user.email) |
||
95 | browser.fill('password', '123123') |
||
96 | browser.find_by_css('[type=submit]')[0].click() |
||
97 | assert len(outbox) == 1 |
||
98 | mail = outbox[0] |
||
99 | confirm_link = re.findall(r'http.*/accounts/.*/', mail.body) |
||
100 | assert confirm_link |
||
101 | browser.visit(confirm_link[0]) |
||
102 | assert browser.title, "Confirm E-mail Address" |
||
103 | browser.find_by_css('[type=submit]')[0].click() |
||
104 | |||
105 | location1 = f.create_locaiton(name='location1') |
||
106 | |||
107 | poc_type = f.create_usertype(slug='poc', display_name='poc') |
||
108 | user.profile.usertype.add(poc_type) |
||
109 | user.profile.location = location1 |
||
110 | user.profile.save() |
||
111 | user.save() |
||
112 | browser.fill('login', user.email) |
||
113 | browser.fill('password', '123123') |
||
114 | browser.find_by_css('[type=submit]')[0].click() |
||
115 | |||
116 | url = base_url + '/organisation/' |
||
117 | browser.visit(url) |
||
118 | org_create_link = browser.find_by_text('Add Organisation')[0] |
||
119 | assert org_create_link |
||
120 | org_create_link.click() |
||
121 | browser.select('organisation_type', 1) |
||
122 | browser.fill('name', 'Org2') |
||
123 | browser.fill('description', 'Description') |
||
124 | browser.select('location', location1.id) |
||
125 | browser.fill('organisation_role', 'Role1') |
||
126 | browser.find_by_css('[type=submit]')[0].click() |
||
127 | |||
128 | org = f.create_organisation(location=location1, created_by=user) |
||
129 | org.save() |
||
130 | |||
131 | user2 = f.create_user() |
||
132 | user2.set_password('123123') |
||
133 | user2.save() |
||
134 | |||
135 | # login |
||
136 | url = base_url + '/accounts/logout/' |
||
137 | browser.visit(url) |
||
138 | |||
139 | url = base_url + '/accounts/login/' |
||
140 | browser.visit(url) |
||
141 | browser.fill('login', user2.email) |
||
142 | browser.fill('password', '123123') |
||
143 | browser.find_by_css('[type=submit]')[0].click() |
||
144 | assert len(outbox) == 4 |
||
145 | mail = outbox[3] |
||
146 | confirm_link = re.findall(r'http.*/accounts/.*/', mail.body) |
||
147 | assert confirm_link |
||
148 | browser.visit(confirm_link[0]) |
||
149 | assert browser.title, "Confirm E-mail Address" |
||
150 | browser.find_by_css('[type=submit]')[0].click() |
||
151 | |||
152 | poc_type = f.create_usertype(slug='poc', display_name='poc') |
||
153 | user2.profile.usertype.add(poc_type) |
||
154 | user2.profile.location = location1 |
||
155 | user2.profile.save() |
||
156 | user2.save() |
||
157 | |||
158 | org.user.add(user2) |
||
159 | org.save() |
||
160 | |||
161 | url = base_url + '/organisation/' |
||
162 | browser.fill('login', user2.email) |
||
163 | browser.fill('password', '123123') |
||
164 | browser.find_by_css('[type=submit]')[0].click() |
||
165 | browser.visit(url) |
||
166 | browser.find_by_text(org.name)[0].click() |
||
167 | assert not browser.find_by_text('Edit') |
||
168 |