"""Tests for the stix2 library"""

import datetime

import pytest
import pytz

import stix2

amsterdam = pytz.timezone('Europe/Amsterdam')
eastern = pytz.timezone('US/Eastern')


@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'),
    (eastern.localize(datetime.datetime(2017, 1, 1, 12, 34, 56)), '2017-01-01T17:34:56Z'),
    (eastern.localize(datetime.datetime(2017, 7, 1)), '2017-07-01T04:00:00Z'),
])
def test_timestamp_formatting(dt, timestamp):
    assert stix2.format_datetime(dt) == timestamp


def test_basic_indicator():
    indicator = stix2.Indicator()
    assert indicator.id.startswith("indicator")


EXPECTED = """{
    "created": "2017-01-01T00:00:00Z",
    "id": "indicator--01234567-89ab-cdef-0123-456789abcdef",
    "labels": [
        "malicious-activity"
    ],
    "modified": "2017-01-01T00:00:00Z",
    "pattern": "[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']",
    "type": "indicator",
    "valid_from": "1970-01-01T00:00:00Z"
}"""


def test_indicator_with_all_required_fields():
    now = datetime.datetime(2017, 1, 1, 0, 0, 0, tzinfo=pytz.utc)
    epoch = datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=pytz.utc)

    indicator = stix2.Indicator(
        type="indicator",
        id="indicator--01234567-89ab-cdef-0123-456789abcdef",
        created=now,
        modified=now,
        labels=['malicious-activity'],
        pattern="[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']",
        valid_from=epoch,
    )

    assert str(indicator) == EXPECTED

@@ -649,120 +649,8 @@
 p%0A%0A%0A
-def test_basic_indicator():%0A    indicator = stix2.Indicator()%0A    assert indicator.id.startswith(%22indicator%22)%0A%0A%0A
 EXPE
@@ -1314,42 +1314,304 @@
     
-created=now,%0A        modified=now,
+labels=%5B'malicious-activity'%5D,%0A        pattern=%22%5Bfile:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e'%5D%22,%0A        created=now,%0A        modified=now,%0A        valid_from=epoch,%0A    )%0A%0A    assert str(indicator) == EXPECTED%0A%0A%0Adef test_indicator_autogenerated_fields():%0A    indicator = stix2.Indicator(
 %0A   
@@ -1728,71 +1728,368 @@
     
+)%0A%0A
     
-valid_from=epoch,%0A    )%0A%0A    assert str(indicator) == EXPECTED
+assert indicator.type == 'indicator'%0A    assert indicator.id.startswith('indicator--')%0A    assert indicator.created is not None%0A    assert indicator.modified is not None%0A    assert indicator.labels == %5B'malicious-activity'%5D%0A    assert indicator.pattern == %22%5Bfile:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e'%5D%22%0A    assert indicator.valid_from is not None
 %0A

Add tests for all different fields