Exemplo n.º 1
0
    def test_schema(self) -> None:
        mockConfig = {
            'UNEDITABLE_SCHEMAS': ['uneditable_schema'],
            'UNEDITABLE_TABLE_DESCRIPTION_MATCH_RULES': [],
        }

        self.assertTrue(
            is_table_editable('different_schema', 'anytable', mockConfig))
        self.assertFalse(
            is_table_editable('uneditable_schema', 'anytable', mockConfig))
Exemplo n.º 2
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))
Exemplo n.º 3
0
    def test_no_schemas_editable(self) -> None:
        mockConfig: Dict = {
            'ALL_UNEDITABLE_SCHEMAS': True,
            'UNEDITABLE_SCHEMAS': [],
            'UNEDITABLE_TABLE_DESCRIPTION_MATCH_RULES': [],
        }

        self.assertFalse(is_table_editable('anyschema', 'anytable',
                                           mockConfig))
        self.assertFalse(
            is_table_editable('anotherschema', 'anothertable', mockConfig))
        self.assertFalse(
            is_table_editable('athirdschema', 'athirdtable', mockConfig))
Exemplo n.º 4
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))
Exemplo n.º 5
0
    def test_empty_allowed(self) -> None:
        mockConfig = {
            'UNEDITABLE_SCHEMAS': [],
            'UNEDITABLE_TABLE_DESCRIPTION_MATCH_RULES': [],
        }

        self.assertTrue(is_table_editable('anyschema', 'anytable', mockConfig))
Exemplo n.º 6
0
def put_table_description() -> Response:

    @action_logging
    def _log_put_table_description(*, table_key: str, description: str, source: str) -> None:
        pass  # pragma: no cover

    try:
        args = request.get_json()
        table_endpoint = _get_table_endpoint()

        table_key = get_query_param(args, 'key')

        description = get_query_param(args, 'description')
        src = get_query_param(args, 'source')

        table_uri = TableUri.from_uri(table_key)
        if not is_table_editable(table_uri.schema, table_uri.table):
            return make_response('', HTTPStatus.FORBIDDEN)

        url = '{0}/{1}/description'.format(table_endpoint, table_key)
        _log_put_table_description(table_key=table_key, description=description, source=src)

        response = request_metadata(url=url, method='PUT', data=json.dumps({'description': description}))
        status_code = response.status_code

        if status_code == HTTPStatus.OK:
            message = 'Success'
        else:
            message = 'Update table description failed'

        payload = jsonify({'msg': message})
        return make_response(payload, status_code)
    except Exception as e:
        payload = jsonify({'msg': 'Encountered exception: ' + str(e)})
        return make_response(payload, HTTPStatus.INTERNAL_SERVER_ERROR)