Пример #1
0
 def test_export_objectstore_exception(self, mock_distribute,
                                       mock_export_to_file):
     mock_export_to_file.side_effect = lambda *args, **kwargs: True
     mock_distribute.side_effect = GOBException
     result = _export_collection("host", "meetbouten", "meetbouten", None,
                                 "Objectstore")
     self.assertEqual(result, False)
Пример #2
0
 def test_export_objectstore_all_products(self, mock_export_to_file,
                                          mock_distribute):
     mock_export_to_file.side_effect = lambda *args, **kwargs: True
     # All products (7 files) should be exported
     result = _export_collection("host", "gebieden", "stadsdelen", None,
                                 "Objectstore")
     self.assertEqual(result, None)
     mock_distribute.assert_called()
     self.assertEqual(mock_distribute.call_count, 7)
Пример #3
0
 def test_export_objectstore_one_product(self, mock_clean,
                                         mock_export_to_file,
                                         mock_distribute):
     mock_export_to_file.side_effect = lambda *args, **kwargs: True
     # Only csv_actueel should be exported
     result = _export_collection("host", "gebieden", "stadsdelen",
                                 "not exists", "Objectstore")
     self.assertEqual(result, None)
     mock_distribute.assert_not_called()
     mock_clean.assert_not_called()
Пример #4
0
 def test_export_exception(self, mock_export_to_file):
     mock_export_to_file.side_effect = lambda *args: fail("Export failed")
     result = _export_collection("host", "meetbouten", "meetbouten", None,
                                 "Objectstore")
     self.assertEqual(result, None)
     self.assertEqual(mock_export_to_file.call_count, 3)
Пример #5
0
 def test_export_file(self, mock_get_datastore_config):
     result = _export_collection("host", "meetbouten", "meetbouten", None,
                                 "File")
     self.assertEqual(result, None)
     mock_get_datastore_config.assert_not_called()
Пример #6
0
    def test_export_collection_append(self, mock_append, mock_clean,
                                      mock_export_to_file, mock_distribute):
        products = {
            'prod1': {
                'api_type': 'graphql_streaming',
                'exporter': csv_exporter,
                'query': 'q1',
                'filename': 'the/filename.csv',
                'mime_type': 'mime/type'
            },
            'prod2': {
                'api_type': 'graphql_streaming',
                'exporter': csv_exporter,
                'query': 'q1',
                'append': True,
                'filename': 'the/filename.csv',
                'mime_type': 'mime/type'
            }
        }

        config_object = type('Config', (), {'products': products})
        config = {'cat': {'coll': config_object}}
        mock_export_to_file.side_effect = lambda *args, **kwargs: True

        with patch("gobexport.export.CONFIG_MAPPING", config):
            result = _export_collection("host", "cat", "coll", None, "File")

        mock_export_to_file.assert_has_calls([
            call('host',
                 products['prod1'],
                 'the/filename.csv',
                 'cat',
                 'coll',
                 buffer_items=True),
            call('host',
                 products['prod2'],
                 '/tmpfile/the/filename.csv.to_append',
                 'cat',
                 'coll',
                 buffer_items=True)
        ])

        mock_append.assert_called_with('/tmpfile/the/filename.csv.to_append',
                                       'the/filename.csv')

        # Objectstore, uses two tmp files
        mock_export_to_file.reset_mock()
        with patch("gobexport.export.CONFIG_MAPPING", config):
            result = _export_collection("host", "cat", "coll", None,
                                        "Objectstore")

        mock_export_to_file.assert_has_calls([
            call('host',
                 products['prod1'],
                 '/tmpfile/the/filename.csv',
                 'cat',
                 'coll',
                 buffer_items=True),
            call('host',
                 products['prod2'],
                 '/tmpfile/the/filename.csv.to_append',
                 'cat',
                 'coll',
                 buffer_items=True)
        ])

        mock_append.assert_called_with('/tmpfile/the/filename.csv.to_append',
                                       '/tmpfile/the/filename.csv')