Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/integ tests notifications #1597

Merged
merged 27 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1b5ba8f
Skeletion notifications
noah-paige Sep 25, 2024
72075df
Skeletion notifications
noah-paige Sep 25, 2024
39364d4
remove tooling
Sep 27, 2024
18ab1e0
remove iam role after test
Sep 27, 2024
f4aec98
PR changes
Sep 30, 2024
8ba7f1a
remove unused test
Sep 30, 2024
3289ad6
Merge branch 'os-main' into feat/integ-tests-notifications
noah-paige Sep 30, 2024
36d2dd0
add notification tests
noah-paige Sep 30, 2024
e0c1a22
Integ Tests Notifications
noah-paige Oct 1, 2024
298e244
Remove countRead, countUnread, and delete Notification Ops
noah-paige Oct 1, 2024
00633e3
Missed cleanup files
noah-paige Oct 1, 2024
831df25
Merge latest OS
noah-paige Oct 1, 2024
4c19eb2
merge latest os
noah-paige Oct 2, 2024
6b1f556
ruff
noah-paige Oct 2, 2024
f9c3e1b
clean up delete notificiation
noah-paige Oct 2, 2024
a00951b
Merge latest os-main
noah-paige Oct 28, 2024
741031b
Fix notification tests since latest shares test changes
noah-paige Oct 28, 2024
e22537e
Add notification service and split logic
noah-paige Oct 28, 2024
4bb2c35
Add notification service and split logic
noah-paige Oct 28, 2024
3c156f7
merge latest os
noah-paige Nov 21, 2024
1a814c3
adda test unauth notification
noah-paige Nov 21, 2024
39da41c
fix
noah-paige Nov 21, 2024
bc26f2d
move out is_recipient check from notification access decorator
noah-paige Dec 6, 2024
cf5e282
Merge branch 'os-main' into feat/integ-tests-notifications
noah-paige Dec 6, 2024
ac6bc24
Add Notification Permission tests
noah-paige Dec 6, 2024
c8292e2
Merge branch 'main' into feat/integ-tests-notifications
dlpzx Dec 23, 2024
f8fe9a3
nit: PR review notification
dlpzx Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions backend/dataall/modules/notifications/api/mutations.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataall.base.api import gql
from .resolvers import delete, mark_as_read
from .resolvers import mark_as_read


markNotificationAsRead = gql.MutationField(
Expand All @@ -10,10 +10,3 @@
type=gql.Boolean,
resolver=mark_as_read,
)

deleteNotification = gql.MutationField(
name='deleteNotification',
args=[gql.Argument(name='notificationUri', type=gql.String)],
type=gql.Boolean,
resolver=delete,
)
16 changes: 0 additions & 16 deletions backend/dataall/modules/notifications/api/queries.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from dataall.base.api import gql
from .resolvers import (
count_deleted_notifications,
count_read_notifications,
count_unread_notifications,
list_my_notifications,
)
Expand All @@ -21,17 +19,3 @@
type=gql.Integer,
resolver=count_unread_notifications,
)

# Not used in frontend
countReadNotifications = gql.QueryField(
name='countReadNotifications',
type=gql.Integer,
resolver=count_read_notifications,
)

# Not used in frontend
countDeletedNotifications = gql.QueryField(
name='countDeletedNotifications',
type=gql.Integer,
resolver=count_deleted_notifications,
)
20 changes: 0 additions & 20 deletions backend/dataall/modules/notifications/api/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,3 @@ def count_unread_notifications(context: Context, source):
return NotificationRepository.count_unread_notifications(
session=session, username=get_context().username, groups=get_context().groups
)


def count_deleted_notifications(context: Context, source):
with _session() as session:
return NotificationRepository.count_deleted_notifications(
session=session, username=get_context().username, groups=get_context().groups
)


def count_read_notifications(context: Context, source):
with _session() as session:
return NotificationRepository.count_read_notifications(
session=session, username=get_context().username, groups=get_context().groups
)


def delete(context: Context, source, notificationUri):
_required_uri(notificationUri)
with _session() as session:
return NotificationRepository.delete_notification(session=session, notificationUri=notificationUri)
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,9 @@ def count_unread_notifications(session, username, groups):
)
return int(count)

@staticmethod
def count_read_notifications(session, username, groups):
count = (
session.query(func.count(models.Notification.notificationUri))
.filter(or_(models.Notification.recipient == username, models.Notification.recipient.in_(groups)))
.filter(models.Notification.is_read == True)
.filter(models.Notification.deleted.is_(None))
.scalar()
)
return int(count)

