def test_synchronize_delete_removed_records(self): with mock.patch('xml2kinto.synchronize.KintoRecords') as KintoRecords: KintoRecords.return_value.records = [deleted_record] KintoRecords.return_value.find.return_value = None here = os.path.dirname(__file__) test_file = os.path.join(here, 'test_synchronize.xml') synchronize(FIELDS, xml_options={'filename': test_file}, kinto_options=mock.MagicMock()) assert KintoRecords.return_value.delete.call_count == 1
def test_synchronize_raises_SynchronizationError_if_create_fails(self): error = KintoException() error.response = mock.MagicMock(content='foobar') with mock.patch('xml2kinto.synchronize.KintoRecords') as KintoRecords: KintoRecords.return_value.records = [] KintoRecords.return_value.find.return_value = None KintoRecords.return_value.create.side_effect = error here = os.path.dirname(__file__) test_file = os.path.join(here, 'test_synchronize.xml') with pytest.raises(SynchronizationError): synchronize(FIELDS, xml_options={'filename': test_file}, kinto_options=mock.MagicMock())
def main(args=None): parser = argparse.ArgumentParser(description="Syncs a Kinto DB.") parser.add_argument("-s", "--kinto-server", help="Kinto Server", type=str, default=kinto_server) parser.add_argument("-x", "--xml-file", help="XML Source file", type=str, default=xml_file) parser.add_argument("-a", "--auth", help="BasicAuth user:pass", type=str, default=":".join(auth)) args = parser.parse_args(args=args) synchronize( fields, xml_options={"filename": args.xml_file}, kinto_options={ "server": args.kinto_server, "bucket_name": bucket_name, "collection_name": collection_name, "auth": tuple(args.auth.split(":")), "permissions": collection_permissions, }, )