Skip to content

Commit

Permalink
Merge pull request #16 from RavenPack/fix-creating-edge-dataset
Browse files Browse the repository at this point in the history
Fix creating EDGE dataset without product attribute specified
  • Loading branch information
joserc87 authored Feb 1, 2024
2 parents 849287b + 2e6fa30 commit 8c6e0f0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions ravenpackapi/examples/edge_entity_reference_filtered.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
you get those mappings for the entities you are interested into, without having
to download all the rest.
"""

import csv

from ravenpackapi import RPApi
Expand Down
1 change: 1 addition & 0 deletions ravenpackapi/examples/ravenpack_annotations_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Note: this example requires the "futures" package in python 2.7,
or python 3.2+
"""

import glob
import os
from concurrent.futures.thread import ThreadPoolExecutor
Expand Down
6 changes: 2 additions & 4 deletions ravenpackapi/models/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,9 @@ def __init__(

self.uuid = uuid

# If the product is not specified, we assume it is RPA
# unless the uuid is specified, in which case we'll ask the server
self.product = product
if self.product is None and self.uuid is None:
self.product = "RPA"
if self.product is None and self.uuid is None and self.api is not None:
self.product = self.api.product

self.name = name
self.description = description
Expand Down
20 changes: 13 additions & 7 deletions ravenpackapi/tests/unit/models/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

class TestDataset:
def test_create_rpa_dataset(self, fake_api):
dataset = Dataset(api=fake_api, name="test")
dataset = Dataset(product="rpa", api=fake_api, name="test")
assert dataset.name == "test"
assert dataset.api == fake_api
assert dataset.product == "RPA"
assert dataset.product == "rpa"
dataset.save()
assert fake_api.datasets["1"] == {
"uuid": "1",
"product": "RPA",
"product": "rpa",
"product_version": "1.0",
"name": "test",
}
Expand All @@ -30,13 +30,18 @@ def test_create_edge_dataset(self, fake_api):
"name": "test",
}

def test_create_dataset_with_default_product(self, fake_api):
@pytest.mark.parametrize(
"product",
["rpa", "edge"],
)
def test_create_dataset_with_default_product(self, product):
fake_api = FakeAPI(product=product)
dataset = Dataset(api=fake_api, name="test")
assert dataset.product == "RPA"
assert dataset.product == product
dataset.save()
assert fake_api.datasets["1"] == {
"uuid": "1",
"product": "RPA",
"product": product,
"product_version": "1.0",
"name": "test",
}
Expand Down Expand Up @@ -117,8 +122,9 @@ def fake_api(self):


class FakeAPI:
def __init__(self):
def __init__(self, product="rpa"):
self.datasets = {}
self.product = product

def request(self, endpoint, method="get", json=None):
if method == "post":
Expand Down

0 comments on commit 8c6e0f0

Please sign in to comment.