-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ce9ca42
commit 7298732
Showing
6 changed files
with
77 additions
and
3 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,31 @@ | ||
# Generated by Django 5.1.2 on 2024-11-01 15:08 | ||
|
||
from django.db import migrations, models | ||
|
||
# Once GraphModel.create_node_alias is a static method, we can remove this import. | ||
# Until then, this is safe to use in a migration, because it doesn't use Graph | ||
# fields (and thus is a lot like a static method). | ||
from arches.app.models.graph import Graph | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("models", "11042_update__arches_staging_to_tile"), | ||
] | ||
|
||
def create_node_aliases(apps, schema_editor): | ||
Node = apps.get_model("models", "Node") | ||
nodes_needing_alias = Node.objects.filter(alias__isnull=True) | ||
for node in nodes_needing_alias: | ||
Graph.objects.get(pk=node.graph_id).create_node_alias(node) | ||
Node.objects.bulk_update(nodes_needing_alias, ["alias"]) | ||
|
||
operations = [ | ||
migrations.RunPython(create_node_aliases, migrations.RunPython.noop), | ||
migrations.AlterField( | ||
model_name="node", | ||
name="alias", | ||
field=models.TextField(blank=True), | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from arches.app.models.graph import Graph | ||
from arches.app.models.models import Node | ||
from tests.base_test import ArchesTestCase | ||
|
||
# these tests can be run from the command line via | ||
# python manage.py test tests.models.node_tests --settings="tests.test_settings" | ||
|
||
|
||
class NodeTests(ArchesTestCase): | ||
@classmethod | ||
def setUpTestData(cls): | ||
cls.graph = Graph.new(name="Node Tests Graph") | ||
|
||
def test_missing_alias_supplied(self): | ||
new_node = Node(graph_id=self.graph.pk) | ||
new_node.clean() | ||
self.assertIsNotNone(new_node.alias) | ||
|
||
def test_empty_custom_alias_regenerated(self): | ||
"""One dubiously empty alias per graph is currently allowed at the | ||
database level. Ensure it is regenerated via the application.""" | ||
new_node = Node( | ||
graph_id=self.graph.pk, name="Test node", alias="", hascustomalias=True | ||
) | ||
new_node.clean() | ||
self.assertEqual(new_node.alias, "test_node") | ||
self.assertIs(new_node.hascustomalias, False) |
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