Skip to content

Commit 8fe80a7

Browse files
committed
PENG-3689 - Introducing support for datasets functionality
1 parent d55252e commit 8fe80a7

File tree

3 files changed

+45
-48
lines changed

3 files changed

+45
-48
lines changed

examples/datasets.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@
3232
"scope": "account",
3333
},
3434
repeat=None,
35-
timeframe={
36-
"aggregation": "monthly",
37-
"cycles": 1
38-
},
35+
timeframe={"aggregation": "monthly", "cycles": 1},
3936
export_type="csv",
4037
recipient_emails=None,
4138
)

ns1/dataset.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ def loadFromDict(self, dt):
6868
:param dict dt: dictionary containing *at least* either an id or domain/path/target
6969
"""
7070
if "id" in dt or (
71-
"name" in dt
72-
and "datatype" in dt
73-
and "repeat" in dt
74-
and "timeframe" in dt
75-
and "export_type" in dt
76-
and "recipient_emails" in dt
71+
"name" in dt
72+
and "datatype" in dt
73+
and "repeat" in dt
74+
and "timeframe" in dt
75+
and "export_type" in dt
76+
and "recipient_emails" in dt
7777
):
7878
self.data = dt
7979
return self
@@ -88,8 +88,16 @@ def delete(self, callback=None, errback=None):
8888
return self._rest.delete(id, callback=callback, errback=errback)
8989

9090
def create(
91-
self, name, datatype, repeat, timeframe, export_type, recipient_emails, callback=None, errback=None,
92-
**kwargs
91+
self,
92+
name,
93+
datatype,
94+
repeat,
95+
timeframe,
96+
export_type,
97+
recipient_emails,
98+
callback=None,
99+
errback=None,
100+
**kwargs
93101
):
94102
"""
95103
Create a new dataset. Pass a list of keywords and their values to
@@ -106,7 +114,15 @@ def create(
106114
raise DatasetException("dataset already loaded")
107115

108116
return self._rest.create(
109-
name, datatype, repeat, timeframe, export_type, recipient_emails, callback=None, errback=None, **kwargs
117+
name,
118+
datatype,
119+
repeat,
120+
timeframe,
121+
export_type,
122+
recipient_emails,
123+
callback=None,
124+
errback=None,
125+
**kwargs
110126
)
111127

112128
def listDatasets(self, callback=None, errback=None):
@@ -137,4 +153,6 @@ def retrieveReport(self, rp_id, dt_id=None, callback=None, errback=None):
137153
if dt_id is None:
138154
raise DatasetException("no dataset id: did you mean to create?")
139155

140-
return Datasets(self.config).retrieveReport(dt_id, rp_id, callback=callback, errback=errback)
156+
return Datasets(self.config).retrieveReport(
157+
dt_id, rp_id, callback=callback, errback=errback
158+
)

tests/unit/test_datasets.py

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ def datasets_config(config):
2828
return config
2929

3030

31-
@pytest.mark.parametrize(
32-
"url",
33-
[(
34-
"datasets"
35-
)]
36-
)
31+
@pytest.mark.parametrize("url", [("datasets")])
3732
def test_rest_datasets_list(datasets_config, url):
3833
z = NS1(config=datasets_config).datasets()
3934
z._make_request = mock.MagicMock()
@@ -48,10 +43,12 @@ def test_rest_datasets_list(datasets_config, url):
4843

4944
@pytest.mark.parametrize(
5045
"dtId, url",
51-
[(
46+
[
47+
(
5248
"96529d62-fb0c-4150-b5ad-6e5b8b2736f6",
53-
"datasets/96529d62-fb0c-4150-b5ad-6e5b8b2736f6"
54-
)]
49+
"datasets/96529d62-fb0c-4150-b5ad-6e5b8b2736f6",
50+
)
51+
],
5552
)
5653
def test_rest_dataset_retrieve(datasets_config, dtId, url):
5754
z = NS1(config=datasets_config).datasets()
@@ -65,12 +62,7 @@ def test_rest_dataset_retrieve(datasets_config, dtId, url):
6562
)
6663

6764

68-
@pytest.mark.parametrize(
69-
"url",
70-
[(
71-
"datasets"
72-
)]
73-
)
65+
@pytest.mark.parametrize("url", [("datasets")])
7466
def test_rest_dataset_create(datasets_config, url):
7567
z = NS1(config=datasets_config).datasets()
7668
z._make_request = mock.MagicMock()
@@ -81,10 +73,7 @@ def test_rest_dataset_create(datasets_config, url):
8173
"scope": "account",
8274
},
8375
repeat=None,
84-
timeframe={
85-
"aggregation": "monthly",
86-
"cycles": 1
87-
},
76+
timeframe={"aggregation": "monthly", "cycles": 1},
8877
export_type="csv",
8978
recipient_emails=None,
9079
)
@@ -98,10 +87,7 @@ def test_rest_dataset_create(datasets_config, url):
9887
"type": "num_queries",
9988
"scope": "account",
10089
},
101-
"timeframe": {
102-
"aggregation": "monthly",
103-
"cycles": 1
104-
},
90+
"timeframe": {"aggregation": "monthly", "cycles": 1},
10591
"repeat": None,
10692
"export_type": "csv",
10793
"recipient_emails": None,
@@ -113,10 +99,12 @@ def test_rest_dataset_create(datasets_config, url):
11399

114100
@pytest.mark.parametrize(
115101
"dtId, url",
116-
[(
102+
[
103+
(
117104
"96529d62-fb0c-4150-b5ad-6e5b8b2736f6",
118-
"datasets/96529d62-fb0c-4150-b5ad-6e5b8b2736f6"
119-
)]
105+
"datasets/96529d62-fb0c-4150-b5ad-6e5b8b2736f6",
106+
)
107+
],
120108
)
121109
def test_rest_datasets_delete(datasets_config, dtId, url):
122110
z = NS1(config=datasets_config).datasets()
@@ -138,10 +126,7 @@ def test_rest_datasets_buildbody(datasets_config):
138126
"type": "num_queries",
139127
"scope": "account",
140128
},
141-
"timeframe": {
142-
"aggregation": "monthly",
143-
"cycles": 1
144-
},
129+
"timeframe": {"aggregation": "monthly", "cycles": 1},
145130
"repeat": None,
146131
"recipient_emails": None,
147132
"export_type": "csv",
@@ -152,10 +137,7 @@ def test_rest_datasets_buildbody(datasets_config):
152137
"type": "num_queries",
153138
"scope": "account",
154139
},
155-
"timeframe": {
156-
"aggregation": "monthly",
157-
"cycles": 1
158-
},
140+
"timeframe": {"aggregation": "monthly", "cycles": 1},
159141
"repeat": None,
160142
"recipient_emails": None,
161143
"export_type": "csv",

0 commit comments

Comments
 (0)