import pytest


@pytest.fixture
def klass():
    from agile_analytics.models import AgileTicket
    return AgileTicket


@pytest.fixture
def datetime():
    from datetime import datetime
    return datetime


@pytest.fixture
def make_one(klass):
    def _make_one(*args, **kwargs):
        kwargs['key'] = kwargs.get('key', "TEST-1")
        return klass(*args, **kwargs)
    return _make_one


def test_construction(make_one):
    t = make_one()
    assert t


def test_flow_log_append_happy(make_one, datetime):
    t = make_one()
    t.flow_log.append(
        dict(
            entered_at=datetime.now(),
            state="Missouri"
        )
    )
    assert t.flow_log[0]


def test_flow_log_append_unicode(make_one, datetime):
    t = make_one()
    t.flow_log.append(
        dict(
            entered_at=datetime.now(),
            state="LA",
        )
    )
    assert t.flow_log[0][u'state'] == unicode("LA")


def test_flow_log_append_datetime(make_one, datetime):
    test_dt = datetime.now()
    t = make_one()
    t.flow_log.append(
        dict(
            entered_at=test_dt,
            state="OK"
        )
    )
    assert t.flow_log[0][u'entered_at'] == test_dt


def test_flow_log_append_unhappy(make_one, datetime):
    t = make_one()
    with pytest.raises(TypeError):
        t.flow_log.append(
            dict(
                state="SD",
                entered_at=str(datetime.now()),
            )
        )


def test_flow_log_append_unhappy_no_dict(make_one):
    t = make_one()
    with pytest.raises(TypeError):
        t.flow_log.append(['VT', '278461911'])

@@ -1,12 +1,36 @@
+%22%22%22Test the models.%22%22%22%0A%0A
 import pytes
@@ -58,24 +58,46 @@
 ef klass():%0A
+    %22%22%22Return CUT.%22%22%22%0A
     from agi
@@ -188,24 +188,58 @@
 datetime():%0A
+    %22%22%22Return Datetime module.%22%22%22%0A
     from dat
@@ -315,24 +315,67 @@
 one(klass):%0A
+    %22%22%22Function to make an AgileTicket.%22%22%22%0A
     def _mak
@@ -536,32 +536,65 @@
 tion(make_one):%0A
+    %22%22%22Ensure make_one works.%22%22%22%0A
     t = make_one
@@ -655,32 +655,88 @@
 one, datetime):%0A
+    %22%22%22Ensure FlowLogs require entered_at and state.%22%22%22%0A
     t = make_one
@@ -932,32 +932,79 @@
 one, datetime):%0A
+    %22%22%22Ensure flow log strings are unicode.%22%22%22%0A
     t = make_one
@@ -1227,24 +1227,73 @@
  datetime):%0A
+    %22%22%22Ensure flow log datetimes are honored.%22%22%22%0A
     test_dt 
@@ -1539,24 +1539,78 @@
  datetime):%0A
+    %22%22%22Ensure we only accept datetime-ish objects.%22%22%22%0A
     t = make
@@ -1794,24 +1794,24 @@
         )%0A%0A%0A
-
 def test_flo
@@ -1846,24 +1846,74 @@
 (make_one):%0A
+    %22%22%22Ensure we only accept dict-ish objects.%22%22%22%0A
     t = make

Add docstrings.