from ..bill import Bill
from validictory import ValidationError


def toy_bill():
    b = Bill(bill_id="HB 2017",
             session="2012A",
             title="A bill for an act to raise the cookie budget by 200%",
             type="bill")
    b.add_source("http://uri.example.com/", note="foo")
    b.validate()
    return b


def test_basic_invalid_bill():
    """ Test that we can create an invalid bill, and validation will fail """
    b = toy_bill()
    b.bill_id = None
    try:
        assert ("Big Garbage String") == b.validate()
    except ValidationError:
        pass


def test_verify_actions():
    """ Make sure actions work """
    b = toy_bill()
    b.add_action("Some dude liked it.", "some dude", "2013-04-29")
    b.validate()
    # XXX: Check output


def test_verify_related_bill():
    """ Make sure related bills work """
    b = toy_bill()
    b.add_related_bill(bill_id="HB 2020",
                       session="2011A",
                       chamber="upper",
                       relation="companion")  # continuation?
    b.validate()


def test_verify_documents():
    """ Make sure we can add documents """
    b = toy_bill()
    b.add_document(name="Fiscal Impact",
                   date="2013-04",
                   type='foo')

    links = [{
        "url": "http://foo.bar.baz",
    }, {
        "url": "http://hi.example.com/foo#bar",
        "mimetype": "text/html"
    }]
    b.add_document(name="Fiscal Impact",
                   date="2013-04",
                   type='foo',
                   links=links)
    b.validate()

    links.append({"mimetype": "foo"})
    b.add_document(name="Fiscal Impact",
                   date="2013-04",
                   type='foo',
                   links=links)
    try:
        assert ("This shouldn't happen") == b.validate()
    except ValidationError:
        pass


def test_verify_sponsors():
    """ Make sure sponsors work """
    b = toy_bill()
    b.add_sponsor(name="Joe Bleu",
                  sponsorship_type="Author",
                  entity_type="legislator",
                  primary=True,
                  chamber="upper")
    b.validate()


def test_subjects():
    b = toy_bill()
    b.add_subject("Foo")
    b.add_subject("Bar")
    b.validate()

@@ -2167,24 +2167,61 @@
 subjects():%0A
+    %22%22%22 Test we can add subjects %22%22%22%0A
     b = toy_
@@ -2274,28 +2274,811 @@
 ect(%22Bar%22)%0A    b.validate()%0A
+%0A%0Adef test_versions():%0A    %22%22%22 Test that versions work right %22%22%22%0A    b = toy_bill()%0A    b.add_version(name=%22Final Version%22,%0A                  date=%222013-04%22,%0A                  type='foo')%0A%0A    links = %5B%7B%0A        %22url%22: %22http://foo.bar.baz%22,%0A    %7D, %7B%0A        %22url%22: %22http://hi.example.com/foo#bar%22,%0A        %22mimetype%22: %22text/html%22%0A    %7D%5D%0A    b.add_version(name=%22Introduced Version%22,%0A                  date=%222013-04%22,%0A                  type='foo',%0A                  links=links)%0A    b.validate()%0A%0A    links.append(%7B%22mimetype%22: %22foo%22%7D)%0A    b.add_version(name=%22With Committee Markup%22,%0A                  date=%222013-04%22,%0A                  type='foo',%0A                  links=links)%0A    try:%0A        assert (%22This shouldn't happen%22) == b.validate()%0A    except ValidationError:%0A        pass%0A

Add testing for versions