Conditions | 1 |
Total Lines | 86 |
Code Lines | 54 |
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:
1 | """ |
||
107 | @patch('byceps.email.send') |
||
108 | def test_create( |
||
109 | send_email_mock, |
||
110 | site_app, |
||
111 | brand, |
||
112 | site, |
||
113 | terms_version, |
||
114 | privacy_policy_consent_subject_id, |
||
115 | newsletter_list, |
||
116 | ): |
||
117 | screen_name = 'Hiro' |
||
118 | |||
119 | user_count_before = get_user_count() |
||
120 | assert find_user(screen_name) is None |
||
121 | |||
122 | form_data = { |
||
123 | 'screen_name': screen_name, |
||
124 | 'first_names': 'Hiroaki', |
||
125 | 'last_name': 'Protagonist', |
||
126 | 'email_address': '[email protected]', |
||
127 | 'password': 'Snow_Crash', |
||
128 | 'terms_version_id': terms_version.id, |
||
129 | 'consent_to_terms': 'y', |
||
130 | f'consent_to_subject_{privacy_policy_consent_subject_id}': 'y', |
||
131 | 'subscribe_to_newsletter': 'y', |
||
132 | } |
||
133 | |||
134 | response = send_request(site_app, form_data) |
||
135 | assert response.status_code == 302 |
||
136 | |||
137 | user_count_afterwards = get_user_count() |
||
138 | assert user_count_afterwards == user_count_before + 1 |
||
139 | |||
140 | user = find_user(screen_name) |
||
141 | assert user is not None |
||
142 | |||
143 | assert user.created_at is not None |
||
144 | assert user.screen_name == 'Hiro' |
||
145 | assert user.email_address == '[email protected]' |
||
146 | assert not user.initialized |
||
147 | assert not user.deleted |
||
148 | |||
149 | # events |
||
150 | assert_creation_event_created(user.id) |
||
151 | |||
152 | # password |
||
153 | assert_password_credentials_created(user.id) |
||
154 | |||
155 | # Session token should not have been created at this point. |
||
156 | session_token = session_service.find_session_token_for_user(user.id) |
||
157 | assert session_token is None |
||
158 | |||
159 | # avatar |
||
160 | assert user.avatar is None |
||
161 | |||
162 | # details |
||
163 | assert user.detail.first_names == 'Hiroaki' |
||
164 | assert user.detail.last_name == 'Protagonist' |
||
165 | |||
166 | # authorization |
||
167 | role_ids = authorization_service.find_role_ids_for_user(user.id) |
||
168 | assert role_ids == set() |
||
169 | |||
170 | # consents |
||
171 | assert_consent(user.id, terms_version.consent_subject_id) |
||
172 | assert_consent(user.id, privacy_policy_consent_subject_id) |
||
173 | |||
174 | # newsletter subscription |
||
175 | assert is_subscribed_to_newsletter(user.id, brand.id) |
||
176 | |||
177 | # confirmation e-mail |
||
178 | |||
179 | verification_token = find_verification_token(user.id) |
||
180 | assert verification_token is not None |
||
181 | |||
182 | expected_sender = '[email protected]' |
||
183 | expected_recipients = ['[email protected]'] |
||
184 | expected_subject = 'Hiro, bitte bestätige deine E-Mail-Adresse' |
||
185 | expected_body = f''' |
||
186 | Hallo Hiro, |
||
187 | |||
188 | bitte bestätige deine E-Mail-Adresse, indem du diese URL abrufst: https://www.acmecon.test/users/email_address/confirmation/{verification_token.token} |
||
189 | '''.strip() |
||
190 | |||
191 | send_email_mock.assert_called_once_with( |
||
192 | expected_sender, expected_recipients, expected_subject, expected_body |
||
193 | ) |
||
278 |