Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add column type targets to API #366

Merged
merged 26 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
26a5007
modify type getter to support displaying DB names
mathemancer Jul 8, 2021
6be9ced
fix unfriendly type names bug, add test for it
mathemancer Jul 8, 2021
b60050d
pass DB types to API and use for column creation
mathemancer Jul 8, 2021
929d514
refactor, add function to get valid target_type for given type
mathemancer Jul 12, 2021
db30fb5
remove TEXT db type for now, improve valid target type map
mathemancer Jul 12, 2021
944922f
add method to MathesarColumn to get target_types for casting
mathemancer Jul 12, 2021
29fc95c
add method for getting valid target types to MathesarColumn
mathemancer Jul 14, 2021
4b69434
modify cast map getter to match with MathesarColumn
mathemancer Jul 14, 2021
e026789
add function to get table with MathesarColumns
mathemancer Jul 14, 2021
e6b3d3e
add mathesar_columns property to Table model
mathemancer Jul 14, 2021
593bdb5
use new enriched columns to return target_types in API
mathemancer Jul 14, 2021
58949cb
fix failing API tests
mathemancer Jul 14, 2021
3bf3638
remove unneeded print statement
mathemancer Jul 14, 2021
8cff309
remove unused engine init arg
mathemancer Jul 14, 2021
69e8021
fix flake8 errors
mathemancer Jul 14, 2021
51e18c2
Merge branch 'master' into column_type_targets
mathemancer Jul 14, 2021
e528311
move new enriched column behavior to sa_columns
mathemancer Jul 15, 2021
2ccdd34
add tests for new MathesarColumn methods
mathemancer Jul 18, 2021
bb6ca09
add test for getting cast map
mathemancer Jul 18, 2021
a59aad3
Merge branch 'master' into column_type_targets
mathemancer Jul 19, 2021
4093f7b
use column index getter in MathesarColumn class
mathemancer Jul 20, 2021
e9c510d
fix column API tests with new column index field
mathemancer Jul 20, 2021
ce20d87
Merge branch 'master' into column_type_targets
mathemancer Jul 20, 2021
3daf865
add tests for column index property
mathemancer Jul 20, 2021
824219d
Merge branch 'master' into column_type_targets
mathemancer Jul 20, 2021
6807e26
change field column_index to index in columns endpoint
mathemancer Jul 20, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix failing API tests
  • Loading branch information
mathemancer committed Jul 14, 2021
commit 58949cb1d4048dbcea71ee1919934d366c8b4691
10 changes: 6 additions & 4 deletions db/columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@ def valid_target_types(self):
"""
if self.engine is not None and not self.is_default:
db_type = self.type.compile(dialect=self.engine.dialect)
return list(
set(
alteration.get_full_cast_map(self.engine).get(db_type)
valid_target_types = sorted(
list(
set(
alteration.get_full_cast_map(self.engine).get(db_type, [])
)
)
)

return valid_target_types if valid_target_types else None


def get_default_mathesar_column_list():
Expand Down
60 changes: 54 additions & 6 deletions mathesar/tests/views/api/test_column_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,67 @@ def test_column_list(column_test_table, client):
response_data = response.json()
assert response_data['count'] == len(column_test_table.sa_columns)
expect_results = [
{'name': 'mycolumn0', 'type': 'INTEGER', 'nullable': False, 'primary_key': True},
{'name': 'mycolumn1', 'type': 'INTEGER', 'nullable': False, 'primary_key': False},
{'name': 'mycolumn2', 'type': 'INTEGER', 'nullable': True, 'primary_key': False},
{'name': 'mycolumn3', 'type': 'VARCHAR', 'nullable': True, 'primary_key': False}
{
'name': 'mycolumn0',
'type': 'INTEGER',
'nullable': False,
'primary_key': True,
'valid_target_types': None,
},
{
'name': 'mycolumn1',
'type': 'INTEGER',
'nullable': False,
'primary_key': False,
'valid_target_types': None,
},
{
'name': 'mycolumn2',
'type': 'INTEGER',
'nullable': True,
'primary_key': False,
'valid_target_types': None,
},
{
'name': 'mycolumn3',
'type': 'VARCHAR',
'nullable': True,
'primary_key': False,
'valid_target_types': [
'BOOLEAN',
'INTERVAL',
'NUMERIC',
'VARCHAR',
'mathesar_types.email',
],
}
]
assert response_data['results'] == expect_results


@pytest.mark.parametrize(
"index,expect_data",
[
(0, {'name': 'mycolumn0', 'type': 'INTEGER', 'nullable': False, 'primary_key': True}),
(2, {'name': 'mycolumn2', 'type': 'INTEGER', 'nullable': True, 'primary_key': False}),
(
0,
{
'name': 'mycolumn0',
'type': 'INTEGER',
'nullable': False,
'primary_key': True,
'valid_target_types': None
},
),
(
2,
{
'name': 'mycolumn2',
'type': 'INTEGER',
'nullable': True,
'primary_key': False,
'valid_target_types': None
},
),
]
)
def test_column_retrieve(index, expect_data, column_test_table, client):
Expand Down