|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +# contributor license agreements. See the NOTICE file distributed with |
| 4 | +# this work for additional information regarding copyright ownership. |
| 5 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +# (the "License"); you may not use this file except in compliance with |
| 7 | +# the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | +# |
| 17 | +import unittest |
| 18 | + |
| 19 | +from parameterized import parameterized |
| 20 | + |
| 21 | +try: |
| 22 | + from apache_beam.transforms.enrichment_handlers.cloudsql import CloudSQLEnrichmentHandler, DatabaseTypeAdapter |
| 23 | + from apache_beam.transforms.enrichment_handlers.cloudsql_it_test import _row_key_fn |
| 24 | +except ImportError: |
| 25 | + raise unittest.SkipTest('Cloud SQL test dependencies are not installed.') |
| 26 | + |
| 27 | + |
| 28 | +class TestCloudSQLEnrichmentHandler(unittest.TestCase): |
| 29 | + @parameterized.expand([('product_id', _row_key_fn), ('', None)]) |
| 30 | + def test_cloud_sql_enrichment_invalid_args(self, row_key, row_key_fn): |
| 31 | + with self.assertRaises(ValueError): |
| 32 | + _ = CloudSQLEnrichmentHandler( |
| 33 | + project_id='apache-beam-testing', |
| 34 | + region_id='us-east1', |
| 35 | + instance_id='beam-test', |
| 36 | + table_id='cloudsql-enrichment-test', |
| 37 | + database_type_adapter=DatabaseTypeAdapter.POSTGRESQL, |
| 38 | + database_name='postgres', |
| 39 | + database_user='postgres', |
| 40 | + database_password='', |
| 41 | + row_key=row_key, |
| 42 | + row_key_fn=row_key_fn) |
| 43 | + |
| 44 | + |
| 45 | +if __name__ == '__main__': |
| 46 | + unittest.main() |
0 commit comments