Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_search_ids_dataframe_subset_of_cols(self):
ids = [
"e166e6253dd843624f6cbe4fd45e7f2cff4671e600b4d6371172dd92a0255946",
"6cd99c8f9e67e61892a691237b3342a4caae5ec1c76784b1b93952afda44ae24",
]
df = Products().search(ids=ids).to_df(columns=["name", "id"])
assert list(df.columns) == ["name", "id"]
assert len(df) == 2
def test_search_ids_retreives_names(self):
products = Products().search().to_df()
assert len(products) > 0
def test_search_ids(self):
ids = [
"e166e6253dd843624f6cbe4fd45e7f2cff4671e600b4d6371172dd92a0255946",
"6cd99c8f9e67e61892a691237b3342a4caae5ec1c76784b1b93952afda44ae24",
]
products = Products().search(ids=ids).to_list()
assert len(products) == 2
print([x.name for x in products])
def test_to_list(self):
Products().search().to_list()
def test_search_crude(self):
set_client(create_client())
result = [p.id for p in Products().search("Crude").to_list()]
assert (
"6f11b0724c9a4e85ffa7f1445bc768f054af755a090118dcf99f14745c261653"
in result
)
def test_search_ids_dataframe(self):
ids = [
"e166e6253dd843624f6cbe4fd45e7f2cff4671e600b4d6371172dd92a0255946",
"6cd99c8f9e67e61892a691237b3342a4caae5ec1c76784b1b93952afda44ae24",
]
df = Products().search(ids=ids).to_df()
assert list(df.columns) == DEFAULT_COLUMNS
assert len(df) == 2
def test_search_multiple_terms_to_dataframe(self):
df = (
Products()
.search(term=["diesel", "fuel oil", "grane"])
.to_df("all")
)
assert set(df.columns) == {
"id",
"name",
"layer.0",
"leaf",
"parent.0.name",
"parent.0.layer.0",
"parent.0.id",
"meta.api_min",
"meta.api_max",
"ref_type",
"meta.sulphur_min",
def test_load_all(self):
all_products = Products().load_all()
assert len(all_products) > 100
def test_lookup_crude(self):
set_client(create_client())
result = Products().reference(
"6f11b0724c9a4e85ffa7f1445bc768f054af755a090118dcf99f14745c261653"
)
assert result["name"] == "Crude"
def convert_to_product_ids(
ids_or_names_list: List[Union[ID, str]]
) -> List[ID]:
"""
Convert a mixed list of names or IDs to vessel ids.
# Example
```
>>> convert_to_product_ids(["crude"])
[...]
```
"""
return _convert_to_ids(ids_or_names_list, Products())