diff --git a/tests_new/integration_tests/modules/feed/queries.py b/tests_new/integration_tests/modules/feed/queries.py new file mode 100644 index 000000000..0062c116a --- /dev/null +++ b/tests_new/integration_tests/modules/feed/queries.py @@ -0,0 +1,64 @@ +# TODO: This file will be replaced by using the SDK directly + + +def post_feed_message(client, target_uri, target_type, content): + query = { + 'operationName': 'PostFeedMessage', + 'variables': { + 'targetUri': target_uri, + 'targetType': target_type, + 'input': {'content': content}, + }, + 'query': """ + mutation PostFeedMessage( + $targetUri: String! + $targetType: String! + $input: FeedMessageInput! + ) { + postFeedMessage( + targetUri: $targetUri + targetType: $targetType + input: $input + ) { + feedMessageUri + content + created + creator + } + } + """, + } + response = client.query(query=query) + return response.data.postFeedMessage + + +def get_feed(client, target_uri, target_type, filter={}): + query = { + 'operationName': 'GetFeed', + 'variables': {'targetUri': target_uri, 'targetType': target_type, 'filter': filter}, + 'query': """ + query GetFeed( + $targetUri: String! + $targetType: String! + $filter: FeedMessageFilter + ) { + getFeed(targetUri: $targetUri, targetType: $targetType) { + messages(filter: $filter) { + count + hasNext + hasPrevious + page + pages + nodes { + content + feedMessageUri + creator + created + } + } + } + } + """, + } + response = client.query(query=query) + return response.data.getFeed diff --git a/tests_new/integration_tests/modules/feed/test_feed.py b/tests_new/integration_tests/modules/feed/test_feed.py new file mode 100644 index 000000000..17f984770 --- /dev/null +++ b/tests_new/integration_tests/modules/feed/test_feed.py @@ -0,0 +1,44 @@ +from assertpy import assert_that + +from integration_tests.errors import GqlError + +from integration_tests.modules.feed.queries import post_feed_message, get_feed + + +S3_DATASET_TARGET_TYPE = 'Dataset' + + +def test_get_feed(client1, session_s3_dataset1): + feed = get_feed(client1, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE) + assert_that(feed).is_not_none() + + +def test_post_feed_message(client1, session_s3_dataset1, session_id): + feed_message_count = get_feed( + client1, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE, filter={'term': session_id} + ).messages.count + + feed_mesage = post_feed_message(client1, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE, session_id) + assert_that(feed_mesage.feedMessageUri).is_not_none() + + feed = get_feed(client1, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE, filter={'term': session_id}) + assert_that(feed.messages.count).is_equal_to(feed_message_count + 1) + assert_that(feed.messages.nodes[0].content).is_equal_to(session_id) + + +def test_post_feed_message_invalid(client1, session_s3_dataset1): + assert_that(post_feed_message).raises(GqlError).when_called_with( + client1, session_s3_dataset1.datasetUri, None, None + ).contains('targetType', 'must not be null') + assert_that(post_feed_message).raises(GqlError).when_called_with( + client1, None, S3_DATASET_TARGET_TYPE, None + ).contains('targetUri', 'must not be null') + + +def test_get_feed_invalid(client1, session_s3_dataset1): + assert_that(get_feed).raises(GqlError).when_called_with(client1, session_s3_dataset1.datasetUri, None).contains( + 'targetType', 'must not be null' + ) + assert_that(get_feed).raises(GqlError).when_called_with(client1, None, S3_DATASET_TARGET_TYPE).contains( + 'targetUri', 'must not be null' + )