forked from schreiber-lab/scicat_ingest
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from rosalindfranklininstitute/upsert-dataset
Upsert dataset
- Loading branch information
Showing
4 changed files
with
118 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ on: | |
- cron: '00 4 * * *' # daily at 4AM | ||
|
||
jobs: | ||
|
||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
Datablock, | ||
DataFile, | ||
Dataset, | ||
RawDataset, | ||
Ownable, | ||
) | ||
|
||
|
@@ -28,6 +29,26 @@ def add_mock_requests(mock_request): | |
) | ||
mock_request.post(local_url + "Samples", json={"sampleId": "dataset_id"}) | ||
mock_request.post(local_url + "RawDatasets/replaceOrCreate", json={"pid": "42"}) | ||
mock_request.get( | ||
local_url | ||
+ "/Datasets/?filter=%7B%22where%22:%7B%22sampleId%22:%20%22gargleblaster%22%7D%7D", | ||
json={"response": "random"}, | ||
) | ||
mock_request.get( | ||
local_url | ||
+ "/Datasets/?filter=%7B%22where%22:%7B%22sampleId%22:%20%22wowza%22%7D%7D", | ||
json={"response": "random"}, | ||
) | ||
mock_request.post( | ||
local_url | ||
+ "/RawDatasets/upsertWithWhere?where=%7B%22where%22:%7B%22sampleId%22:%20%22gargleblaster%22%7D%7D", | ||
json={"pid": "42"}, | ||
) | ||
mock_request.post( | ||
local_url | ||
+ "/RawDatasets/upsertWithWhere?where=%7B%22where%22:%7B%22sampleId%22:%20%22wowza%22%7D%7D", | ||
json={"pid": "54"}, | ||
) | ||
mock_request.post( | ||
local_url + "RawDatasets/42/origdatablocks", | ||
json={"response": "random"}, | ||
|
@@ -80,6 +101,33 @@ def test_scicate_ingest(): | |
) | ||
dataset_id = scicat.upload_raw_dataset(dataset) | ||
|
||
# new dataset | ||
dataset = RawDataset( | ||
path="/foo/bar", | ||
size=42, | ||
owner="slartibartfast", | ||
contactEmail="[email protected]", | ||
creationLocation="magrathea", | ||
creationTime=str(datetime.now()), | ||
type="raw", | ||
instrumentId="earth", | ||
proposalId="deepthought", | ||
dataFormat="planet", | ||
principalInvestigator="A. Mouse", | ||
sourceFolder="/foo/bar", | ||
scientificMetadata={"a": "newfield"}, | ||
sampleId="gargleblaster", | ||
**ownable.dict() | ||
) | ||
|
||
# Update existing record | ||
dataset_id = scicat.upsert_raw_dataset(dataset, {"sampleId": "gargleblaster"}) | ||
assert dataset_id == "42" | ||
|
||
# Upsert non-existing record | ||
dataset_id_2 = scicat.upsert_raw_dataset(dataset, {"sampleId": "wowza"}) | ||
assert dataset_id_2 == "54" | ||
|
||
# Datablock with DataFiles | ||
data_file = DataFile(path="/foo/bar", size=42) | ||
data_block = Datablock( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters