def test_sync_existing_legislator_data_skips_old_data(): instance = factories.LegislatorFactory.build() original_id = instance.id updated_at = utils.format_datetime(instance.openstates_updated_at - ONE_DAY) api_data = data.get_sample_legislator_detail(updated_at=updated_at) info = services.sync_existing_legislator_data(instance, api_data, commit=False) assert info.action == services.Action.SKIPPED assert info.instance.id == original_id
def test_sync_existing_legislator_data_updates_from_recently_updated_data(): instance = factories.LegislatorFactory.build() original_id = instance.id updated_at = utils.format_datetime(instance.openstates_updated_at + ONE_DAY) api_data = data.get_sample_legislator_detail(updated_at=updated_at) info = services.sync_existing_legislator_data(instance, api_data, commit=False) assert info.action == services.Action.UPDATED assert_legislator_fields_match_data(info.instance, api_data) assert info.instance.id == original_id
def test_sync_existing_bill_skips_older(self): instance = BillFactory.create() older_data = { 'id': instance.openstates_bill_id, 'updated_at': utils.format_datetime(instance.openstates_updated_at - ONE_DAY), } with mock.patch.object( utils, 'deserialize_openstates_bill') as mock_deserialize: info = services.sync_bill_data(older_data) mock_deserialize.assert_not_called() assert info.action == services.Action.SKIPPED
def test_sync_existing_bill_updates_given_newer_data(self): instance = BillFactory.create() newer_data = { 'id': instance.openstates_bill_id, 'updated_at': utils.format_datetime(instance.openstates_updated_at + ONE_DAY), } with mock.patch.object( utils, 'deserialize_openstates_bill') as mock_deserialize: info = services.sync_bill_data(newer_data) mock_deserialize.assert_called_once_with(newer_data, instance=instance) assert info.action == services.Action.UPDATED