Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
otter606 committed Feb 10, 2022
1 parent a13333a commit 1659797
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 64 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,12 @@ All notable changes to this project will be documented in this file

## Unreleased

## 2.3.2 2022-02-09

### Fixed

- #31 Extra fields ignored in bulk/ sample posts

## 2.3.1 2022-02-09

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -23,7 +23,7 @@ See [DEVELOPING.md](DEVELOPING.md) for details of running tests.
To install rspace-client and its dependencies, run

```bash
pip install rspace-client==2.3.1
pip install rspace-client==2.3.2
```

### Compatibility with RSpace server versions
Expand Down
8 changes: 2 additions & 6 deletions rspace_client/client_base.py
Expand Up @@ -99,9 +99,7 @@ def doDelete(self, path, resource_id):
"""
numeric_id = self._get_numeric_record_id(resource_id)
return self.retrieve_api_results(
"/{}/{}".format(path, numeric_id),
content_type=None,
request_type="DELETE",
"/{}/{}".format(path, numeric_id), content_type=None, request_type="DELETE",
)

def retrieve_api_results(
Expand Down Expand Up @@ -207,9 +205,7 @@ def serr(self, msg: str):
print(msg, file=sys.stderr)

def _stream(
self,
endpoint: str,
pagination: Pagination = Pagination(),
self, endpoint: str, pagination: Pagination = Pagination(),
):
"""
Yields items, making paginated requests to the server as each page
Expand Down
19 changes: 6 additions & 13 deletions rspace_client/eln/eln.py
Expand Up @@ -97,8 +97,7 @@ def get_document_csv(self, doc_id):
"""
numeric_doc_id = self._get_numeric_record_id(doc_id)
return self.retrieve_api_results(
"/documents/{}".format(numeric_doc_id),
content_type="text/csv",
"/documents/{}".format(numeric_doc_id), content_type="text/csv",
)

def create_document(
Expand Down Expand Up @@ -245,9 +244,7 @@ def update_document(
data["fields"] = fields
numeric_doc_id = self._get_numeric_record_id(document_id)
return self.retrieve_api_results(
"/documents/{}".format(numeric_doc_id),
request_type="PUT",
params=data,
"/documents/{}".format(numeric_doc_id), request_type="PUT", params=data,
)

# Sharing methods
Expand Down Expand Up @@ -687,8 +684,7 @@ def publish_form(self, form_id):
"""
numeric_doc_id = self._get_numeric_record_id(form_id)
return self.retrieve_api_results(
"/forms/{}/publish".format(numeric_doc_id),
request_type="PUT",
"/forms/{}/publish".format(numeric_doc_id), request_type="PUT",
)

def unpublish_form(self, form_id):
Expand All @@ -700,8 +696,7 @@ def unpublish_form(self, form_id):
"""
numeric_doc_id = self._get_numeric_record_id(form_id)
return self.retrieve_api_results(
"/forms/{}/unpublish".format(numeric_doc_id),
request_type="PUT",
"/forms/{}/unpublish".format(numeric_doc_id), request_type="PUT",
)

def share_form(self, form_id):
Expand All @@ -713,8 +708,7 @@ def share_form(self, form_id):
"""
numeric_doc_id = self._get_numeric_record_id(form_id)
return self.retrieve_api_results(
"/forms/{}/share".format(numeric_doc_id),
request_type="PUT",
"/forms/{}/share".format(numeric_doc_id), request_type="PUT",
)

