Skip to content

Commit 53ddf32

Browse files
committed
Style/lint fixes
1 parent 6c3a689 commit 53ddf32

File tree

1 file changed

+69
-82
lines changed

1 file changed

+69
-82
lines changed

stix2/test/test_data_sources.py

Lines changed: 69 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,58 @@
1-
import pytest
2-
import requests
3-
41
from stix2.sources import taxii
52

63

7-
#Data Source (common API)
8-
9-
10-
#TAXII
114
def test_ds_taxii():
125
ds = taxii.TAXIIDataSource()
136
assert ds.name == 'TAXII'
147

8+
159
def test_ds_taxii_name():
1610
ds = taxii.TAXIIDataSource(name='My Data Source Name')
1711
assert ds.name == "My Data Source Name"
1812

13+
1914
def test_ds_params():
2015
url = "http://taxii_url.com:5000"
21-
creds = {"username":"Wade", "password":"Wilson"}
22-
ds = taxii.TAXIIDataSource(api_root=url,
23-
auth= creds)
16+
creds = {"username": "Wade", "password": "Wilson"}
17+
ds = taxii.TAXIIDataSource(api_root=url, auth=creds)
2418
assert ds.taxii_info['api_root']['url'] == url
2519
assert ds.taxii_info['auth'] == creds
2620

21+
2722
def test_parse_taxii_filters():
2823
query = [
2924
{
30-
"field":"added_after",
31-
"op":"=",
32-
"value":"2016-02-01T00:00:01.000Z"
25+
"field": "added_after",
26+
"op": "=",
27+
"value": "2016-02-01T00:00:01.000Z"
3328
},
3429
{
35-
"field":"id",
36-
"op":"=",
37-
"value":"taxii stix object ID"
30+
"field": "id",
31+
"op": "=",
32+
"value": "taxii stix object ID"
3833
},
3934
{
40-
"field":"type",
41-
"op":"=",
42-
"value":"taxii stix object ID"
35+
"field": "type",
36+
"op": "=",
37+
"value": "taxii stix object ID"
4338
},
4439
{
45-
"field":"version",
46-
"op":"=",
47-
"value":"first"
40+
"field": "version",
41+
"op": "=",
42+
"value": "first"
4843
},
4944
{
50-
"field":"created_by_ref",
51-
"op":"=",
52-
"value":"Bane"
45+
"field": "created_by_ref",
46+
"op": "=",
47+
"value": "Bane"
5348
}
5449
]
5550

5651
expected_params = {
57-
"added_after":"2016-02-01T00:00:01.000Z",
58-
"match[id]":"taxii stix object ID",
59-
"match[type]":"taxii stix object ID",
60-
"match[version]":"first"
52+
"added_after": "2016-02-01T00:00:01.000Z",
53+
"match[id]": "taxii stix object ID",
54+
"match[type]": "taxii stix object ID",
55+
"match[version]": "first"
6156
}
6257

6358
ds = taxii.TAXIIDataSource()
@@ -73,95 +68,87 @@ class dummy(object):
7368

7469
obj_1 = dummy()
7570

76-
#First 3 filters are valid, remaining fields are erroneous in some way
71+
# First 3 filters are valid, remaining fields are erroneous in some way
7772
filters = [
7873
{
7974
"field": "type",
8075
"op": '=',
81-
"value":"malware"
76+
"value": "malware"
8277
},
8378
{
84-
"field":"id",
85-
"op":"!=",
86-
"value":"stix object id"
79+
"field": "id",
80+
"op": "!=",
81+
"value": "stix object id"
8782
},
8883
{
89-
"field":"labels",
90-
"op":"in",
91-
"value":["heartbleed","malicious-activity"]
84+
"field": "labels",
85+
"op": "in",
86+
"value": ["heartbleed", "malicious-activity"]
9287
},
9388
{
94-
"field":"revoked",
95-
"value":"filter missing \'op\' field"
89+
"field": "revoked",
90+
"value": "filter missing \'op\' field"
9691
},
9792
{
98-
"field":"granular_markings",
99-
"op":"=",
100-
"value":"not supported field - just place holder"
93+
"field": "granular_markings",
94+
"op": "=",
95+
"value": "not supported field - just place holder"
10196
},
10297
{
103-
"field":"modified",
104-
"op":"*",
105-
"value":"not supported operator - just place holder"
98+
"field": "modified",
99+
"op": "*",
100+
"value": "not supported operator - just place holder"
106101
},
107102
{
108-
"field":"created",
109-
"op":"=",
110-
"value":obj_1
103+
"field": "created",
104+
"op": "=",
105+
"value": obj_1
111106
}
112107
]
113108

114-
expected_errors =[
109+
expected_errors = [
115110
"Filter was missing a required field(key). Each filter requires 'field', 'op', 'value' keys.",
116111
"Filter 'field' is not a STIX 2.0 common property. Currently only STIX object common properties supported",
117112
"Filter operation(from 'op' field) not supported",
118113
"Filter 'value' type is not supported. The type(value) must be python immutable type or dictionary"
119114
]
120115

121116
ds = taxii.TAXIIDataSource()
122-
#add
117+
# add
123118
ids, statuses = ds.add_filter(filters)
124119

125-
#7 filters should have been successfully added
120+
# 7 filters should have been successfully added
126121
assert len(ids) == 7
127122

128-
#all filters added to data source
123+
# all filters added to data source
129124
for idx, status in enumerate(statuses):
130125
assert status['filter'] == filters[idx]
131126

132-
#proper status warnings were triggered
127+
# proper status warnings were triggered
133128
assert statuses[3]['errors'][0] == expected_errors[0]
134129
assert statuses[4]['errors'][0] == expected_errors[1]
135130
assert statuses[5]['errors'][0] == expected_errors[2]
136131
assert statuses[6]['errors'][0] == expected_errors[3]
137132

138133

139-
140-
#File
141-
142-
'''
143-
144-
def test_data_source_file():
145-
ds = file.FileDataSource()
146-
147-
assert ds.name == "DataSource"
148-
149-
150-
def test_data_source_name():
151-
ds = file.FileDataSource(name="My File Data Source")
152-
153-
assert ds.name == "My File Data Source"
154-
155-
156-
def test_data_source_get():
157-
ds = file.FileDataSource(name="My File Data Source")
158-
159-
with pytest.raises(NotImplementedError):
160-
ds.get("foo")
161-
162-
#filter testing
163-
def test_add_filter():
164-
ds = file.FileDataSource()
165-
166-
167-
'''
134+
# def test_data_source_file():
135+
# ds = file.FileDataSource()
136+
#
137+
# assert ds.name == "DataSource"
138+
#
139+
#
140+
# def test_data_source_name():
141+
# ds = file.FileDataSource(name="My File Data Source")
142+
#
143+
# assert ds.name == "My File Data Source"
144+
#
145+
#
146+
# def test_data_source_get():
147+
# ds = file.FileDataSource(name="My File Data Source")
148+
#
149+
# with pytest.raises(NotImplementedError):
150+
# ds.get("foo")
151+
#
152+
# #filter testing
153+
# def test_add_filter():
154+
# ds = file.FileDataSource()

0 commit comments

Comments
 (0)