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