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

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
8 changes: 7 additions & 1 deletion backend/dataall/core/environment/cdk/environment_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,13 @@ def create_integration_tests_role(self):

self.test_role.add_to_policy(
iam.PolicyStatement(
actions=['iam:GetRole', 'iam:CreateRole', 'iam:PutRolePolicy'],
actions=[
'iam:GetRole',
'iam:CreateRole',
'iam:DeleteRole',
'iam:PutRolePolicy',
'iam:DeleteRolePolicy',
],
effect=iam.Effect.ALLOW,
resources=[f'arn:aws:iam::{self.account}:role/dataall-test-*'],
),
Expand Down
31 changes: 16 additions & 15 deletions tests_new/integration_tests/aws_clients/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@


class IAMClient:
CONSUMPTION_POLICY_NAME = 'ConsumptionPolicy'

def __init__(self, session=boto3.Session(), region=os.environ.get('AWS_REGION', 'us-east-1')):
self._client = session.client('iam', region_name=region)
self._resource = session.resource('iam', region_name=region)
Expand All @@ -21,13 +23,12 @@ def get_role(self, role_name):
log.info(f'Error occurred: {e}')
return None

@staticmethod
def get_tooling_account_id():
session = boto3.Session()
param_client = session.client('ssm', os.environ.get('AWS_REGION', 'us-east-1'))
parameter_path = f"/dataall/{os.environ.get('ENVNAME', 'dev')}/toolingAccount"
toolingAccount = param_client.get_parameter(Name=parameter_path)['Parameter']['Value']
return toolingAccount
def delete_role(self, role_name):
try:
self._client.delete_role(RoleName=role_name)
except Exception as e:
log.error(e)
raise e

def create_role(self, account_id, role_name, test_role_name):
policy_doc = {
Expand All @@ -38,7 +39,6 @@ def create_role(self, account_id, role_name, test_role_name):
'Principal': {
'AWS': [
f'arn:aws:iam::{account_id}:root',
f'arn:aws:iam::{IAMClient.get_tooling_account_id()}:root',
f'arn:aws:sts::{account_id}:assumed-role/{test_role_name}/{test_role_name}',
]
},
Expand All @@ -58,23 +58,24 @@ def create_role(self, account_id, role_name, test_role_name):
log.error(e)
raise e

def create_role_if_not_exists(self, account_id, role_name, test_role_name):
role = self.get_role(role_name)
if role is None:
role = self.create_role(account_id, role_name, test_role_name)
return role

def get_consumption_role(self, account_id, role_name, test_role_name):
role = self.get_role(role_name)
if role is None:
role = self.create_role(account_id, role_name, test_role_name)
self.put_consumption_role_policy(role_name)
return role

def delete_policy(self, role_name, policy_name):
self._client.delete_role_policy(RoleName=role_name, PolicyName=policy_name)

def delete_consumption_role(self, role_name):
self.delete_policy(role_name, self.CONSUMPTION_POLICY_NAME)
self.delete_role(role_name)

def put_consumption_role_policy(self, role_name):
self._client.put_role_policy(
RoleName=role_name,
PolicyName='ConsumptionPolicy',
PolicyName=self.CONSUMPTION_POLICY_NAME,
PolicyDocument="""{
"Version": "2012-10-17",
"Statement": [
Expand Down
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)
98 changes: 98 additions & 0 deletions tests_new/integration_tests/modules/notifications/queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# 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 delete_notification(client, uri):
query = {
'operationName': 'deleteNotification',
'variables': {'notificationUri': uri},
'query': """
mutation deleteNotification($notificationUri: String!) {
deleteNotification(notificationUri: $notificationUri)
}
""",
}
response = client.query(query=query)
return response.data.deleteNotification


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_notificiations(client):
query = {
'operationName': 'countUnreadNotifications',
'variables': {},
'query': """
query countUnreadNotifications {
countUnreadNotifications
}
""",
}
response = client.query(query=query)
return response.data.countUnreadNotifications


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As commented already, count_read_notificiations and count_deleted_notificiations are not used in the FE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed all 3 ops

def count_read_notificiations(client):
query = {
'operationName': 'countReadNotifications',
'variables': {},
'query': """
query countReadNotifications {
countReadNotifications
}
""",
}
response = client.query(query=query)
return response.data.countReadNotifications


def count_deleted_notificiations(client):
query = {
'operationName': 'countDeletedNotifications',
'variables': {},
'query': """
query countDeletedNotifications {
countDeletedNotifications
}
""",
}
response = client.query(query=query)
return response.data.countDeletedNotifications
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import pytest
from assertpy import assert_that

from integration_tests.errors import GqlError
from integration_tests.modules.notifications.queries import (
list_notifications,
count_deleted_notificiations,
count_read_notificiations,
count_unread_notificiations,
mark_notification_read,
delete_notification,
)


def test_list_notification(client1):
assert_that(list_notifications(client1)).is_not_none()
assert_that(list_notifications(client1, filter={'read': True})).is_not_none()
assert_that(list_notifications(client1, filter={'unread': True})).is_not_none()
assert_that(list_notifications(client1, filter={'archived': True})).is_not_none()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can assert the keys of the response, not only that it is not None

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asserted contains_key(...)



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


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

countReadNotifications and countDeletedNotifications are not used in the frontend. Maybe we should delete them from the backend and remove the tests for countReadNotifications. wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deleteNotification is also not used in the frontend

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed all 3 ops

def test_count_read_notification(client1):
assert_that(count_read_notificiations(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_notificiations(client1)
count_read = count_read_notificiations(client1)

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

assert_that(count_unread_notificiations(client1)).is_equal_to(count_unread - 1)
assert_that(count_read_notificiations(client1)).is_equal_to(count_read + 1)


def test_delete_notification_invalid(client1):
assert_that(delete_notification).raises(GqlError).when_called_with(client1, '').contains('RequiredParameter', 'URI')


def test_delete_notification(client1, session_share_1_notifications):
count_deleted = count_deleted_notificiations(client1)
response = list_notifications(client1, {'read': True})
delete_notification(client1, response.nodes[0].notificationUri)
assert_that(count_deleted_notificiations(client1)).is_equal_to(count_deleted + 1)
Loading
Loading