示例#1
0
def test_create_chamber_basic():
    nc = lookup(abbr="NC")

    juris = Jurisdiction.objects.create(id=nc.jurisdiction_id,
                                        name=nc.name,
                                        division=None)
    leg = Organization.objects.create(
        id=nc.legislature_organization_id,
        name=nc.legislature_name,
        classification="legislature",
        jurisdiction=juris,
    )
    create_chamber(juris, leg, nc.lower)

    # ensure the org and posts were created
    org = Organization.objects.get(classification="lower")
    assert org.name == nc.lower.name
    assert org.id == nc.lower.organization_id
    assert org.posts.count() == 120
示例#2
0
def test_create_chamber_unicam():
    ne = lookup(abbr="NE")

    juris = Jurisdiction.objects.create(id=ne.jurisdiction_id,
                                        name=ne.name,
                                        division=None)
    leg = Organization.objects.create(
        id=ne.legislature_organization_id,
        name=ne.legislature_name,
        classification="legislature",
        jurisdiction=juris,
    )

    create_chamber(juris, leg, ne.legislature)

    # no org was created, but posts were
    assert Organization.objects.count() == 1
    org = Organization.objects.get(classification="legislature")
    assert org.posts.count() == 49
示例#3
0
def test_create_chamber_duplicate_with_changes():
    nc = lookup(abbr="NC")

    juris = Jurisdiction.objects.create(id=nc.jurisdiction_id,
                                        name=nc.name,
                                        division=None)
    leg = Organization.objects.create(
        id=nc.legislature_organization_id,
        name=nc.legislature_name,
        classification="legislature",
        jurisdiction=juris,
    )

    create_chamber(juris, leg, nc.lower)
    # second call, but lower chamber name has been changed
    nc.lower.name = "Ronald McDonald House of Clowns"
    with pytest.raises(IntegrityError):
        create_chamber(juris, leg,
                       nc.lower)  # unsupported, should definitely be loud

    assert Organization.objects.filter(classification="lower").count() == 1
示例#4
0
def test_create_chamber_duplicate_idempotent():
    nc = lookup(abbr="NC")

    juris = Jurisdiction.objects.create(id=nc.jurisdiction_id,
                                        name=nc.name,
                                        division=None)
    leg = Organization.objects.create(
        id=nc.legislature_organization_id,
        name=nc.legislature_name,
        classification="legislature",
        jurisdiction=juris,
    )

    # second call, identical to first, should be idempotent
    create_chamber(juris, leg, nc.lower)
    create_chamber(juris, leg, nc.lower)

    assert Organization.objects.filter(classification="lower").count() == 1

    # ensure the org and posts were created
    org = Organization.objects.get(classification="lower")
    assert org.name == nc.lower.name
    assert org.id == nc.lower.organization_id
    assert org.posts.count() == 120