2022-11-20 21:20:41 +08:00
|
|
|
import logging
|
|
|
|
|
2023-03-19 23:21:32 +08:00
|
|
|
import pytest
|
|
|
|
|
2023-02-26 22:14:43 +08:00
|
|
|
from felicity.apps.impress.tasks import impress_results
|
|
|
|
|
2022-11-20 21:20:41 +08:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
@pytest.mark.order(90)
|
|
|
|
async def test_sample_publish(gql_client, auth_data):
|
|
|
|
add_gql = """
|
2023-02-26 22:14:43 +08:00
|
|
|
mutation PublishSamples ($samples: [SamplePublishInputType!]!) {
|
2022-11-20 21:20:41 +08:00
|
|
|
publishSamples(samples: $samples){
|
2023-02-26 22:14:43 +08:00
|
|
|
... on OperationSuccess{
|
2022-11-20 21:20:41 +08:00
|
|
|
__typename
|
2023-02-26 22:14:43 +08:00
|
|
|
message
|
2022-11-20 21:20:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
... on OperationError {
|
|
|
|
__typename
|
|
|
|
error
|
|
|
|
suggestion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2023-03-19 23:21:32 +08:00
|
|
|
response = await gql_client.post(
|
|
|
|
"/felicity-gql",
|
|
|
|
json={
|
|
|
|
"query": add_gql,
|
|
|
|
"variables": {
|
|
|
|
"samples": [
|
|
|
|
{"uid": 1, "action": "publish"},
|
|
|
|
{"uid": 2, "action": "publish"},
|
|
|
|
{"uid": 3, "action": "publish"},
|
|
|
|
{"uid": 4, "action": "publish"},
|
|
|
|
{"uid": 5, "action": "publish"},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
headers=auth_data["headers"],
|
|
|
|
)
|
2022-11-20 21:20:41 +08:00
|
|
|
|
|
|
|
logger.info(f"publishing samples response: {response} {response.json()}")
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
_data = response.json()["data"]["publishSamples"]
|
2023-02-26 22:14:43 +08:00
|
|
|
assert _data["message"] == "Your results are being published in the background."
|
|
|
|
|
|
|
|
# process job for the next test
|
|
|
|
await impress_results(6)
|
2022-11-20 21:20:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
@pytest.mark.order(91)
|
|
|
|
async def test_sample_invalidate(gql_client, auth_data):
|
|
|
|
add_gql = """
|
|
|
|
mutation InvalidateSamples ($samples: [Int!]!) {
|
|
|
|
invalidateSamples(samples: $samples){
|
|
|
|
... on SampleListingType{
|
|
|
|
__typename
|
|
|
|
samples {
|
|
|
|
uid
|
|
|
|
status
|
|
|
|
sampleId
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
... on OperationError {
|
|
|
|
__typename
|
|
|
|
error
|
|
|
|
suggestion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2023-03-19 23:21:32 +08:00
|
|
|
response = await gql_client.post(
|
|
|
|
"/felicity-gql",
|
|
|
|
json={
|
|
|
|
"query": add_gql,
|
|
|
|
"variables": {
|
|
|
|
"samples": [1],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
headers=auth_data["headers"],
|
|
|
|
)
|
2022-11-20 21:20:41 +08:00
|
|
|
|
|
|
|
logger.info(f"publishing samples response: {response} {response.json()}")
|
|
|
|
|
|
|
|
assert response.status_code == 200
|
|
|
|
_data = response.json()["data"]["invalidateSamples"]
|
|
|
|
assert len(_data["samples"]) == 2
|
|
|
|
for _, sample in enumerate(_data["samples"]):
|
2023-03-19 23:21:32 +08:00
|
|
|
if sample["uid"] == 1:
|
|
|
|
assert sample["status"] == "invalidated"
|
|
|
|
assert sample["sampleId"].endswith("_R01") is False
|
2022-11-20 21:20:41 +08:00
|
|
|
else:
|
2023-03-19 23:21:32 +08:00
|
|
|
assert sample["status"] == "received"
|
|
|
|
assert sample["sampleId"].endswith("_R01") is True
|