def test_only_import_certs_and_gfx(self): """Only import specified collections""" with mock.patch("kinto_client.cli_utils.Client"): with mock.patch("xml2kinto.__main__.sync_records") as mock_sync: main.main(["--certificates", "-G", "--no-schema"]) assert mock_sync.call_count == 2 # Only called for certificats and gfx mock_sync.assert_has_calls( [ mock.call( fields=main.CERT_ITEMS_FIELDS, filename=main.XML_FILE, xpath="certItems/*", kinto_client=mock.ANY, bucket=main.CERT_BUCKET, collection=main.CERT_COLLECTION, schema=None, ), mock.call( fields=main.GFX_ITEMS_FIELDS, filename=main.XML_FILE, xpath="gfxItems/*", kinto_client=mock.ANY, bucket=main.GFX_BUCKET, collection=main.GFX_COLLECTION, schema=None, ), ], any_order=True, )
def test_only_import_certs_and_gfx(self): """Only import specified collections""" with mock.patch('kinto_client.cli_utils.Client'): with mock.patch('xml2kinto.__main__.sync_records') as mock_sync: main.main(['--certificates', '-G', '--no-schema']) assert mock_sync.call_count == 2 # Only called for certificats and gfx mock_sync.assert_has_calls([ mock.call( fields=main.CERT_ITEMS_FIELDS, filename=main.XML_FILE, xpath='certItems/*', kinto_client=mock.ANY, bucket=main.CERT_BUCKET, collection=main.CERT_COLLECTION, schema=None), mock.call( fields=main.GFX_ITEMS_FIELDS, filename=main.XML_FILE, xpath='gfxItems/*', kinto_client=mock.ANY, bucket=main.GFX_BUCKET, collection=main.GFX_COLLECTION, schema=None)], any_order=True)
def test_no_collections_means_all_collections(self): """If no 'collection' is passed as parameter, import all of them.""" with mock.patch('kinto_client.cli_utils.Client') as MockedClient: with mock.patch('xml2kinto.__main__.sync_records') as mock_sync: main.main([]) # Nothing specific to be tested here, it's the default behavior self.assert_arguments(mock_sync, MockedClient)
def test_no_collections_means_all_collections(self): """If no 'collection' is passed as parameter, import all of them.""" with mock.patch("kinto_client.cli_utils.Client") as MockedClient: with mock.patch("xml2kinto.__main__.sync_records") as mock_sync: main.main([]) # Nothing specific to be tested here, it's the default behavior self.assert_arguments(mock_sync, MockedClient)
def test_can_define_the_plugins_bucket_and_collection(self): with mock.patch('kinto_client.cli_utils.Client') as MockedClient: with mock.patch('xml2kinto.__main__.sync_records') as mock_sync: main.main( ['--plugins-bucket', 'bucket', '--plugins-collection', 'collection']) self.assert_arguments(mock_sync, MockedClient, plugins_bucket='bucket', plugins_collection='collection')
def test_main_default(self): # let's check that main() parsing uses our defaults with mock.patch('xml2kinto.__main__.synchronize') as sync: main([]) options = sync.call_args[1]['kinto_options'] self.assertEqual(options['server'], kinto_server) self.assertEqual(options['auth'], auth) xml_options = sync.call_args[1]['xml_options'] self.assertEqual(xml_options['filename'], xml_file)
def test_only_import_certificats(self): """If only one collection is specified, only import it.""" with mock.patch('kinto_client.cli_utils.Client'): with mock.patch('xml2kinto.__main__.sync_records') as mock_sync: main.main(['--certificates', '--no-schema']) mock_sync.assert_called_once_with(fields=main.CERT_ITEMS_FIELDS, filename=main.XML_FILE, xpath='certItems/*', kinto_client=mock.ANY, bucket=main.CERT_BUCKET, collection=main.CERT_COLLECTION, schema=None)
def test_only_import_certificats(self): """If only one collection is specified, only import it.""" with mock.patch("kinto_client.cli_utils.Client"): with mock.patch("xml2kinto.__main__.sync_records") as mock_sync: main.main(["--certificates", "--no-schema"]) mock_sync.assert_called_once_with( fields=main.CERT_ITEMS_FIELDS, filename=main.XML_FILE, xpath="certItems/*", kinto_client=mock.ANY, bucket=main.CERT_BUCKET, collection=main.CERT_COLLECTION, schema=None, )
def test_can_define_the_auth_credentials(self): with mock.patch('kinto_client.cli_utils.Client') as MockedClient: with mock.patch('xml2kinto.__main__.sync_records') as mock_sync: main.main(['--auth', 'user:pass']) self.assert_arguments(mock_sync, MockedClient, auth=('user', 'pass'))
def test_can_define_the_xml_file(self): with mock.patch('kinto_client.cli_utils.Client') as MockedClient: with mock.patch('xml2kinto.__main__.sync_records') as mock_sync: main.main(['-x', '/tmp/toto.xml']) self.assert_arguments(mock_sync, MockedClient, filename='/tmp/toto.xml')
def test_main_custom_server(self): with mock.patch('kinto_client.cli_utils.Client') as MockedClient: with mock.patch('xml2kinto.__main__.sync_records') as mock_sync: main.main(['-s', 'http://yeah']) self.assert_arguments(mock_sync, MockedClient, kinto_server='http://yeah')
def test_no_schema_option_does_add_the_schema(self): with mock.patch('kinto_client.cli_utils.Client') as MockedClient: with mock.patch('xml2kinto.__main__.sync_records') as mock_sync: main.main(['--no-schema']) self.assert_arguments(mock_sync, MockedClient, no_schema=True)
def test_no_schema_option_does_add_the_schema(self): with mock.patch("kinto_client.cli_utils.Client") as MockedClient: with mock.patch("xml2kinto.__main__.sync_records") as mock_sync: main.main(["--no-schema"]) self.assert_arguments(mock_sync, MockedClient, no_schema=True)
def test_can_define_the_auth_credentials(self): with mock.patch("kinto_client.cli_utils.Client") as MockedClient: with mock.patch("xml2kinto.__main__.sync_records") as mock_sync: main.main(["--auth", "user:pass"]) self.assert_arguments(mock_sync, MockedClient, auth=("user", "pass"))
def test_can_define_the_plugins_bucket_and_collection(self): with mock.patch("kinto_client.cli_utils.Client") as MockedClient: with mock.patch("xml2kinto.__main__.sync_records") as mock_sync: main.main(["--plugins-bucket", "bucket", "--plugins-collection", "collection"]) self.assert_arguments(mock_sync, MockedClient, plugins_bucket="bucket", plugins_collection="collection")
def test_can_define_the_xml_file(self): with mock.patch("kinto_client.cli_utils.Client") as MockedClient: with mock.patch("xml2kinto.__main__.sync_records") as mock_sync: main.main(["-x", "/tmp/toto.xml"]) self.assert_arguments(mock_sync, MockedClient, filename="/tmp/toto.xml")
def test_main_custom_server(self): with mock.patch("kinto_client.cli_utils.Client") as MockedClient: with mock.patch("xml2kinto.__main__.sync_records") as mock_sync: main.main(["-s", "http://yeah"]) self.assert_arguments(mock_sync, MockedClient, kinto_server="http://yeah")
def test_main_default(self): # let's check that main() parsing uses our defaults with mock.patch('kinto_client.cli_utils.Client') as MockedClient: with mock.patch('xml2kinto.__main__.sync_records') as mock_sync: main.main([]) self.assert_arguments(mock_sync, MockedClient)
def test_main_custom_server(self): with mock.patch('xml2kinto.__main__.synchronize') as sync: main(['-s', 'http://yeah']) options = sync.call_args[1]['kinto_options'] self.assertEqual(options['server'], 'http://yeah')
def test_main_default(self): # let's check that main() parsing uses our defaults with mock.patch("kinto_client.cli_utils.Client") as MockedClient: with mock.patch("xml2kinto.__main__.sync_records") as mock_sync: main.main([]) self.assert_arguments(mock_sync, MockedClient)