2017-03-22 13:46:39 +01:00
|
|
|
import uuid
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
import stix2
|
|
|
|
|
2017-05-09 21:10:53 +02:00
|
|
|
from .constants import (FAKE_TIME, INDICATOR_KWARGS, MALWARE_KWARGS,
|
|
|
|
RELATIONSHIP_KWARGS)
|
2017-03-22 13:46:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Inspired by: http://stackoverflow.com/a/24006251
|
|
|
|
@pytest.fixture
|
|
|
|
def clock(monkeypatch):
|
|
|
|
|
2017-06-23 00:47:35 +02:00
|
|
|
class mydatetime(stix2.utils.STIXdatetime):
|
2017-03-22 13:46:39 +01:00
|
|
|
@classmethod
|
|
|
|
def now(cls, tz=None):
|
|
|
|
return FAKE_TIME
|
|
|
|
|
2017-06-23 00:47:35 +02:00
|
|
|
monkeypatch.setattr(stix2.utils, 'STIXdatetime', mydatetime)
|
2017-03-22 13:46:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def uuid4(monkeypatch):
|
|
|
|
def wrapper():
|
|
|
|
data = [0]
|
|
|
|
|
|
|
|
def wrapped():
|
|
|
|
data[0] += 1
|
|
|
|
return "00000000-0000-0000-0000-00000000%04x" % data[0]
|
|
|
|
|
|
|
|
return wrapped
|
|
|
|
monkeypatch.setattr(uuid, "uuid4", wrapper())
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def indicator(uuid4, clock):
|
|
|
|
return stix2.Indicator(**INDICATOR_KWARGS)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def malware(uuid4, clock):
|
|
|
|
return stix2.Malware(**MALWARE_KWARGS)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def relationship(uuid4, clock):
|
|
|
|
return stix2.Relationship(**RELATIONSHIP_KWARGS)
|