github.com/apache/beam/sdks/v2@v2.48.2/python/apache_beam/io/gcp/bigquery_io_metadata_test.py (about) 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 18 """Tests for bigquery_io_metadata.""" 19 20 # pytype: skip-file 21 22 import logging 23 import unittest 24 25 from apache_beam.io.gcp import bigquery_io_metadata 26 27 28 class BigqueryIoMetadataTest(unittest.TestCase): 29 def test_is_valid_cloud_label_value(self): 30 # A dataflow job ID. 31 # Lowercase letters, numbers, underscores and hyphens are allowed. 32 test_str = '2020-06-29_15_26_09-12838749047888422749' 33 self.assertTrue(bigquery_io_metadata._is_valid_cloud_label_value(test_str)) 34 35 # At least one character. 36 test_str = '0' 37 self.assertTrue(bigquery_io_metadata._is_valid_cloud_label_value(test_str)) 38 39 # Up to 63 characters. 40 test_str = '0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij012' 41 self.assertTrue(bigquery_io_metadata._is_valid_cloud_label_value(test_str)) 42 43 # Lowercase letters allowed 44 test_str = 'abcdefghijklmnopqrstuvwxyz' 45 for test_char in test_str: 46 self.assertTrue( 47 bigquery_io_metadata._is_valid_cloud_label_value(test_char)) 48 49 # Empty strings not allowed. 50 test_str = '' 51 self.assertFalse(bigquery_io_metadata._is_valid_cloud_label_value(test_str)) 52 53 # 64 or more characters not allowed. 54 test_str = ( 55 '0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123') 56 self.assertFalse(bigquery_io_metadata._is_valid_cloud_label_value(test_str)) 57 58 # Uppercase letters not allowed 59 test_str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 60 for test_char in test_str: 61 self.assertFalse( 62 bigquery_io_metadata._is_valid_cloud_label_value(test_char)) 63 64 # Special characters besides hyphens are not allowed 65 test_str = '!@#$%^&*()+=[{]};:\'\"\\|,<.>?/`~' 66 for test_char in test_str: 67 self.assertFalse( 68 bigquery_io_metadata._is_valid_cloud_label_value(test_char)) 69 70 71 if __name__ == '__main__': 72 logging.getLogger().setLevel(logging.INFO) 73 unittest.main()