def test_jurisdiction_merge_related(): Division.objects.create(id='ocd-division/country:us', name='USA') # need to ensure legislative_sessions don't get deleted ji = JurisdictionImporter('jurisdiction-id') tj = FakeJurisdiction() ji.import_item(tj.as_dict()) assert LegislativeSession.objects.count() == 2 # disallow deletion of legislative sessions as it can remove bills tj.legislative_sessions.pop() ji.import_item(tj.as_dict()) # should still have two assert LegislativeSession.objects.count() == 2 # now will have three tj.legislative_sessions.append({ 'identifier': '2017', 'name': '2017 Session' }) ji.import_item(tj.as_dict()) assert LegislativeSession.objects.count() == 3 # and test that the non-identifier fields actually update tj.legislative_sessions.append({'identifier': '2016', 'name': 'updated'}) ji.import_item(tj.as_dict()) assert LegislativeSession.objects.count() == 3 assert LegislativeSession.objects.get(identifier='2016').name == 'updated'
def test_jurisdiction_merge_related(): Division.objects.create(id='ocd-division/country:us', name='USA') # need to ensure legislative_sessions don't get deleted ji = JurisdictionImporter('jurisdiction-id') tj = FakeJurisdiction() ji.import_item(tj.as_dict()) assert LegislativeSession.objects.count() == 2 # disallow deletion of legislative sessions as it can remove bills tj.legislative_sessions.pop() ji.import_item(tj.as_dict()) # should still have two assert LegislativeSession.objects.count() == 2 # now will have three tj.legislative_sessions.append({'identifier': '2017', 'name': '2017 Session'}) ji.import_item(tj.as_dict()) assert LegislativeSession.objects.count() == 3 # and test that the non-identifier fields actually update tj.legislative_sessions.append({'identifier': '2016', 'name': 'updated'}) ji.import_item(tj.as_dict()) assert LegislativeSession.objects.count() == 3 assert LegislativeSession.objects.get(identifier='2016').name == 'updated'
def test_jurisdiction_update(): tj = FakeJurisdiction() ji = JurisdictionImporter('jurisdiction-id') _, what = ji.import_item(tj.as_dict()) assert what == 'insert' _, what = ji.import_item(tj.as_dict()) assert what == 'noop' assert Jurisdiction.objects.count() == 1 tj.name = 'different name' obj, what = ji.import_item(tj.as_dict()) assert what == 'update' assert Jurisdiction.objects.count() == 1 assert obj.name == 'different name'
def test_jurisdiction_update(): tj = FakeJurisdiction() ji = JurisdictionImporter('jurisdiction-id') _, what = ji.import_item(tj.as_dict()) assert what == 'insert' _, what = ji.import_item(tj.as_dict()) assert what == 'noop' assert Jurisdiction.objects.count() == 1 tj.name = 'different name' obj, what = ji.import_item(tj.as_dict()) assert what == 'update' assert Jurisdiction.objects.count() == 1 assert Jurisdiction.objects.get().name == 'different name'
def test_jurisdiction_update(): Division.objects.create(id='ocd-division/country:us', name='USA') tj = FakeJurisdiction() ji = JurisdictionImporter('jurisdiction-id') _, what = ji.import_item(tj.as_dict()) assert what == 'insert' _, what = ji.import_item(tj.as_dict()) assert what == 'noop' assert Jurisdiction.objects.count() == 1 tj.name = 'different name' obj, what = ji.import_item(tj.as_dict()) assert what == 'update' assert Jurisdiction.objects.count() == 1 assert Jurisdiction.objects.get().name == 'different name'