From aba4e2285a4638c59ddacf360018436d62fd83e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=B0=B8=E5=BC=BA?= <11704063+s-yongqiang@user.noreply.gitee.com> Date: Wed, 14 Aug 2024 17:46:03 +0800 Subject: [PATCH] update test --- seahub/api2/utils.py | 2 +- .../registration/browse_login_email.html | 2 +- .../registration/new_device_login_email.html | 2 +- .../registration/password_change_email.html | 6 +---- tests/api/endpoints/test_send_share_link.py | 24 +++++++++---------- .../seahub/views/sysadmin/test_user_reset.py | 11 ++++----- 6 files changed, 21 insertions(+), 26 deletions(-) diff --git a/seahub/api2/utils.py b/seahub/api2/utils.py index 8678477d15a..f33c20416b7 100644 --- a/seahub/api2/utils.py +++ b/seahub/api2/utils.py @@ -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} diff --git a/seahub/templates/registration/browse_login_email.html b/seahub/templates/registration/browse_login_email.html index 9b90f9f436c..7dbd0c6244c 100644 --- a/seahub/templates/registration/browse_login_email.html +++ b/seahub/templates/registration/browse_login_email.html @@ -9,7 +9,7 @@

{% trans "Hi," %}

-{% 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 %}

{{ email }} diff --git a/seahub/templates/registration/new_device_login_email.html b/seahub/templates/registration/new_device_login_email.html index 343e5c1e473..86ccf1f7017 100644 --- a/seahub/templates/registration/new_device_login_email.html +++ b/seahub/templates/registration/new_device_login_email.html @@ -9,7 +9,7 @@

{% trans "Hi," %}

-{% 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 %}

diff --git a/seahub/templates/registration/password_change_email.html b/seahub/templates/registration/password_change_email.html index 00f17daa075..4af2d820318 100644 --- a/seahub/templates/registration/password_change_email.html +++ b/seahub/templates/registration/password_change_email.html @@ -7,11 +7,7 @@

{% trans "Hi," %}

-{% blocktrans with account=email %}Your password was changed. {% endblocktrans %} +{% blocktrans with account=user.username|email2nickname|escape %}Your password was changed. {{ account }}{% endblocktrans %}

-

-{{ email }} -

- {% endblock %} diff --git a/tests/api/endpoints/test_send_share_link.py b/tests/api/endpoints/test_send_share_link.py index 904878fce70..ec1ea65f386 100644 --- a/tests/api/endpoints/test_send_share_link.py +++ b/tests/api/endpoints/test_send_share_link.py @@ -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 == 'from_noreply@seafile.com' + assert 'test.txt' in mail.outbox[1].body + assert mail.outbox[1].from_email == 'from_noreply@seafile.com' @patch('seahub.utils.IS_EMAIL_CONFIGURED', True) @patch('seahub.api2.endpoints.send_share_link_email.IS_EMAIL_CONFIGURED', True) @@ -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) @@ -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, @@ -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) @@ -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) @@ -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) diff --git a/tests/seahub/views/sysadmin/test_user_reset.py b/tests/seahub/views/sysadmin/test_user_reset.py index 915bebd82fe..375c7edd673 100644 --- a/tests/seahub/views/sysadmin/test_user_reset.py +++ b/tests/seahub/views/sysadmin/test_user_reset.py @@ -26,17 +26,16 @@ def test_can_send_reset_email_to_contact_email(self): p.contact_email = 'contact@mail.com' 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] == 'contact@mail.com' - 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] == 'contact@mail.com' + self.assertEqual(len(mail.outbox), 2) def test_can_reset_when_pwd_change_required(self): self.config.FORCE_PASSWORD_CHANGE = 1