Exemplo n.º 1
0
    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,
        )
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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')
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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,
        )
Exemplo n.º 9
0
 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'))
Exemplo n.º 10
0
 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')
Exemplo n.º 11
0
 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')
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
 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)
Exemplo n.º 14
0
 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"))
Exemplo n.º 15
0
 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")
Exemplo n.º 16
0
 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")
Exemplo n.º 17
0
 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")
Exemplo n.º 18
0
 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)
Exemplo n.º 19
0
 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')
Exemplo n.º 20
0
 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)