Skip to content

Commit

Permalink
Add Dataset integration tests - Table Columns (#1548)
Browse files Browse the repository at this point in the history
### Feature or Bugfix
- Feature: Testing

### Detail
Follow-up of #1391 

- Implement Table Column tests

### Relates
- #1358
- #1391 

### Security
Please answer the questions below briefly where applicable, or write
`N/A`. Based on
[OWASP 10](https://owasp.org/Top10/en/).

- Does this PR introduce or modify any input fields or queries - this
includes
fetching data from storage outside the application (e.g. a database, an
S3 bucket)?
  - Is the input sanitized?
- What precautions are you taking before deserializing the data you
consume?
  - Is injection prevented by parametrizing queries?
  - Have you ensured no `eval` or similar functions are used?
- Does this PR introduce any functionality or component that requires
authorization?
- How have you ensured it respects the existing AuthN/AuthZ mechanisms?
  - Are you logging failed auth attempts?
- Are you using or adding any cryptographic features?
  - Do you use a standard proven implementations?
  - Are the used keys controlled by the customer? Where are they stored?
- Are you introducing any new policies/roles/users?
  - Have you used the least-privilege principle? How?


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

---------

Co-authored-by: Noah Paige <noahpaig@amazon.com>
  • Loading branch information
dlpzx and noah-paige committed Sep 24, 2024
1 parent b9915ef commit 59f0b26
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 19 deletions.
2 changes: 1 addition & 1 deletion tests_new/integration_tests/modules/s3_datasets/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def update_dataset_table_column(client, columnUri, input):
return response.data.updateDatasetTableColumn


def list_dataset_table_columns(client, tableUri, term):
def list_dataset_table_columns(client, tableUri, term=''):
query = {
'operationName': 'ListDatasetTableColumns',
'variables': {'tableUri': tableUri, 'filter': {'term': term}},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import pytest
from assertpy import assert_that

from integration_tests.modules.s3_datasets.queries import (
Expand All @@ -7,35 +8,80 @@
list_dataset_table_columns,
)
from integration_tests.errors import GqlError
from integration_tests.modules.s3_datasets.conftest import (
TABLES_FIXTURES_PARAMS,
TABLES_CONFIDENTIALITY_FIXTURES_PARAMS,
)

log = logging.getLogger(__name__)


def test_sync_dataset_table_columns():
# TODO
pass
@pytest.mark.parametrize(*TABLES_FIXTURES_PARAMS)
def test_sync_dataset_table_columns(client1, tables_fixture_name, request):
tables = request.getfixturevalue(tables_fixture_name)
response = sync_dataset_table_columns(client1, tables[0].tableUri)
assert_that(response.count).is_equal_to(3)
assert_that(response.nodes[0].name).is_equal_to('column1')
assert_that(response.nodes[0].typeName).is_equal_to('int')


def test_sync_dataset_table_columns_unauthorized():
# TODO
pass
@pytest.mark.parametrize(
'dataset_fixture_name,tables_fixture_name',
[('session_s3_dataset1', 'session_s3_dataset1_tables')],
)
def test_sync_dataset_table_columns_unauthorized(client2, dataset_fixture_name, tables_fixture_name, request):
dataset = request.getfixturevalue(dataset_fixture_name)
tables = request.getfixturevalue(tables_fixture_name)
table_uri = tables[0].tableUri
assert_that(sync_dataset_table_columns).raises(GqlError).when_called_with(client2, table_uri).contains(
'UnauthorizedOperation', 'UPDATE_DATASET_TABLE', dataset.datasetUri
)


def test_update_dataset_table_column():
# TODO
pass
@pytest.mark.parametrize(*TABLES_FIXTURES_PARAMS)
def test_list_dataset_table_columns(client1, tables_fixture_name, request):
tables = request.getfixturevalue(tables_fixture_name)
table_uri = tables[0].tableUri
response = list_dataset_table_columns(client1, table_uri)
assert_that(response.count).is_equal_to(3)
assert_that(response.nodes[0].name).is_equal_to('column1')
assert_that(response.nodes[0].columnUri).is_not_none()


def test_update_dataset_table_column_unauthorized():
# TODO
pass
@pytest.mark.parametrize(*TABLES_CONFIDENTIALITY_FIXTURES_PARAMS)
def test_list_dataset_table_columns_by_confidentiality(client2, tables_fixture_name, confidentiality, request):
tables = request.getfixturevalue(tables_fixture_name)
table_uri = tables[0].tableUri
if confidentiality in ['Unclassified']:
response = list_dataset_table_columns(client2, table_uri)
assert_that(response.count).is_equal_to(3)
else:
assert_that(list_dataset_table_columns).raises(GqlError).when_called_with(client2, table_uri).contains(
'UnauthorizedOperation', 'LIST_DATASET_TABLE_COLUMNS'
)


def test_list_dataset_table_columns():
# TODO
pass
@pytest.mark.parametrize(*TABLES_FIXTURES_PARAMS)
def test_update_dataset_table_column(client1, tables_fixture_name, request, session_id):
tables = request.getfixturevalue(tables_fixture_name)
table_uri = tables[0].tableUri
columns = list_dataset_table_columns(client1, table_uri)
column_uri = columns.nodes[0].columnUri
new_desc = f'{session_id} new updated description'
response = update_dataset_table_column(client1, column_uri, {'description': new_desc})
assert_that(response.description).is_equal_to(new_desc)


def test_list_dataset_table_columns_unauthorized():
# TODO
pass
@pytest.mark.parametrize(
'dataset_fixture_name,tables_fixture_name',
[('session_s3_dataset1', 'session_s3_dataset1_tables')],
)
def test_update_dataset_table_column_unauthorized(client1, client2, dataset_fixture_name, tables_fixture_name, request):
dataset = request.getfixturevalue(dataset_fixture_name)
tables = request.getfixturevalue(tables_fixture_name)
table_uri = tables[0].tableUri
columns = list_dataset_table_columns(client1, table_uri)
column_uri = columns.nodes[0].columnUri
assert_that(update_dataset_table_column).raises(GqlError).when_called_with(
client2, column_uri, {'description': 'badNewDescription'}
).contains('UnauthorizedOperation', 'UPDATE_DATASET_TABLE', dataset.datasetUri)

0 comments on commit 59f0b26

Please sign in to comment.