def test_table_desc_match_rule_table_only(self) -> None:
        # Mock match rule, table name and schema
        test_match_rule = MatchRuleObject(table_name_regex=r"^noedit_([a-zA-Z_0-9]+)")

        # assert result for given table name and match rule
        self.assertEqual(_parse_editable_rule(test_match_rule, 'schema', 'noedit_test_table'), False)
        self.assertEqual(_parse_editable_rule(test_match_rule, 'schema', 'editable_test_table'), True)
    def test_table_desc_match_rule_schema_only(self) -> None:
        # Mock match rule, table name and schema
        test_match_rule = MatchRuleObject(schema_regex=r"^(schema1)")

        # assert result for given schema and match rule
        self.assertEqual(_parse_editable_rule(test_match_rule, 'schema1', 'test_table'), False)
        self.assertEqual(_parse_editable_rule(test_match_rule, 'schema2', 'test_table'), True)
 def test_table_desc_match_rule_schema_and_table(self) -> None:
     # Mock match rule, table name and schema
     test_match_rule = MatchRuleObject(schema_regex=r"^(schema1|schema2)",
                                       table_name_regex=r"^other_([a-zA-Z_0-9]+)")
     # assert result for given schema, table name and match rule
     self.assertEqual(_parse_editable_rule(test_match_rule, 'schema1', 'other_test_table'), False)
     self.assertEqual(_parse_editable_rule(test_match_rule, 'schema1', 'test_table'), True)
     self.assertEqual(_parse_editable_rule(test_match_rule, 'schema3', 'other_test_table'), True)
     self.assertEqual(_parse_editable_rule(test_match_rule, 'schema3', 'test_table'), True)
Esempio n. 4
0
    def test_schema_match_rule(self) -> None:
        mockConfig = {
            'UNEDITABLE_SCHEMAS': [''],
            'UNEDITABLE_TABLE_DESCRIPTION_MATCH_RULES': [
                MatchRuleObject(schema_regex=r"^(uneditable).*"),
            ],
        }

        self.assertTrue(
            is_table_editable('not_uneditable_schema', 'anytable', mockConfig))
        self.assertFalse(
            is_table_editable('uneditable_schema', 'anytable', mockConfig))
Esempio n. 5
0
    def test_schema_table_match_rule(self) -> None:
        mockConfig = {
            'UNEDITABLE_SCHEMAS': [''],
            'UNEDITABLE_TABLE_DESCRIPTION_MATCH_RULES': [
                MatchRuleObject(schema_regex=r"^first.*",
                                table_name_regex=r".*bad.*")
            ],
        }

        self.assertFalse(is_table_editable('first', 'bad', mockConfig))
        self.assertFalse(is_table_editable('first', 'also_bad', mockConfig))
        self.assertTrue(is_table_editable('first', 'good', mockConfig))
        self.assertTrue(is_table_editable('not_first', 'bad', mockConfig))
        self.assertTrue(is_table_editable('second', 'bad', mockConfig))
Esempio n. 6
0
    def test_put_column_description_denied(self) -> None:
        """
        Test put_column_description on an unwritable table.
        :return:
        """
        url = local_app.config['METADATASERVICE_BASE'] + TABLE_ENDPOINT + \
            '/db://cluster.schema/an_uneditable_table/column/col/description'
        responses.add(responses.PUT, url, json={}, status=HTTPStatus.OK)

        rule = MatchRuleObject(table_name_regex=r".*uneditable_table.*")
        with patch.dict(local_app.config,
                        {'UNEDITABLE_TABLE_DESCRIPTION_MATCH_RULES': [rule]}):
            with local_app.test_client() as test:
                response = test.put(
                    '/api/metadata/v0/put_column_description',
                    json={
                        'key': 'db://cluster.schema/an_uneditable_table',
                        'column_name': 'col',
                        'description': 'test',
                        'source': 'source'
                    })
                self.assertEqual(response.status_code, HTTPStatus.FORBIDDEN)