-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for active_by_default column in entity_class table.
This commit adds support for the new active_by_default column in entity_class tables. It is now possible to change the value of the flag while creating or editing entity classes in Database editor. Re spine-tools/Spine-Database-API#316
- Loading branch information
Showing
17 changed files
with
252 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.spinetoolbox/local/ | ||
.spinetoolbox/items/ | ||
*.bak* |
79 changes: 79 additions & 0 deletions
79
execution_tests/active_by_default/.spinetoolbox/project.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
"project": { | ||
"version": 12, | ||
"description": "", | ||
"settings": { | ||
"enable_execute_all": true | ||
}, | ||
"specifications": { | ||
"Exporter": [ | ||
{ | ||
"type": "path", | ||
"relative": true, | ||
"path": ".spinetoolbox/specifications/Exporter/export_entities.json" | ||
} | ||
] | ||
}, | ||
"connections": [ | ||
{ | ||
"name": "from Test data to Exporter", | ||
"from": [ | ||
"Test data", | ||
"right" | ||
], | ||
"to": [ | ||
"Exporter", | ||
"left" | ||
], | ||
"options": { | ||
"require_scenario_filter": true | ||
}, | ||
"filter_settings": { | ||
"known_filters": { | ||
"db_url@Test data": { | ||
"scenario_filter": { | ||
"base_scenario": true | ||
} | ||
} | ||
}, | ||
"auto_online": true | ||
} | ||
} | ||
], | ||
"jumps": [] | ||
}, | ||
"items": { | ||
"Test data": { | ||
"type": "Data Store", | ||
"description": "", | ||
"x": -115.31149147072384, | ||
"y": 22.059589672660213, | ||
"url": { | ||
"dialect": "sqlite", | ||
"host": "", | ||
"port": "", | ||
"database": { | ||
"type": "path", | ||
"relative": true, | ||
"path": "Test data.sqlite" | ||
}, | ||
"schema": "" | ||
} | ||
}, | ||
"Exporter": { | ||
"type": "Exporter", | ||
"description": "", | ||
"x": 17.046046565237432, | ||
"y": 22.05958967266021, | ||
"output_time_stamps": false, | ||
"cancel_on_error": true, | ||
"output_labels": [ | ||
{ | ||
"in_label": "db_url@Test data", | ||
"out_label": "data.csv" | ||
} | ||
], | ||
"specification": "Export entities" | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
execution_tests/active_by_default/.spinetoolbox/specifications/Exporter/export_entities.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"item_type": "Exporter", | ||
"output_format": "csv", | ||
"name": "Export entities", | ||
"description": "", | ||
"mappings": { | ||
"Mapping (1)": { | ||
"type": "entities", | ||
"mapping": [ | ||
{ | ||
"map_type": "EntityClass", | ||
"position": 0 | ||
}, | ||
{ | ||
"map_type": "Entity", | ||
"position": 1 | ||
} | ||
], | ||
"enabled": true, | ||
"always_export_header": true, | ||
"group_fn": "no_group", | ||
"use_fixed_table_name": false | ||
} | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from pathlib import Path | ||
import shutil | ||
import subprocess | ||
import sys | ||
import unittest | ||
from spinedb_api import DatabaseMapping | ||
|
||
class ActiveByDefault(unittest.TestCase): | ||
_root_path = Path(__file__).parent | ||
_database_path = _root_path / "Test data.sqlite" | ||
_exporter_output_path = _root_path / ".spinetoolbox" / "items" / "exporter" / "output" | ||
|
||
def _check_addition(self, result): | ||
error = result[1] | ||
self.assertIsNone(error) | ||
|
||
def setUp(self): | ||
if self._exporter_output_path.exists(): | ||
shutil.rmtree(self._exporter_output_path) | ||
self._database_path.parent.mkdir(parents=True, exist_ok=True) | ||
if self._database_path.exists(): | ||
self._database_path.unlink() | ||
url = "sqlite:///" + str(self._database_path) | ||
with DatabaseMapping(url, create=True) as db_map: | ||
self._check_addition(db_map.add_entity_class_item(name="HiddenByDefault", active_by_default=False)) | ||
self._check_addition(db_map.add_entity_item(name="hidden", entity_class_name="HiddenByDefault")) | ||
self._check_addition(db_map.add_entity_class_item(name="VisibleByDefault", active_by_default=True)) | ||
self._check_addition(db_map.add_entity_item(name="visible", entity_class_name="VisibleByDefault")) | ||
self._check_addition(db_map.add_scenario_item(name="base_scenario")) | ||
self._check_addition(db_map.add_scenario_alternative_item(scenario_name="base_scenario", alternative_name="Base", rank=0)) | ||
db_map.commit_session("Add test data.") | ||
|
||
def test_execution(self): | ||
this_file = Path(__file__) | ||
completed = subprocess.run((sys.executable, "-m", "spinetoolbox", "--execute-only", str(this_file.parent))) | ||
self.assertEqual(completed.returncode, 0) | ||
self.assertTrue(self._exporter_output_path.exists()) | ||
self.assertEqual(len(list(self._exporter_output_path.iterdir())), 1) | ||
output_dir = next(iter(self._exporter_output_path.iterdir())) | ||
filter_id = (output_dir / ".filter_id").read_text(encoding="utf-8").splitlines() | ||
self.assertEqual(len(filter_id), 1) | ||
self.assertEqual(filter_id, ["base_scenario - Test data"]) | ||
entities = (output_dir / "data.csv").read_text(encoding="utf-8").splitlines() | ||
expected = ["VisibleByDefault,visible"] | ||
self.assertCountEqual(entities, expected) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.