@staticmethod
def count_deleted_notifications(session, username, groups):
count = (
session.query(func.count(models.Notification.notificationUri))
.filter(or_(models.Notification.recipient == username, models.Notification.recipient.in_(groups)))
.filter(models.Notification.deleted.isnot(None))
.scalar()
)
return int(count)

@staticmethod
def read_notification(session, notificationUri):
notification = session.query(models.Notification).get(notificationUri)
notification.is_read = True
session.commit()
return True

@staticmethod
def delete_notification(session, notificationUri):
notification = session.query(models.Notification).get(notificationUri)
if notification:
notification.deleted = datetime.now()
session.commit()
return True
12 changes: 0 additions & 12 deletions frontend/src/services/graphql/Notification/archiveNotification.js

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions frontend/src/services/graphql/Notification/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export * from './archiveNotification';
export * from './countDeletedNotifications';
export * from './countReadNotifications';
export * from './countUnreadNotifications';
export * from './listNotifications';
export * from './markAsRead';
1 change: 1 addition & 0 deletions tests_new/integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'integration_tests.core.organizations.global_conftest',
'integration_tests.core.environment.global_conftest',
'integration_tests.modules.s3_datasets.global_conftest',
'integration_tests.modules.share_base.global_conftest',
]


Expand Down
22 changes: 22 additions & 0 deletions tests_new/integration_tests/modules/notifications/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest

from tests_new.integration_tests.modules.share_base.queries import (
submit_share_object,
add_share_item,
get_share_object,
remove_shared_item,
)


@pytest.fixture(scope='module')
def session_share_1_notifications(client5, session_share_1):
share_item_uri = None
try:
updated_share = get_share_object(client5, session_share_1.shareUri)
item_to_add = updated_share['items'].nodes[0]
share_item_uri = add_share_item(client5, session_share_1.shareUri, item_to_add.itemUri, item_to_add.itemType)
submit_share_object(client5, session_share_1.shareUri)
yield session_share_1
finally:
if share_item_uri:
remove_shared_item(client5, share_item_uri)
56 changes: 56 additions & 0 deletions tests_new/integration_tests/modules/notifications/queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# TODO: This file will be replaced by using the SDK directly


def mark_notification_read(client, uri):
query = {
'operationName': 'markNotificationAsRead',
'variables': {'notificationUri': uri},
'query': """
mutation markNotificationAsRead($notificationUri: String!) {
markNotificationAsRead(notificationUri: $notificationUri)
}
""",
}
response = client.query(query=query)
return response.data.markNotificationAsRead


def list_notifications(client, filter={}):
query = {
'operationName': 'listNotifications',
'variables': {'filter': filter},
'query': """
query listNotifications($filter: NotificationFilter) {
listNotifications(filter: $filter) {
count
page
pages
hasNext
hasPrevious
nodes {
notificationUri
message
type
is_read
target_uri
}
}
}
""",
}
response = client.query(query=query)
return response.data.listNotifications


dlpzx marked this conversation as resolved.
Show resolved Hide resolved
def count_unread_notifications(client):
query = {
'operationName': 'countUnreadNotifications',
'variables': {},
'query': """
query countUnreadNotifications {
countUnreadNotifications
}
""",
}
response = client.query(query=query)
return response.data.countUnreadNotifications
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from assertpy import assert_that

from integration_tests.errors import GqlError
from integration_tests.modules.notifications.queries import (
list_notifications,
count_unread_notifications,
mark_notification_read,
)


def test_list_notification(client1):
assert_that(list_notifications(client1)).contains_key('page', 'pages', 'nodes', 'count')
assert_that(list_notifications(client1, filter={'read': True})).contains_key('page', 'pages', 'nodes', 'count')
assert_that(list_notifications(client1, filter={'unread': True})).contains_key('page', 'pages', 'nodes', 'count')
assert_that(list_notifications(client1, filter={'archived': True})).contains_key('page', 'pages', 'nodes', 'count')


def test_count_unread_notification(client1):
assert_that(count_unread_notifications(client1)).is_greater_than_or_equal_to(0)


def test_read_notification_invalid(client1):
assert_that(mark_notification_read).raises(GqlError).when_called_with(client1, '').contains(
'RequiredParameter', 'URI'
)


def test_read_notification(client1, session_share_1_notifications):
count_unread = count_unread_notifications(client1)

response = list_notifications(client1)
mark_notification_read(client1, response.nodes[0].notificationUri)

assert_that(count_unread_notifications(client1)).is_equal_to(count_unread - 1)
Loading
Loading