<s> import pytest <EOL> from validictory import ValidationError <EOL> from pupa . scrape import Bill <EOL> from pupa . utils . generic import get_pseudo_id <EOL> def toy_bill ( ) : <EOL> b = Bill ( identifier = "<STR_LIT>" , legislative_session = "<STR_LIT>" , <EOL> title = "<STR_LIT>" , <EOL> from_organization = "<STR_LIT>" , classification = "<STR_LIT>" ) <EOL> b . add_source ( "<STR_LIT>" , note = "<STR_LIT:foo>" ) <EOL> return b <EOL> def test_basic_valid_bill ( ) : <EOL> b = toy_bill ( ) <EOL> b . validate ( ) <EOL> assert '<STR_LIT>' <EOL> def test_bill_type_setting ( ) : <EOL> b = Bill ( identifier = "<STR_LIT>" , legislative_session = "<STR_LIT>" , title = "<STR_LIT>" ) <EOL> assert b . classification == [ "<STR_LIT>" ] <EOL> b = Bill ( identifier = "<STR_LIT>" , legislative_session = "<STR_LIT>" , title = "<STR_LIT>" , <EOL> classification = "<STR_LIT:string>" ) <EOL> assert b . classification == [ "<STR_LIT:string>" ] <EOL> b = Bill ( identifier = "<STR_LIT>" , legislative_session = "<STR_LIT>" , title = "<STR_LIT>" , <EOL> classification = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> assert b . classification == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> b = Bill ( identifier = "<STR_LIT>" , legislative_session = "<STR_LIT>" , title = "<STR_LIT>" , <EOL> classification = ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> assert b . classification == [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> def test_basic_invalid_bill ( ) : <EOL> """<STR_LIT>""" <EOL> b = toy_bill ( ) <EOL> b . identifier = None <EOL> with pytest . raises ( ValueError ) : <EOL> b . validate ( ) <EOL> def test_from_organization ( ) : <EOL> assert ( ( get_pseudo_id ( Bill ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) . from_organization ) == <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> assert ( get_pseudo_id ( Bill ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , chamber = '<STR_LIT>' ) . from_organization ) == <EOL> { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> assert Bill ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , from_organization = '<STR_LIT:test>' ) . from_organization == '<STR_LIT:test>' <EOL> with pytest . raises ( ValueError ) : <EOL> Bill ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , from_organization = '<STR_LIT>' , chamber = '<STR_LIT>' ) <EOL> def test_add_action ( ) : <EOL> """<STR_LIT>""" <EOL> b = toy_bill ( ) <EOL> b . add_action ( "<STR_LIT>" , "<STR_LIT>" , chamber = '<STR_LIT>' ) <EOL> assert len ( b . actions ) == <NUM_LIT:1> <EOL> assert b . actions [ <NUM_LIT:0> ] [ '<STR_LIT:description>' ] == '<STR_LIT>' <EOL> assert get_pseudo_id ( b . actions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) == { '<STR_LIT>' : '<STR_LIT>' } <EOL> assert b . actions [ <NUM_LIT:0> ] [ '<STR_LIT:date>' ] == '<STR_LIT>' <EOL> b . validate ( ) <EOL> def test_add_related_bill ( ) : <EOL> """<STR_LIT>""" <EOL> b = toy_bill ( ) <EOL> b . add_related_bill ( identifier = "<STR_LIT>" , legislative_session = "<STR_LIT>" , <EOL> relation_type = "<STR_LIT>" ) <EOL> assert len ( b . related_bills ) == <NUM_LIT:1> <EOL> assert b . related_bills [ <NUM_LIT:0> ] == { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> b . validate ( ) <EOL> def test_add_sponsor ( ) : <EOL> b = toy_bill ( ) <EOL> b . add_sponsorship ( name = "<STR_LIT>" , classification = "<STR_LIT>" , entity_type = "<STR_LIT>" , <EOL> primary = True , chamber = "<STR_LIT>" ) <EOL> assert len ( b . sponsorships ) == <NUM_LIT:1> <EOL> assert b . sponsorships [ <NUM_LIT:0> ] == { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , '<STR_LIT>' : None } <EOL> b . validate ( ) <EOL> def test_subjects ( ) : <EOL> b = toy_bill ( ) <EOL> b . add_subject ( "<STR_LIT>" ) <EOL> b . add_subject ( "<STR_LIT>" ) <EOL> assert b . subject == [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> b . validate ( ) <EOL> def test_abstract ( ) : <EOL> b = toy_bill ( ) <EOL> b . add_abstract ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> b . add_abstract ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> assert b . abstracts == [ { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:date>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:date>' : '<STR_LIT>' } ] <EOL> def test_add_documents ( ) : <EOL> b = toy_bill ( ) <EOL> b . add_document_link ( note = "<STR_LIT>" , date = "<STR_LIT>" , url = "<STR_LIT>" , <EOL> media_type = "<STR_LIT>" ) <EOL> b . add_document_link ( note = "<STR_LIT>" , date = "<STR_LIT>" , url = '<STR_LIT>' ) <EOL> assert len ( b . documents ) == <NUM_LIT:1> <EOL> b . add_document_link ( note = "<STR_LIT>" , date = "<STR_LIT>" , url = '<STR_LIT>' ) <EOL> assert len ( b . documents ) == <NUM_LIT:2> <EOL> b . validate ( ) <EOL> b . add_document_link ( note = "<STR_LIT>" , date = "<STR_LIT>" , url = None , media_type = '<STR_LIT:foo>' ) <EOL> with pytest . raises ( ValidationError ) : <EOL> b . validate ( ) <EOL> def test_versions ( ) : <EOL> b = toy_bill ( ) <EOL> b . add_version_link ( url = "<STR_LIT>" , note = "<STR_LIT>" , date = "<STR_LIT>" ) <EOL> b . add_version_link ( url = "<STR_LIT>" , note = "<STR_LIT>" , date = "<STR_LIT>" ) <EOL> b . validate ( ) <EOL> assert len ( b . versions ) == <NUM_LIT:1> <EOL> assert len ( b . versions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) == <NUM_LIT:2> <EOL> with pytest . raises ( ValueError ) : <EOL> b . add_version_link ( url = "<STR_LIT>" , note = "<STR_LIT>" , date = "<STR_LIT>" ) <EOL> b . add_version_link ( url = "<STR_LIT>" , note = "<STR_LIT>" , date = "<STR_LIT>" , <EOL> on_duplicate = '<STR_LIT:ignore>' ) <EOL> assert len ( b . versions ) == <NUM_LIT:1> <EOL> assert len ( b . versions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) == <NUM_LIT:2> <EOL> with pytest . raises ( ValueError ) : <EOL> b . add_version_link ( url = "<STR_LIT>" , note = "<STR_LIT>" , date = "<STR_LIT>" ) <EOL> assert len ( b . versions ) == <NUM_LIT:1> <EOL> assert len ( b . versions [ <NUM_LIT:0> ] [ '<STR_LIT>' ] ) == <NUM_LIT:2> <EOL> b . add_version_link ( url = "<STR_LIT>" , note = "<STR_LIT>" , date = "<STR_LIT>" ) <EOL> assert len ( b . versions ) == <NUM_LIT:2> <EOL> assert len ( b . versions [ <NUM_LIT:1> ] [ '<STR_LIT>' ] ) == <NUM_LIT:1> <EOL> b . validate ( ) <EOL> def test_str ( ) : <EOL> b = toy_bill ( ) <EOL> assert b . identifier in str ( b ) </s>
