Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
孙永强 committed Aug 15, 2024
1 parent 062f7e9 commit aba4e22
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
2 changes: 1 addition & 1 deletion seahub/api2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def get_token_v2(request, username, platform, device_id, device_name,
raise serializers.ValidationError('invalid platform')

if not TokenV2.objects.filter(user=username, device_id=device_id).first():
email_template_name='registration/new_device_login_email.html'
email_template_name = 'registration/new_device_login_email.html'
send_to = email2contact_email(username)
site_name = get_site_name()
c = {'email': send_to}
Expand Down
2 changes: 1 addition & 1 deletion seahub/templates/registration/browse_login_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<p style="color:#121214;font-size:14px;">{% trans "Hi," %}</p>

<p style="font-size:14px;color:#434144;">
{% blocktrans with account=email %}You are currently logging into this site using a browser{% endblocktrans %}
{% blocktrans %}You are currently logging into this site using a browser{% endblocktrans %}
</p>
<p style="font-size:14px;color:#434144;margin-left: auto">
{{ email }}
Expand Down
2 changes: 1 addition & 1 deletion seahub/templates/registration/new_device_login_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<p style="color:#121214;font-size:14px;">{% trans "Hi," %}</p>

<p style="font-size:14px;color:#434144;">
{% blocktrans with account=email %}You are trying to log in to your account with a new device {{ account }}{% endblocktrans %}
{% blocktrans with account=user.username|email2nickname|escape %}You are trying to log in to your account with a new device {{ account }}{% endblocktrans %}
</p>

<p style="font-size:14px;color:#434144;">
Expand Down
6 changes: 1 addition & 5 deletions seahub/templates/registration/password_change_email.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
<p style="color:#121214;font-size:14px;">{% trans "Hi," %}</p>

<p style="font-size:14px;color:#434144;">
{% blocktrans with account=email %}Your password was changed. {% endblocktrans %}
{% blocktrans with account=user.username|email2nickname|escape %}Your password was changed. {{ account }}{% endblocktrans %}
</p>
<p style="font-size:14px;color:#434144;">
{{ email }}
</p>


{% endblock %}
24 changes: 12 additions & 12 deletions tests/api/endpoints/test_send_share_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def test_can_send_email_configured(self):

resp = self.client.post(url, data)
self.assertEqual(200, resp.status_code)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(len(mail.outbox), 2)
json_resp = json.loads(resp.content)
assert json_resp['success'][0] == self.admin.email
assert json_resp['failed'][0]['email'] == invalid_email
assert 'test.txt' in mail.outbox[0].body
assert mail.outbox[0].from_email == '[email protected]'
assert 'test.txt' in mail.outbox[1].body
assert mail.outbox[1].from_email == '[email protected]'

@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
@patch('seahub.api2.endpoints.send_share_link_email.IS_EMAIL_CONFIGURED', True)
Expand All @@ -57,11 +57,11 @@ def test_can_send_email_rewrite(self):

resp = self.client.post(url, data)
self.assertEqual(200, resp.status_code)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(len(mail.outbox), 2)
json_resp = json.loads(resp.content)
assert json_resp['success'][0] == self.admin.email
assert 'test.txt' in mail.outbox[0].body
assert mail.outbox[0].extra_headers['Reply-to'] == self.user.email
assert 'test.txt' in mail.outbox[1].body
assert mail.outbox[1].extra_headers['Reply-to'] == self.user.email

@patch('seahub.utils.IS_EMAIL_CONFIGURED', True)
@patch('seahub.api2.endpoints.send_share_link_email.IS_EMAIL_CONFIGURED', True)
Expand All @@ -75,7 +75,6 @@ def test_can_send_email_rewrite_contact_email(self):
p.save()

refresh_cache(self.user.email)

url = reverse("api2-send-share-link")
data = {
"token": self.token,
Expand All @@ -84,11 +83,12 @@ def test_can_send_email_rewrite_contact_email(self):

resp = self.client.post(url, data)
self.assertEqual(200, resp.status_code)
self.assertEqual(len(mail.outbox), 1)

self.assertEqual(len(mail.outbox), 2)
json_resp = json.loads(resp.content)
assert json_resp['success'][0] == self.admin.email
assert 'test.txt' in mail.outbox[0].body
assert mail.outbox[0].extra_headers['Reply-to'] == contact_email
assert 'test.txt' in mail.outbox[1].body
assert mail.outbox[1].extra_headers['Reply-to'] == contact_email

@patch('seahub.utils.IS_EMAIL_CONFIGURED', False)
@patch('seahub.api2.endpoints.send_share_link_email.IS_EMAIL_CONFIGURED', False)
Expand All @@ -103,7 +103,7 @@ def test_can_send_email_not_configured(self):

resp = self.client.post(url, data)
self.assertEqual(403, resp.status_code)
self.assertEqual(len(mail.outbox), 0)
self.assertEqual(len(mail.outbox), 1)

def test_can_not_send_email_if_not_link_owner(self):
self.login_as(self.admin)
Expand All @@ -115,4 +115,4 @@ def test_can_not_send_email_if_not_link_owner(self):

resp = self.client.post(url, data)
self.assertEqual(403, resp.status_code)
self.assertEqual(len(mail.outbox), 0)
self.assertEqual(len(mail.outbox), 1)
11 changes: 5 additions & 6 deletions tests/seahub/views/sysadmin/test_user_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ def test_can_send_reset_email_to_contact_email(self):
p.contact_email = '[email protected]'
p.save()

self.assertEqual(len(mail.outbox), 0)
self.assertEqual(len(mail.outbox), 1)

resp = self.client.post(
reverse('user_reset', args=[self.user.email])
)
self.assertEqual(302, resp.status_code)

self.assertEqual(len(mail.outbox), 1)
assert mail.outbox[0].to[0] != self.user.username
assert mail.outbox[0].to[0] == '[email protected]'
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(len(mail.outbox), 2)
assert mail.outbox[1].to[0] != self.user.username
assert mail.outbox[1].to[0] == '[email protected]'
self.assertEqual(len(mail.outbox), 2)

def test_can_reset_when_pwd_change_required(self):
self.config.FORCE_PASSWORD_CHANGE = 1
Expand Down

0 comments on commit aba4e22

Please sign in to comment.