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

New attribute literal label set as Optional #766

Merged
merged 3 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/csvcubed/readers/cubeconfig/v1/columnschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ def map_to_existing_qb_attribute(

@dataclass
class NewAttributeLiteral(SchemaBaseClass):
label: str
data_type: str
label: Optional[str] = None
description: Optional[str] = None
from_existing: Optional[str] = None
definition_uri: Optional[str] = None
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/readers/cubeconfig/v1_0/test_cube_from_config_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,21 @@ def test_attribute_new_literal():
_check_new_attribute_column(column, column_config, column_data, "New Attribute")


def test_attribute_new_literal_no_label():
"""
Ensure that a new literal attribute without a given label is created successfully,
with the column's title being used as the label instead.
"""
column_data = ["1", "2", "3", "4"]
column_config = vc.ATTRIBUTE_NEW_LITERAL_NO_LABEL
data = pd.Series(column_data, name="Attribute Heading")

(column, _) = map_column_to_qb_component(
"New Attribute", column_config, data, cube_config_minor_version=0
)
_check_new_attribute_column(column, column_config, column_data, "New Attribute")


@pytest.mark.vcr
def test_attribute_new_resource_with_values():
"""
Expand Down
15 changes: 14 additions & 1 deletion tests/unit/readers/cubeconfig/v1_0/virtualconfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class VirtualConfigurations:
}
"""
A configuration for defining a new attribute resource

{
"type": "attribute",
"label": "The New Attribute",
Expand All @@ -124,6 +124,19 @@ class VirtualConfigurations:
}
"""

ATTRIBUTE_NEW_LITERAL_NO_LABEL = {
"type": "attribute",
"data_type": "int",
}
"""
A configuration for defining a new attribute literal.

{
"type": "attribute",
"data_type": "int",
}
"""

ATTRIBUTE_NEW_RESOURCE_WITH_VALUES = {
"type": "attribute",
"label": "Attribute Label",
Expand Down