<s> import pytest <EOL> from pupa . scrape import Jurisdiction as JurisdictionBase <EOL> from pupa . importers import JurisdictionImporter <EOL> from opencivicdata . models import Jurisdiction , LegislativeSession <EOL> class FakeJurisdiction ( JurisdictionBase ) : <EOL> division_id = '<STR_LIT>' <EOL> name = '<STR_LIT:test>' <EOL> url = '<STR_LIT>' <EOL> classification = '<STR_LIT>' <EOL> legislative_sessions = [ <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' } , <EOL> ] <EOL> @ pytest . mark . django_db <EOL> def test_jurisdiction_import ( ) : <EOL> tj = FakeJurisdiction ( ) <EOL> juris_dict = tj . as_dict ( ) <EOL> JurisdictionImporter ( '<STR_LIT>' ) . import_data ( [ juris_dict ] ) <EOL> dbj = Jurisdiction . objects . get ( ) <EOL> assert dbj . id == tj . jurisdiction_id <EOL> assert dbj . division_id == tj . division_id <EOL> assert dbj . name == tj . name <EOL> assert dbj . url == tj . url <EOL> @ pytest . mark . django_db <EOL> def test_jurisdiction_update ( ) : <EOL> tj = FakeJurisdiction ( ) <EOL> ji = JurisdictionImporter ( '<STR_LIT>' ) <EOL> _ , what = ji . import_item ( tj . as_dict ( ) ) <EOL> assert what == '<STR_LIT>' <EOL> _ , what = ji . import_item ( tj . as_dict ( ) ) <EOL> assert what == '<STR_LIT>' <EOL> assert Jurisdiction . objects . count ( ) == <NUM_LIT:1> <EOL> tj . name = '<STR_LIT>' <EOL> obj , what = ji . import_item ( tj . as_dict ( ) ) <EOL> assert what == '<STR_LIT>' <EOL> assert Jurisdiction . objects . count ( ) == <NUM_LIT:1> <EOL> assert Jurisdiction . objects . get ( ) . name == '<STR_LIT>' <EOL> @ pytest . mark . django_db <EOL> def test_jurisdiction_merge_related ( ) : <EOL> ji = JurisdictionImporter ( '<STR_LIT>' ) <EOL> tj = FakeJurisdiction ( ) <EOL> ji . import_item ( tj . as_dict ( ) ) <EOL> assert LegislativeSession . objects . count ( ) == <NUM_LIT:2> <EOL> tj . legislative_sessions . pop ( ) <EOL> ji . import_item ( tj . as_dict ( ) ) <EOL> assert LegislativeSession . objects . count ( ) == <NUM_LIT:2> <EOL> tj . legislative_sessions . append ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> ji . import_item ( tj . as_dict ( ) ) <EOL> assert LegislativeSession . objects . count ( ) == <NUM_LIT:3> <EOL> tj . legislative_sessions . append ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> ji . import_item ( tj . as_dict ( ) ) <EOL> assert LegislativeSession . objects . count ( ) == <NUM_LIT:3> <EOL> assert LegislativeSession . objects . get ( identifier = '<STR_LIT>' ) . name == '<STR_LIT>' </s>
