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

add integration tests votes #1578

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions backend/dataall/modules/vote/db/vote_repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def get_vote(session, targetUri, targetType) -> [models.Vote]:
.filter(
models.Vote.targetUri == targetUri,
models.Vote.targetType == targetType,
models.Vote.username == get_context().username,
)
.first()
)
Expand All @@ -24,6 +25,7 @@ def upvote(session, targetUri: str, targetType: str, upvote: bool) -> [models.Vo
vote: models.Vote = (
session.query(models.Vote)
.filter(
models.Vote.username == get_context().username,
models.Vote.targetUri == targetUri,
models.Vote.targetType == targetType,
)
Expand Down
11 changes: 11 additions & 0 deletions tests_new/integration_tests/modules/vote/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest
from integration_tests.modules.vote.queries import upvote, get_vote


S3_DATASET_TARGET_TYPE = 'dataset'


@pytest.fixture(scope='session')
def vote1(client1, session_s3_dataset1):
upvote(client1, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE, True)
yield get_vote(client1, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE)
55 changes: 55 additions & 0 deletions tests_new/integration_tests/modules/vote/queries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# TODO: This file will be replaced by using the SDK directly


def upvote(client, uri, target_type, vote):
query = {
'operationName': 'upVote',
'variables': {'input': {'targetUri': uri, 'targetType': target_type, 'upvote': vote}},
'query': """
mutation upVote($input:VoteInput!){
upVote(input:$input){
voteUri
targetUri
targetType
upvote
}
}
""",
}

response = client.query(query=query)
return response.data.upVote


def count_upvotes(client, uri, target_type):
query = {
'operationName': 'countUpVotes',
'variables': {'targetUri': uri, 'targetType': target_type},
'query': """
query countUpVotes($targetUri:String!, $targetType:String!){
countUpVotes(targetUri:$targetUri, targetType:$targetType)
}
""",
}
response = client.query(query=query)
return response.data.countUpVotes


def get_vote(client, uri, target_type):
query = {
'operationName': 'getVote',
'variables': {'targetUri': uri, 'targetType': target_type},
'query': """
query getVote($targetUri:String!, $targetType:String!){
getVote(targetUri:$targetUri, targetType:$targetType){
upvote
voteUri
targetUri
targetType
}
}
""",
}
response = client.query(query=query)
print(response.data.getVote)
return response.data.getVote
22 changes: 22 additions & 0 deletions tests_new/integration_tests/modules/vote/test_vote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from assertpy import assert_that

from integration_tests.modules.vote.queries import upvote, count_upvotes
from integration_tests.modules.vote.conftest import S3_DATASET_TARGET_TYPE


def test_upvote(client1, vote1):
assert_that(vote1).is_not_none()
assert_that(vote1.voteUri).is_not_none()
assert_that(vote1.upvote).is_true()


def test_count_votes(client2, vote1, session_s3_dataset1):
count = count_upvotes(client2, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE)

# Assert incremeent by 1
upvote(client2, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE, True)
assert_that(count_upvotes(client2, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE)).is_equal_to(count + 1)

# Assert decrement by 1
upvote(client2, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE, False)
assert_that(count_upvotes(client2, session_s3_dataset1.datasetUri, S3_DATASET_TARGET_TYPE)).is_equal_to(count)
Loading