Skip to content

Commit 6bc5c4c

Browse files
committed
Merge branch 'refactor-notifications' of https://github.com/CenterForOpenScience/osf.io into add-new-notifications-data-model
* 'refactor-notifications' of https://github.com/CenterForOpenScience/osf.io: fix mail mocking issues for password reset mock mail for tests re-expose quickfiles migrated logs remove logs groups embedding remove logs groups embedding
2 parents 8bbe32f + 4c50c6c commit 6bc5c4c

5 files changed

Lines changed: 28 additions & 16 deletions

File tree

addons/boa/tests/test_tasks.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from addons.boa import settings as boa_settings
1010
from addons.boa.boa_error_code import BoaErrorCode
11-
from addons.boa.tasks import submit_to_boa, handle_boa_error
11+
from addons.boa.tasks import submit_to_boa, submit_to_boa_async, handle_boa_error
1212
from osf.models import NotificationType
1313
from osf_tests.factories import AuthUserFactory, ProjectFactory
1414
from tests.base import OsfTestCase
@@ -96,7 +96,7 @@ def test_submit_to_boa_async_called(self):
9696
new_callable=AsyncMock,
9797
return_value=BoaErrorCode.NO_ERROR
9898
) as mock_submit_to_boa_async:
99-
return_value = submit_to_boa(
99+
return_value = await submit_to_boa_async(
100100
self.host,
101101
self.username,
102102
self.password,
@@ -186,7 +186,7 @@ async def test_download_error(self):
186186
mock.patch('osf.models.user.OSFUser.get_or_create_cookie', return_value=self.user_cookie), \
187187
mock.patch('urllib.request.urlopen', side_effect=http_404), \
188188
mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error:
189-
return_value = submit_to_boa(
189+
return_value = await submit_to_boa_async(
190190
self.host,
191191
self.username,
192192
self.password,
@@ -217,7 +217,7 @@ async def test_login_error(self):
217217
mock.patch('boaapi.boa_client.BoaClient.login', side_effect=BoaException()) as mock_login, \
218218
mock.patch('boaapi.boa_client.BoaClient.close', return_value=None) as mock_close, \
219219
mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error:
220-
return_value = submit_to_boa(
220+
return_value = await submit_to_boa_async(
221221
self.host,
222222
self.username,
223223
self.password,
@@ -251,7 +251,7 @@ async def test_data_set_error(self):
251251
mock.patch('boaapi.boa_client.BoaClient.get_dataset', side_effect=BoaException()) as mock_get_dataset, \
252252
mock.patch('boaapi.boa_client.BoaClient.close', return_value=None) as mock_close, \
253253
mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error:
254-
return_value = submit_to_boa(
254+
return_value = await submit_to_boa_async(
255255
self.host,
256256
self.username,
257257
self.password,
@@ -286,7 +286,7 @@ async def test_submit_error(self):
286286
mock.patch('boaapi.boa_client.BoaClient.query', side_effect=BoaException()) as mock_query, \
287287
mock.patch('boaapi.boa_client.BoaClient.close', return_value=None) as mock_close, \
288288
mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error:
289-
return_value = submit_to_boa(
289+
return_value = await submit_to_boa_async(
290290
self.host,
291291
self.username,
292292
self.password,
@@ -324,7 +324,7 @@ async def test_compile_error(self):
324324
mock.patch('boaapi.boa_client.BoaClient.close', return_value=None) as mock_close, \
325325
mock.patch('asyncio.sleep', new_callable=AsyncMock, return_value=None), \
326326
mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error:
327-
return_value = submit_to_boa(
327+
return_value = await submit_to_boa_async(
328328
self.host,
329329
self.username,
330330
self.password,
@@ -362,7 +362,7 @@ async def test_execute_error(self):
362362
mock.patch('boaapi.boa_client.BoaClient.close', return_value=None) as mock_close, \
363363
mock.patch('asyncio.sleep', new_callable=AsyncMock, return_value=None), \
364364
mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error:
365-
return_value = submit_to_boa(
365+
return_value = await submit_to_boa_async(
366366
self.host,
367367
self.username,
368368
self.password,
@@ -399,7 +399,7 @@ async def test_output_error_(self):
399399
mock.patch('boaapi.boa_client.BoaClient.close', return_value=None) as mock_close, \
400400
mock.patch('asyncio.sleep', new_callable=AsyncMock, return_value=None), \
401401
mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error:
402-
return_value = submit_to_boa(
402+
return_value = await submit_to_boa_async(
403403
self.host,
404404
self.username,
405405
self.password,
@@ -437,7 +437,7 @@ async def test_upload_error_conflict(self):
437437
mock.patch('boaapi.boa_client.BoaClient.close', return_value=None) as mock_close, \
438438
mock.patch('asyncio.sleep', new_callable=AsyncMock, return_value=None), \
439439
mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error:
440-
return_value = submit_to_boa(
440+
return_value = await submit_to_boa_async(
441441
self.host,
442442
self.username,
443443
self.password,
@@ -475,7 +475,7 @@ async def test_upload_error_other(self):
475475
mock.patch('boaapi.boa_client.BoaClient.close', return_value=None) as mock_close, \
476476
mock.patch('asyncio.sleep', new_callable=AsyncMock, return_value=None), \
477477
mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error:
478-
return_value = submit_to_boa(
478+
return_value = await submit_to_boa_async(
479479
self.host,
480480
self.username,
481481
self.password,
@@ -506,7 +506,7 @@ async def test_file_too_large_error(self):
506506
with mock.patch('osf.models.user.OSFUser.objects.get', return_value=self.user), \
507507
mock.patch('osf.models.user.OSFUser.get_or_create_cookie', return_value=self.user_cookie), \
508508
mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error:
509-
return_value = submit_to_boa(
509+
return_value = await submit_to_boa_async(
510510
self.host,
511511
self.username,
512512
self.password,
@@ -542,7 +542,7 @@ async def test_job_timeout_error(self):
542542
mock.patch('boaapi.boa_client.BoaClient.query', return_value=self.mock_job), \
543543
mock.patch('boaapi.boa_client.BoaClient.close', return_value=None) as mock_close, \
544544
mock.patch('addons.boa.tasks.handle_boa_error', return_value=None) as mock_handle_boa_error:
545-
return_value = submit_to_boa(
545+
return_value = await submit_to_boa_async(
546546
self.host,
547547
self.username,
548548
self.password,

osf/models/notification.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,17 @@ def send(
3131
"""
3232
if not protocol_type == 'email':
3333
raise NotImplementedError(f'Protocol type {protocol_type}. Email notifications are only implemented.')
34-
3534
recipient_address = destination_address or self.subscription.user.username
35+
36+
logging.info(
37+
f"Attempting to send Notification:"
38+
f"\nto={getattr(self.subscription.user, 'username', destination_address)}"
39+
f"\nat={destination_address}"
40+
f"\ntype={self.subscription.notification_type}"
41+
f"\ncontext={self.event_context}"
42+
f"\nemail={email_context}"
43+
)
44+
3645
if protocol_type == 'email' and waffle.switch_is_active(features.ENABLE_MAILHOG):
3746
email.send_email_over_smtp(
3847
recipient_address,

osf/models/notification_subscription.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ def emit(
7171
"""
7272
logging.info(
7373
f"Attempting to create Notification:"
74-
f"\nto={self.user.username}"
74+
f"\nto={getattr(self.user, 'username', destination_address)}"
7575
f"\ntype={self.notification_type.name}"
7676
f"\nmessage_frequency={self.message_frequency}"
7777
f"\ncontext={event_context}"
78+
f"\nemail={email_context}"
79+
7880
)
7981
if self.message_frequency == 'instantly':
8082
notification = Notification.objects.create(

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
addopts = --ds=osf_tests.settings --tb=short --allow-hosts=127.0.0.1,192.168.168.167,localhost
2+
addopts = --ds=osf_tests.settings --tb=short --reuse-db --allow-hosts=127.0.0.1,192.168.168.167,localhost
33
filterwarnings =
44
once::UserWarning
55
ignore:.*U.*mode is deprecated:DeprecationWarning

tests/test_user_profile_view.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from rest_framework import status as http_status
88

99
from addons.github.tests.factories import GitHubAccountFactory
10+
from conftest import start_mock_send_grid
1011
from framework.celery_tasks import handlers
1112
from osf.external.spam import tasks as spam_tasks
1213
from osf.models import NotableDomain, NotificationType

0 commit comments

Comments
 (0)