def unshare_form(self, form_id):
Expand All @@ -727,8 +721,7 @@ def unshare_form(self, form_id):
"""
numeric_doc_id = self._get_numeric_record_id(form_id)
return self.retrieve_api_results(
"/forms/{}/unshare".format(numeric_doc_id),
request_type="PUT",
"/forms/{}/unshare".format(numeric_doc_id), request_type="PUT",
)

# Folder / notebook methods
Expand Down
4 changes: 1 addition & 3 deletions rspace_client/eln/filetree_importer.py
Expand Up @@ -24,9 +24,7 @@ def __init__(self, eln_client):

def _create_file_linking_doc(self, content, parent_folder_id, name, path2Id):
rs_doc = self.cli.create_document(
name,
parent_folder_id=parent_folder_id,
fields=[{"content": content}],
name, parent_folder_id=parent_folder_id, fields=[{"content": content}],
)
path2Id[name] = rs_doc["globalId"]

Expand Down
26 changes: 8 additions & 18 deletions rspace_client/inv/inv.py
Expand Up @@ -755,7 +755,7 @@ class ItemPost:
def __init__(
self,
name: str,
itemType:str,
itemType: str,
tags: Optional[str] = None,
description: Optional[str] = None,
extra_fields: Optional[Sequence] = [],
Expand Down Expand Up @@ -791,9 +791,9 @@ def __init__(
total_quantity: Quantity = None,
attachments=None,
):
super().__init__(name,"SAMPLE", tags, description, extra_fields)
super().__init__(name, "SAMPLE", tags, description, extra_fields)
## converts arguments into JSON POST syntax

if storage_temperature_min is not None:
self.data["storageTempMin"] = storage_temperature_min._toDict()
if storage_temperature_max is not None:
Expand Down Expand Up @@ -1206,9 +1206,7 @@ def _do_simple_list(self, endpoint, pagination, sample_filter):
if sample_filter is not None:
pagination.data.update(sample_filter.data)
return self.retrieve_api_results(
f"/{endpoint}",
request_type="GET",
params=pagination.data,
f"/{endpoint}", request_type="GET", params=pagination.data,
)

def stream_samples(
Expand Down Expand Up @@ -1413,8 +1411,7 @@ def duplicate(
id_to_copy = Id(item_to_duplicate)
endpoint = id_to_copy.get_api_endpoint()
rc = self.retrieve_api_results(
f"/{endpoint}/{id_to_copy.as_id()}/actions/duplicate",
request_type="POST",
f"/{endpoint}/{id_to_copy.as_id()}/actions/duplicate", request_type="POST",
)
if new_name is not None:
rc = self.rename(rc, new_name)
Expand Down Expand Up @@ -1455,9 +1452,7 @@ def add_note_to_subsample(
raise ValueError("Supplied id is not a subsamples")
data = {"content": note}
return self.retrieve_api_results(
f"/subSamples/{ss_id.as_id()}/notes",
request_type="POST",
params=data,
f"/subSamples/{ss_id.as_id()}/notes", request_type="POST", params=data,
)

def get_workbenches(self) -> Sequence[dict]:
Expand Down Expand Up @@ -1629,11 +1624,7 @@ def _id_as_container_id(self, target_container_id):
raise ValueError("Target must be a container")
return id_target

def add_items_to_list_container(
self,
target_container_id,
*item_ids: str,
) -> list:
def add_items_to_list_container(self, target_container_id, *item_ids: str,) -> list:
"""
Adds 1 or more items to a list container
Expand Down Expand Up @@ -2023,8 +2014,7 @@ def restore_sample_template(self, sample_template_id: Union[int, str]) -> dict:
"""
id_to_restore = Id(sample_template_id)
return self.retrieve_api_results(
f"/sampleTemplates/{id_to_restore.as_id()}/restore",
request_type="PUT",
f"/sampleTemplates/{id_to_restore.as_id()}/restore", request_type="PUT",
)

def transfer_sample_template_owner(
Expand Down
18 changes: 10 additions & 8 deletions rspace_client/tests/invapi_test.py
Expand Up @@ -154,23 +154,25 @@ def test_stream_samples(self):
for sample in gen:
result_count += 1
self.assertEqual(0, result_count)

def test_create_sample_withextra_fields(self):
ef1 = inv.ExtraField(name="ef1", content="createdf1 content")
sample = self.invapi.create_sample(base.random_string(),extra_fields=[ef1])
sample = self.invapi.create_sample(base.random_string(), extra_fields=[ef1])
updatedS = self.invapi.get_sample_by_id(sample["globalId"])
self.assertEqual(1, len(updatedS["extraFields"]))

def test_bulkcreate_sample_withextra_fields(self):
## TODO Fix
ef1 = inv.ExtraField(name="ef1",fieldType=inv.ExtraFieldType.TEXT, content="createdf1 content")
sample_post=inv.SamplePost(base.random_string(),extra_fields=[ef1])
sample = self.invapi.bulk_create_sample(sample_post).success_results()[0]['record']
ef1 = inv.ExtraField(
name="ef1", fieldType=inv.ExtraFieldType.TEXT, content="createdf1 content"
)
sample_post = inv.SamplePost(base.random_string(), extra_fields=[ef1])
sample = self.invapi.bulk_create_sample(sample_post).success_results()[0][
"record"
]
self.assertEqual(1, len(sample["extraFields"]))
## this works: {



def test_add_extra_fields(self):
sample = self.invapi.create_sample(base.random_string())
ef1 = inv.ExtraField(name="ef1", content="ef1 content")
Expand Down
19 changes: 4 additions & 15 deletions rspace_client/tests/template_builder_test.py
Expand Up @@ -17,10 +17,7 @@
class TemplateBuilderTest(unittest.TestCase):
def test_invalid_unit(self):
self.assertRaises(
ValueError,
TemplateBuilder,
"name",
"unknownUnit",
ValueError, TemplateBuilder, "name", "unknownUnit",
)

def test_add_radio(self):
Expand Down Expand Up @@ -69,10 +66,7 @@ def test_add_number_field_requires_number(self):
builder = TemplateBuilder("myTemplate", "ml")

self.assertRaises(
ValueError,
builder.number,
"pH",
"XXX",
ValueError, builder.number, "pH", "XXX",
)

def test_add_number_field_no_default(self):
Expand All @@ -83,9 +77,7 @@ def test_add_number_field_no_default(self):
def test_name_required(self):
builder = TemplateBuilder("myTemplate", "ml")
self.assertRaises(
ValueError,
builder.number,
"",
ValueError, builder.number, "",
)

def test_add_date(self):
Expand Down Expand Up @@ -136,10 +128,7 @@ def test_add_uri(self):
self.assertEqual(2, builder.field_count())
self.assertEqual("https://www.google.com", builder._fields()[0]["content"])
self.assertRaises(
ValueError,
builder.uri,
"name",
"aa://www.goog[le.com:XXXX",
ValueError, builder.uri, "name", "aa://www.goog[le.com:XXXX",
)

def test_build(self):
Expand Down

0 comments on commit 1659797

Please sign in to comment.