Skip to content

Commit

Permalink
Add integration tests feed (#1579)
Browse files Browse the repository at this point in the history
### Feature or Bugfix
<!-- please choose -->
- Feature

### Detail
- Add integration tests for `feed` module


### Relates
- #1220 

### Security
Please answer the questions below briefly where applicable, or write
`N/A`. Based on
[OWASP 10](https://owasp.org/Top10/en/).

- Does this PR introduce or modify any input fields or queries - this
includes
fetching data from storage outside the application (e.g. a database, an
S3 bucket)?
  - Is the input sanitized?
- What precautions are you taking before deserializing the data you
consume?
  - Is injection prevented by parametrizing queries?
  - Have you ensured no `eval` or similar functions are used?
- Does this PR introduce any functionality or component that requires
authorization?
- How have you ensured it respects the existing AuthN/AuthZ mechanisms?
  - Are you logging failed auth attempts?
- Are you using or adding any cryptographic features?
  - Do you use a standard proven implementations?
  - Are the used keys controlled by the customer? Where are they stored?
- Are you introducing any new policies/roles/users?
  - Have you used the least-privilege principle? How?


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.
  • Loading branch information
noah-paige authored Oct 1, 2024
1 parent 9204f0a commit cb909e9
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests_new/integration_tests/modules/feed/queries.py
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions tests_new/integration_tests/modules/feed/test_feed.py
Original file line number Diff line number Diff line change
@@ -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'
)

0 comments on commit cb909e9

Please sign in to comment.