forked from Cosive/cti-toolkit
-
Notifications
You must be signed in to change notification settings - Fork 4
/
conftest.py
52 lines (41 loc) · 1.47 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Test setup."""
import sys
from six import StringIO
import pytest
import stix
from certau.scripts import stixtransclient
@pytest.fixture(scope='module')
def package():
"""Create a 'package' fixture.
If you include 'package' as a test argument, you have access to a
pre-loaded STIX package, ready to transform.
"""
with open('tests/CA-TEST-STIX.xml', 'rt') as stix_f:
stix_io = StringIO(stix_f.read())
return stix.core.STIXPackage.from_xml(stix_io)
@pytest.fixture
def client_wrapper(monkeypatch):
"""Wrapper around the client to test command line arguments are mapped to
certau.transform.transform_package() properly.
"""
last_call_args = []
def save_args(pkg, transform, kwargs):
"""Drop-in replacement for capturing how it was called."""
del last_call_args[:]
last_call_args.extend((pkg, transform, kwargs))
monkeypatch.setattr(stixtransclient, 'transform_package', save_args)
class ClientWrapper(object):
"""Wrap the two different helpers."""
@staticmethod
def set_command_line(new_args):
"""Set sys.argv."""
filename = sys.argv[0]
full_args = [filename] + new_args
monkeypatch.setattr(sys, 'argv', full_args)
@staticmethod
def last_args():
"""Return the last args passed to
stixtransclient._process_package().
"""
return last_call_args
return ClientWrapper