Remove a couple un-needed things
This commit is contained in:
parent
d018ae2ec9
commit
0e5c8a39fa
@ -1,4 +1,3 @@
|
|||||||
import asyncio
|
|
||||||
import datetime
|
import datetime
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
@ -539,7 +538,7 @@ class MailAccountHandler(LoggingMixin):
|
|||||||
and account.expiration < timezone.now()
|
and account.expiration < timezone.now()
|
||||||
):
|
):
|
||||||
manager = PaperlessMailOAuth2Manager()
|
manager = PaperlessMailOAuth2Manager()
|
||||||
if asyncio.run(manager.refresh_account_oauth_token(account)):
|
if manager.refresh_account_oauth_token(account):
|
||||||
account.refresh_from_db()
|
account.refresh_from_db()
|
||||||
else:
|
else:
|
||||||
return total_processed_files
|
return total_processed_files
|
||||||
|
@ -64,7 +64,7 @@ class PaperlessMailOAuth2Manager:
|
|||||||
self.gmail_client.get_authorization_url(
|
self.gmail_client.get_authorization_url(
|
||||||
redirect_uri=self.oauth_callback_url,
|
redirect_uri=self.oauth_callback_url,
|
||||||
scope=["https://mail.google.com/"],
|
scope=["https://mail.google.com/"],
|
||||||
extras_params={"prompt": "consent", "access_type": "offline"},
|
extras_params={"access_type": "offline"},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -76,7 +76,6 @@ class PaperlessMailOAuth2Manager:
|
|||||||
"offline_access",
|
"offline_access",
|
||||||
"https://outlook.office.com/IMAP.AccessAsUser.All",
|
"https://outlook.office.com/IMAP.AccessAsUser.All",
|
||||||
],
|
],
|
||||||
extras_params={"response_type": "code"},
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1635,10 +1635,12 @@ class TestMailAccountTestView(APITestCase):
|
|||||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||||
self.assertEqual(response.content.decode(), "Unable to connect to server")
|
self.assertEqual(response.content.decode(), "Unable to connect to server")
|
||||||
|
|
||||||
@mock.patch("paperless_mail.oauth.PaperlessMailOAuth2Manager")
|
@mock.patch(
|
||||||
|
"paperless_mail.oauth.PaperlessMailOAuth2Manager.refresh_account_oauth_token",
|
||||||
|
)
|
||||||
def test_mail_account_test_view_refresh_token(
|
def test_mail_account_test_view_refresh_token(
|
||||||
self,
|
self,
|
||||||
mock_manager,
|
mock_refresh_account_oauth_token,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
@ -1660,7 +1662,7 @@ class TestMailAccountTestView(APITestCase):
|
|||||||
is_token=True,
|
is_token=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
mock_manager.return_value.refresh_account_oauth_token.return_value = True
|
mock_refresh_account_oauth_token.return_value = True
|
||||||
data = {
|
data = {
|
||||||
"id": existing_account.id,
|
"id": existing_account.id,
|
||||||
"imap_server": "imap.example.com",
|
"imap_server": "imap.example.com",
|
||||||
@ -1671,12 +1673,14 @@ class TestMailAccountTestView(APITestCase):
|
|||||||
"is_token": True,
|
"is_token": True,
|
||||||
}
|
}
|
||||||
self.client.post(self.url, data, format="json")
|
self.client.post(self.url, data, format="json")
|
||||||
self.assertEqual(mock_manager.call_count, 1)
|
self.assertEqual(mock_refresh_account_oauth_token.call_count, 1)
|
||||||
|
|
||||||
@mock.patch("paperless_mail.oauth.PaperlessMailOAuth2Manager")
|
@mock.patch(
|
||||||
|
"paperless_mail.oauth.PaperlessMailOAuth2Manager.refresh_account_oauth_token",
|
||||||
|
)
|
||||||
def test_mail_account_test_view_refresh_token_fails(
|
def test_mail_account_test_view_refresh_token_fails(
|
||||||
self,
|
self,
|
||||||
mock_manager,
|
mock_mock_refresh_account_oauth_token,
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
@ -1699,7 +1703,7 @@ class TestMailAccountTestView(APITestCase):
|
|||||||
is_token=True,
|
is_token=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
mock_manager.return_value.refresh_account_oauth_token.return_value = False
|
mock_mock_refresh_account_oauth_token.return_value = False
|
||||||
data = {
|
data = {
|
||||||
"id": existing_account.id,
|
"id": existing_account.id,
|
||||||
"imap_server": "imap.example.com",
|
"imap_server": "imap.example.com",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user