From 022f344b949fef977d24a9b22784c112ff545a13 Mon Sep 17 00:00:00 2001 From: Greg Back Date: Wed, 18 Jan 2017 16:32:52 -0800 Subject: [PATCH] Add UUID fixture --- stix2/test/test_stix2.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/stix2/test/test_stix2.py b/stix2/test/test_stix2.py index b96dfb4..9319ed6 100644 --- a/stix2/test/test_stix2.py +++ b/stix2/test/test_stix2.py @@ -1,6 +1,7 @@ """Tests for the stix2 library""" import datetime +import uuid import pytest import pytz @@ -24,6 +25,29 @@ def clock(monkeypatch): monkeypatch.setattr(datetime, 'datetime', mydatetime) +@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()) + + +def test_my_uuid4_fixture(uuid4): + assert uuid.uuid4() == "00000000-0000-0000-0000-000000000001" + assert uuid.uuid4() == "00000000-0000-0000-0000-000000000002" + assert uuid.uuid4() == "00000000-0000-0000-0000-000000000003" + for _ in range(256): + uuid.uuid4() + assert uuid.uuid4() == "00000000-0000-0000-0000-000000000104" + + + @pytest.mark.parametrize('dt,timestamp', [ (datetime.datetime(2017, 1, 1, tzinfo=pytz.utc), '2017-01-01T00:00:00Z'), (amsterdam.localize(datetime.datetime(2017, 1, 1)), '2016-12-31T23:00:00Z'),