diff --git a/tests/conftest.py b/tests/conftest.py
index 94fcd608..57987f0f 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -14,7 +14,7 @@
from vran.entity.models_django import Entity
from vran.management.display_txt.util import DISPLAY_TXT_ORDER_CONFIG_KEY
from vran.management.models_django import ConfigValue
-from vran.tag.models_django import TagDefinition
+from vran.tag.models_django import TagDefinition, TagDefinitionHistory
from vran.util import VranUser
@@ -63,8 +63,8 @@ def entity2():
@pytest.fixture()
def tag_def(user):
- return TagDefinition.objects.create( # pylint: disable=no-member
- id_persistent=ct.id_tag_persistent_test,
+ return TagDefinitionHistory.objects.create( # pylint: disable=no-member
+ id_persistent=ct.id_tag_def_persistent_test,
name=ct.name_tag_def_test,
time_edit=ct.time_edit_test,
type=TagDefinition.STRING,
@@ -73,9 +73,22 @@ def tag_def(user):
)
+@pytest.fixture()
+def tag_def_disabled(user):
+ return TagDefinitionHistory.objects.create( # pylint: disable=no-member
+ id_persistent=ct.id_tag_def_disabled_test,
+ name=ct.name_tag_def_disabled_test,
+ time_edit=ct.time_edit_test,
+ type=TagDefinition.STRING,
+ owner=user,
+ curated=False,
+ disabled=True,
+ )
+
+
@pytest.fixture()
def tag_def1(user1):
- return TagDefinition.objects.create( # pylint: disable=no-member
+ return TagDefinitionHistory.objects.create( # pylint: disable=no-member
id_persistent=ct.id_tag_def_persistent_test_user1,
name=ct.name_tag_def_test1,
time_edit=ct.time_edit_test1,
@@ -87,7 +100,7 @@ def tag_def1(user1):
@pytest.fixture()
def tag_def_curated():
- return TagDefinition.objects.create( # pylint: disable=no-member
+ return TagDefinitionHistory.objects.create( # pylint: disable=no-member
id_persistent=ct.id_tag_def_curated_test,
name=ct.name_tag_def_curated_test,
time_edit=ct.time_edit_curated_test,
diff --git a/tests/contribution/api/integration/get_contribution_test.py b/tests/contribution/api/integration/get_contribution_test.py
index 247f574c..c4c02036 100644
--- a/tests/contribution/api/integration/get_contribution_test.py
+++ b/tests/contribution/api/integration/get_contribution_test.py
@@ -82,6 +82,7 @@ def test_get_with_match_tag_definition_list(auth_server, tag_def1, tag_def_curat
"name_path": [tag_def_curated.name],
"type": "STRING",
"hidden": tag_def_curated.hidden,
+ "disabled": tag_def_curated.disabled,
"owner": None,
}
]
diff --git a/tests/contribution/api/integration/post_column_assignment_complete_test.py b/tests/contribution/api/integration/post_column_assignment_complete_test.py
index fa4b4c6b..32169ad0 100644
--- a/tests/contribution/api/integration/post_column_assignment_complete_test.py
+++ b/tests/contribution/api/integration/post_column_assignment_complete_test.py
@@ -8,7 +8,7 @@
import tests.user.common as cu
from vran.contribution.models_django import ContributionCandidate
from vran.contribution.tag_definition.models_django import TagDefinitionContribution
-from vran.tag.models_django import TagDefinition
+from vran.tag.models_django import TagDefinition, TagDefinitionHistory
from vran.util.auth import NotAuthenticatedException, VranUser
@@ -203,7 +203,7 @@ def test_complete_assignment(auth_server):
)
)
id_tag_definition_persistent = str(uuid4())
- TagDefinition.objects.create( # pylint: disable=no-member
+ TagDefinitionHistory.objects.create( # pylint: disable=no-member
name="tag definition_test",
id_parent_persistent=None,
type=TagDefinition.INNER,
diff --git a/tests/contribution/entity/queue_test.py b/tests/contribution/entity/queue_test.py
index 1e1f01ad..891b3c91 100644
--- a/tests/contribution/entity/queue_test.py
+++ b/tests/contribution/entity/queue_test.py
@@ -10,7 +10,12 @@
from vran.contribution.entity.models_django import EntityDuplicate
from vran.contribution.models_django import ContributionCandidate
from vran.entity.models_django import Entity
-from vran.tag.models_django import TagDefinition, TagInstance, TagInstanceHistory
+from vran.tag.models_django import (
+ TagDefinition,
+ TagDefinitionHistory,
+ TagInstance,
+ TagInstanceHistory,
+)
@pytest.fixture()
@@ -66,7 +71,7 @@ def test_removes_contribution_candidate_from_others(entity_duplicate):
@pytest.fixture
def tag_def(user):
- return TagDefinition.objects.create( # pylint: disable = no-member
+ return TagDefinitionHistory.objects.create( # pylint: disable = no-member
id_persistent=c.id_tag_def_test,
name=c.name_tag_def_test,
type=TagDefinition.STRING,
@@ -77,7 +82,7 @@ def tag_def(user):
@pytest.fixture
def tag_def1(user):
- return TagDefinition.objects.create( # pylint: disable = no-member
+ return TagDefinitionHistory.objects.create( # pylint: disable = no-member
id_persistent=c.id_tag_def_test1,
id_parent_persistent=c.id_tag_def_test,
name=c.name_tag_def_test1,
diff --git a/tests/contribution/tag_definition/api/integration/patch_tag_definition_test.py b/tests/contribution/tag_definition/api/integration/patch_tag_definition_test.py
index 0d9c8d8e..c196902a 100644
--- a/tests/contribution/tag_definition/api/integration/patch_tag_definition_test.py
+++ b/tests/contribution/tag_definition/api/integration/patch_tag_definition_test.py
@@ -8,7 +8,7 @@
import tests.contribution.tag_definition.api.integration.requests as req
from vran.contribution.models_django import ContributionCandidate
from vran.contribution.tag_definition.models_django import TagDefinitionContribution
-from vran.tag.models_django import TagDefinition
+from vran.tag.models_django import TagDefinition, TagDefinitionHistory
from vran.util.auth import NotAuthenticatedException
@@ -203,7 +203,7 @@ def test_patch_id_existing(auth_server):
server, cookies
)
new_id_existing = str(uuid4)
- TagDefinition.objects.create(
+ TagDefinitionHistory.objects.create(
name="existing tag def test",
type=TagDefinition.INNER,
id_persistent=new_id_existing,
diff --git a/tests/contribution/tag_definition/queue/ingest_test.py b/tests/contribution/tag_definition/queue/ingest_test.py
index 96ddf8a2..ce4f5343 100644
--- a/tests/contribution/tag_definition/queue/ingest_test.py
+++ b/tests/contribution/tag_definition/queue/ingest_test.py
@@ -12,7 +12,7 @@
from vran.contribution.tag_definition.queue.ingest import ingest_values_from_csv
from vran.entity.models_django import Entity
from vran.merge_request.models_django import TagMergeRequest
-from vran.tag.models_django import TagDefinition, TagInstance
+from vran.tag.models_django import TagDefinition, TagDefinitionHistory, TagInstance
csv_cols = {
"names": ["name_0", "name_1"],
@@ -47,7 +47,7 @@ def csv_mock_with_empty_lines():
@pytest.fixture
def verified_tag_def(db):
- return TagDefinition.objects.create( # pylint: disable=no-member
+ return TagDefinitionHistory.objects.create( # pylint: disable=no-member
name="tag definition verified_test",
id_parent_persistent=None,
type=TagDefinition.INNER,
@@ -58,7 +58,7 @@ def verified_tag_def(db):
@pytest.fixture
def party_tag_def(db):
- return TagDefinition.objects.create( # pylint: disable=no-member
+ return TagDefinitionHistory.objects.create( # pylint: disable=no-member
name="tag definition party test",
id_parent_persistent=None,
type=TagDefinition.STRING,
diff --git a/tests/entity/queue_test.py b/tests/entity/queue_test.py
index 1bffb0a3..028d3bf4 100644
--- a/tests/entity/queue_test.py
+++ b/tests/entity/queue_test.py
@@ -5,10 +5,12 @@
import pytest
import tests.tag.common as ct
+from tests.utils import assert_versioned
from vran.contribution.models_django import ContributionCandidate
from vran.entity.models_django import Entity
from vran.entity.queue import (
entity_display_txt_information_cache,
+ tag_def_db_to_dict,
update_display_txt_cache,
)
from vran.merge_request.models_django import TagMergeRequest
@@ -76,18 +78,20 @@ def test_without_display_txt_but_relevant_tag_instance(
)
assert result[0] == value_instance_tag_def_1
tag_def = result[1]
- assert len(tag_def) == 8
- assert "id" in tag_def
- tag_def.pop("id")
- assert tag_def == {
- "id_persistent": ct.id_tag_def_persistent_test_user1,
- "id_parent_persistent": None,
- "name": ct.name_tag_def_test1,
- "type": "STR",
- "owner": {"username": "test-user1"},
- "curated": False,
- "hidden": False,
- }
+ assert_versioned(
+ tag_def,
+ {
+ "id_persistent": ct.id_tag_def_persistent_test_user1,
+ "id_parent_persistent": None,
+ "name": ct.name_tag_def_test1,
+ "type": "STR",
+ "owner": {"username": "test-user1"},
+ "curated": False,
+ "hidden": False,
+ "disabled": False,
+ },
+ version_key="id",
+ )
def test_without_display_txt_and_no_relevant_tag_instance(
@@ -159,15 +163,36 @@ def test_contribution(contribution_instance_without_display_txt, display_txt_ord
)
assert result[0] == value_instance_tag_def_1
tag_def = result[1]
- assert len(tag_def) == 8
- assert "id" in tag_def
- tag_def.pop("id")
- assert tag_def == {
- "id_persistent": ct.id_tag_def_persistent_test_user1,
- "id_parent_persistent": None,
- "name": ct.name_tag_def_test1,
- "type": "STR",
- "owner": {"username": "test-user1"},
- "curated": False,
- "hidden": False,
- }
+ assert_versioned(
+ tag_def,
+ {
+ "id_persistent": ct.id_tag_def_persistent_test_user1,
+ "id_parent_persistent": None,
+ "name": ct.name_tag_def_test1,
+ "type": "STR",
+ "owner": {"username": "test-user1"},
+ "curated": False,
+ "hidden": False,
+ "disabled": False,
+ },
+ version_key="id",
+ )
+
+
+def test_db_to_dict(tag_def):
+ tag_def.disabled = True
+ tag_def_dict = tag_def_db_to_dict(tag_def)
+ assert_versioned(
+ tag_def_dict,
+ {
+ "id_persistent": ct.id_tag_def_persistent_test,
+ "id_parent_persistent": None,
+ "name": ct.name_tag_def_test,
+ "type": "STR",
+ "owner": {"username": "test-user"},
+ "curated": False,
+ "hidden": False,
+ "disabled": True,
+ },
+ version_key="id",
+ )
diff --git a/tests/management/display_txt/api/integration/append_display_txt_test.py b/tests/management/display_txt/api/integration/append_display_txt_test.py
index b82905c5..5b984a63 100644
--- a/tests/management/display_txt/api/integration/append_display_txt_test.py
+++ b/tests/management/display_txt/api/integration/append_display_txt_test.py
@@ -72,6 +72,6 @@ def test_append_to_existing(
)
assert rsp.status_code == 200
assert ConfigValue.get(DISPLAY_TXT_ORDER_CONFIG_KEY) == [
- ct.id_tag_persistent_test,
+ ct.id_tag_def_persistent_test,
ct.id_tag_def_curated_test,
]
diff --git a/tests/management/display_txt/api/integration/get_display_txt_test.py b/tests/management/display_txt/api/integration/get_display_txt_test.py
index 8b718bce..59b62a96 100644
--- a/tests/management/display_txt/api/integration/get_display_txt_test.py
+++ b/tests/management/display_txt/api/integration/get_display_txt_test.py
@@ -44,13 +44,14 @@ def test_three_element_order(auth_server_commissioner, display_txt_order_0_1_cur
{
"tag_definitions": [
{
- "id_persistent": ct.id_tag_persistent_test,
+ "id_persistent": ct.id_tag_def_persistent_test,
"id_parent_persistent": None,
"name": ct.name_tag_def_test,
"name_path": [ct.name_tag_def_test],
"type": "STRING",
"curated": False,
"hidden": False,
+ "disabled": False,
"owner": "test-user",
},
{
@@ -61,6 +62,7 @@ def test_three_element_order(auth_server_commissioner, display_txt_order_0_1_cur
"type": "STRING",
"curated": False,
"hidden": False,
+ "disabled": False,
"owner": "test-user1",
},
{
@@ -71,6 +73,7 @@ def test_three_element_order(auth_server_commissioner, display_txt_order_0_1_cur
"type": "STRING",
"curated": True,
"hidden": False,
+ "disabled": False,
"owner": None,
},
]
diff --git a/tests/management/display_txt/api/integration/remove_display_txt_test.py b/tests/management/display_txt/api/integration/remove_display_txt_test.py
index 17818e71..5c5d057b 100644
--- a/tests/management/display_txt/api/integration/remove_display_txt_test.py
+++ b/tests/management/display_txt/api/integration/remove_display_txt_test.py
@@ -38,7 +38,7 @@ def test_unknown_tag_def(auth_server_commissioner):
def test_remove_only(auth_server_commissioner, display_txt_order_0):
server, cookies = auth_server_commissioner
rsp = req.delete_tag_definition(
- server.url, ct.id_tag_persistent_test, cookies=cookies
+ server.url, ct.id_tag_def_persistent_test, cookies=cookies
)
assert rsp.status_code == 200
assert ConfigValue.get(DISPLAY_TXT_ORDER_CONFIG_KEY) == []
@@ -47,7 +47,7 @@ def test_remove_only(auth_server_commissioner, display_txt_order_0):
def test_remove_start(auth_server_commissioner, display_txt_order_0_1_curated):
server, cookies = auth_server_commissioner
rsp = req.delete_tag_definition(
- server.url, ct.id_tag_persistent_test, cookies=cookies
+ server.url, ct.id_tag_def_persistent_test, cookies=cookies
)
assert rsp.status_code == 200
assert ConfigValue.get(DISPLAY_TXT_ORDER_CONFIG_KEY) == [
@@ -63,7 +63,7 @@ def test_remove_middle(auth_server_commissioner, display_txt_order_0_1_curated):
)
assert rsp.status_code == 200
assert ConfigValue.get(DISPLAY_TXT_ORDER_CONFIG_KEY) == [
- ct.id_tag_persistent_test,
+ ct.id_tag_def_persistent_test,
ct.id_tag_def_curated_test,
]
@@ -75,6 +75,6 @@ def test_remove_end(auth_server_commissioner, display_txt_order_0_1_curated):
)
assert rsp.status_code == 200
assert ConfigValue.get(DISPLAY_TXT_ORDER_CONFIG_KEY) == [
- ct.id_tag_persistent_test,
+ ct.id_tag_def_persistent_test,
ct.id_tag_def_persistent_test_user1,
]
diff --git a/tests/merge_request/api/integration/get_merge_request_conflicts_test.py b/tests/merge_request/api/integration/get_merge_request_conflicts_test.py
index e18392b1..5e435762 100644
--- a/tests/merge_request/api/integration/get_merge_request_conflicts_test.py
+++ b/tests/merge_request/api/integration/get_merge_request_conflicts_test.py
@@ -10,7 +10,7 @@
from tests.utils import assert_versioned, format_datetime
from vran.exception import NotAuthenticatedException
from vran.merge_request.models_django import TagConflictResolution
-from vran.tag.models_django import TagDefinition, TagInstanceHistory
+from vran.tag.models_django import TagDefinitionHistory, TagInstanceHistory
def test_unknown_user(auth_server):
@@ -70,6 +70,7 @@ def test_conflicts_no_resolution(
"id_persistent": c.id_persistent_merge_request,
"created_at": format_datetime(c.time_merge_request),
"state": "OPEN",
+ "disable_origin_on_merge": False,
"origin": {
"id_persistent": c.id_persistent_tag_def_origin,
"id_parent_persistent": None,
@@ -79,6 +80,7 @@ def test_conflicts_no_resolution(
"owner": "test-user1",
"curated": False,
"hidden": False,
+ "disabled": False,
},
"destination": {
"id_persistent": c.id_persistent_tag_def_destination,
@@ -89,6 +91,7 @@ def test_conflicts_no_resolution(
"owner": "test-user",
"curated": False,
"hidden": False,
+ "disabled": False,
},
},
)
@@ -172,6 +175,7 @@ def test_conflicts_same_value(
"id_persistent": c.id_persistent_merge_request,
"created_at": format_datetime(c.time_merge_request),
"state": "OPEN",
+ "disable_origin_on_merge": False,
"origin": {
"id_persistent": c.id_persistent_tag_def_origin,
"id_parent_persistent": None,
@@ -181,6 +185,7 @@ def test_conflicts_same_value(
"owner": "test-user1",
"curated": False,
"hidden": False,
+ "disabled": False,
},
"destination": {
"id_persistent": c.id_persistent_tag_def_destination,
@@ -191,6 +196,7 @@ def test_conflicts_same_value(
"owner": "test-user",
"curated": False,
"hidden": False,
+ "disabled": False,
},
},
)
@@ -227,6 +233,7 @@ def test_conflict_resolved(
"id_persistent": c.id_persistent_merge_request,
"created_at": format_datetime(c.time_merge_request),
"state": "OPEN",
+ "disable_origin_on_merge": False,
"origin": {
"id_persistent": c.id_persistent_tag_def_origin,
"id_parent_persistent": None,
@@ -236,6 +243,7 @@ def test_conflict_resolved(
"owner": "test-user1",
"curated": False,
"hidden": False,
+ "disabled": False,
},
"destination": {
"id_persistent": c.id_persistent_tag_def_destination,
@@ -246,6 +254,7 @@ def test_conflict_resolved(
"owner": "test-user",
"curated": False,
"hidden": False,
+ "disabled": False,
},
},
)
@@ -292,7 +301,7 @@ def test_conflict_resolved_tag_def_origin_changed(
auth_server, merge_request_user, conflict_resolution_replace
):
old_tag_definition = conflict_resolution_replace.tag_definition_origin
- TagDefinition.change_or_create(
+ TagDefinitionHistory.change_or_create(
id_persistent=old_tag_definition.id_persistent,
version=old_tag_definition.id,
name="changed tag definition test",
@@ -321,6 +330,7 @@ def test_conflict_resolved_tag_def_origin_changed(
"id_persistent": c.id_persistent_merge_request,
"created_at": format_datetime(c.time_merge_request),
"state": "OPEN",
+ "disable_origin_on_merge": False,
"origin": {
"id_persistent": c.id_persistent_tag_def_origin,
"id_parent_persistent": None,
@@ -330,6 +340,7 @@ def test_conflict_resolved_tag_def_origin_changed(
"owner": "test-user1",
"curated": False,
"hidden": False,
+ "disabled": False,
},
"destination": {
"id_persistent": c.id_persistent_tag_def_destination,
@@ -340,6 +351,7 @@ def test_conflict_resolved_tag_def_origin_changed(
"owner": "test-user",
"curated": False,
"hidden": False,
+ "disabled": False,
},
},
)
@@ -453,6 +465,7 @@ def test_tag_instance_destination_value_added(
"id_persistent": c.id_persistent_merge_request,
"created_at": format_datetime(c.time_merge_request),
"state": "OPEN",
+ "disable_origin_on_merge": False,
"origin": {
"id_persistent": c.id_persistent_tag_def_origin,
"id_parent_persistent": None,
@@ -462,6 +475,7 @@ def test_tag_instance_destination_value_added(
"owner": "test-user1",
"curated": False,
"hidden": False,
+ "disabled": False,
},
"destination": {
"id_persistent": c.id_persistent_tag_def_destination,
@@ -472,6 +486,7 @@ def test_tag_instance_destination_value_added(
"owner": "test-user",
"curated": False,
"hidden": False,
+ "disabled": False,
},
},
)
diff --git a/tests/merge_request/api/integration/get_merge_requests_test.py b/tests/merge_request/api/integration/get_merge_requests_test.py
index d723fa64..cf142056 100644
--- a/tests/merge_request/api/integration/get_merge_requests_test.py
+++ b/tests/merge_request/api/integration/get_merge_requests_test.py
@@ -7,7 +7,7 @@
from tests.merge_request.api.integration import requests as req
from tests.utils import assert_versioned, format_datetime
from vran.exception import NotAuthenticatedException
-from vran.tag.models_django import TagDefinition
+from vran.tag.models_django import TagDefinition, TagDefinitionHistory
def test_unknown_user(auth_server):
@@ -31,98 +31,98 @@ def test_get_merge_requests(auth_server, merge_request_user, merge_request_user1
assert rsp.status_code == 200
json = rsp.json()
assert len(json) == 2
- created_list = json["created"]
- assert len(created_list) == 1
- created = created_list[0]
- assert len(created) == 7
- assert created["created_at"] == format_datetime(c.time_merge_request1)
- assert created["id_persistent"] == c.id_persistent_merge_request1
- assert created["created_by"] == {
- "user_name": cu.test_username,
- "id_persistent": cu.test_uuid,
- "permission_group": "APPLICANT",
- }
- assert created["assigned_to"] == {
- "user_name": cu.test_username1,
- "id_persistent": cu.test_uuid1,
- "permission_group": "APPLICANT",
- }
- assert created["state"] == "OPEN"
assert_versioned(
- created["destination"],
- {
- "id_persistent": c.id_persistent_tag_def_destination1,
- "id_parent_persistent": None,
- "name": c.name_tag_def_destination1,
- "name_path": [c.name_tag_def_destination1],
- "type": "STRING",
- "owner": "test-user1",
- "curated": False,
- "hidden": False,
- },
- )
- assert_versioned(
- created["origin"],
- {
- "name": c.name_tag_def_origin1,
- "name_path": [c.name_tag_def_origin1],
- "id_parent_persistent": None,
- "id_persistent": c.id_persistent_tag_def_origin1,
- "type": "STRING",
- "owner": "test-user",
- "curated": False,
- "hidden": False,
- },
- )
- assigned_list = json["assigned"]
- assert len(assigned_list) == 1
- assigned = assigned_list[0]
- assert len(assigned) == 7
- assert assigned["created_at"] == format_datetime(c.time_merge_request)
- assert assigned["id_persistent"] == c.id_persistent_merge_request
- assert assigned["created_by"] == {
- "user_name": cu.test_username1,
- "id_persistent": cu.test_uuid1,
- "permission_group": "APPLICANT",
- }
- assert assigned["assigned_to"] == {
- "user_name": cu.test_username,
- "id_persistent": cu.test_uuid,
- "permission_group": "APPLICANT",
- }
- assert assigned["state"] == "OPEN"
- assert_versioned(
- assigned["destination"],
- {
- "id_persistent": c.id_persistent_tag_def_destination,
- "id_parent_persistent": None,
- "name": c.name_tag_def_destination,
- "name_path": [c.name_tag_def_destination],
- "type": "STRING",
- "owner": "test-user",
- "curated": False,
- "hidden": False,
- },
+ json["created"],
+ [
+ {
+ "created_at": format_datetime(c.time_merge_request1),
+ "id_persistent": c.id_persistent_merge_request1,
+ "created_by": {
+ "user_name": cu.test_username,
+ "id_persistent": cu.test_uuid,
+ "permission_group": "APPLICANT",
+ },
+ "assigned_to": {
+ "user_name": cu.test_username1,
+ "id_persistent": cu.test_uuid1,
+ "permission_group": "APPLICANT",
+ },
+ "state": "OPEN",
+ "disable_origin_on_merge": False,
+ "destination": {
+ "id_persistent": c.id_persistent_tag_def_destination1,
+ "id_parent_persistent": None,
+ "name": c.name_tag_def_destination1,
+ "name_path": [c.name_tag_def_destination1],
+ "type": "STRING",
+ "owner": "test-user1",
+ "curated": False,
+ "hidden": False,
+ "disabled": False,
+ },
+ "origin": {
+ "name": c.name_tag_def_origin1,
+ "name_path": [c.name_tag_def_origin1],
+ "id_parent_persistent": None,
+ "id_persistent": c.id_persistent_tag_def_origin1,
+ "type": "STRING",
+ "owner": "test-user",
+ "curated": False,
+ "hidden": False,
+ "disabled": False,
+ },
+ }
+ ],
)
assert_versioned(
- assigned["origin"],
- {
- "name": c.name_tag_def_origin,
- "name_path": [c.name_tag_def_origin],
- "id_persistent": c.id_persistent_tag_def_origin,
- "id_parent_persistent": None,
- "type": "STRING",
- "owner": "test-user1",
- "curated": False,
- "hidden": False,
- },
+ json["assigned"],
+ [
+ {
+ "created_at": format_datetime(c.time_merge_request),
+ "id_persistent": c.id_persistent_merge_request,
+ "created_by": {
+ "user_name": cu.test_username1,
+ "id_persistent": cu.test_uuid1,
+ "permission_group": "APPLICANT",
+ },
+ "assigned_to": {
+ "user_name": cu.test_username,
+ "id_persistent": cu.test_uuid,
+ "permission_group": "APPLICANT",
+ },
+ "state": "OPEN",
+ "disable_origin_on_merge": False,
+ "destination": {
+ "id_persistent": c.id_persistent_tag_def_destination,
+ "id_parent_persistent": None,
+ "name": c.name_tag_def_destination,
+ "name_path": [c.name_tag_def_destination],
+ "type": "STRING",
+ "owner": "test-user",
+ "curated": False,
+ "hidden": False,
+ "disabled": False,
+ },
+ "origin": {
+ "name": c.name_tag_def_origin,
+ "name_path": [c.name_tag_def_origin],
+ "id_persistent": c.id_persistent_tag_def_origin,
+ "id_parent_persistent": None,
+ "type": "STRING",
+ "owner": "test-user1",
+ "curated": False,
+ "hidden": False,
+ "disabled": False,
+ },
+ }
+ ],
)
def test_get_merge_requests_with_hidden(
auth_server, merge_request_user, merge_request_user1, origin_tag_def_for_mr1
):
- tag_def, _ = TagDefinition.change_or_create(
+ tag_def, _ = TagDefinitionHistory.change_or_create(
id_persistent=origin_tag_def_for_mr1.id_persistent,
id_parent_persistent=origin_tag_def_for_mr1.id_parent_persistent,
name=origin_tag_def_for_mr1.name,
@@ -139,91 +139,91 @@ def test_get_merge_requests_with_hidden(
assert rsp.status_code == 200
json = rsp.json()
assert len(json) == 2
- created_list = json["created"]
- assert len(created_list) == 1
- created = created_list[0]
- assert len(created) == 7
- assert created["created_at"] == format_datetime(c.time_merge_request1)
- assert created["id_persistent"] == c.id_persistent_merge_request1
- assert created["created_by"] == {
- "user_name": cu.test_username,
- "id_persistent": cu.test_uuid,
- "permission_group": "APPLICANT",
- }
- assert created["assigned_to"] == {
- "user_name": cu.test_username1,
- "id_persistent": cu.test_uuid1,
- "permission_group": "APPLICANT",
- }
- assert created["state"] == "OPEN"
assert_versioned(
- created["destination"],
- {
- "id_persistent": c.id_persistent_tag_def_destination1,
- "id_parent_persistent": None,
- "name": c.name_tag_def_destination1,
- "name_path": [c.name_tag_def_destination1],
- "type": "STRING",
- "owner": "test-user1",
- "curated": False,
- "hidden": False,
- },
- )
- assert_versioned(
- created["origin"],
- {
- "name": c.name_tag_def_origin1,
- "name_path": [c.name_tag_def_origin1],
- "id_parent_persistent": None,
- "id_persistent": c.id_persistent_tag_def_origin1,
- "type": "STRING",
- "owner": "test-user",
- "curated": False,
- "hidden": True,
- },
- )
- assigned_list = json["assigned"]
- assert len(assigned_list) == 1
- assigned = assigned_list[0]
- assert len(assigned) == 7
- assert assigned["created_at"] == format_datetime(c.time_merge_request)
- assert assigned["id_persistent"] == c.id_persistent_merge_request
- assert assigned["created_by"] == {
- "user_name": cu.test_username1,
- "id_persistent": cu.test_uuid1,
- "permission_group": "APPLICANT",
- }
- assert assigned["assigned_to"] == {
- "user_name": cu.test_username,
- "id_persistent": cu.test_uuid,
- "permission_group": "APPLICANT",
- }
- assert assigned["state"] == "OPEN"
- assert_versioned(
- assigned["destination"],
- {
- "id_persistent": c.id_persistent_tag_def_destination,
- "id_parent_persistent": None,
- "name": c.name_tag_def_destination,
- "name_path": [c.name_tag_def_destination],
- "type": "STRING",
- "owner": "test-user",
- "curated": False,
- "hidden": False,
- },
+ json["created"],
+ [
+ {
+ "created_at": format_datetime(c.time_merge_request1),
+ "id_persistent": c.id_persistent_merge_request1,
+ "created_by": {
+ "user_name": cu.test_username,
+ "id_persistent": cu.test_uuid,
+ "permission_group": "APPLICANT",
+ },
+ "assigned_to": {
+ "user_name": cu.test_username1,
+ "id_persistent": cu.test_uuid1,
+ "permission_group": "APPLICANT",
+ },
+ "state": "OPEN",
+ "disable_origin_on_merge": False,
+ "destination": {
+ "id_persistent": c.id_persistent_tag_def_destination1,
+ "id_parent_persistent": None,
+ "name": c.name_tag_def_destination1,
+ "name_path": [c.name_tag_def_destination1],
+ "type": "STRING",
+ "owner": "test-user1",
+ "curated": False,
+ "hidden": False,
+ "disabled": False,
+ },
+ "origin": {
+ "name": c.name_tag_def_origin1,
+ "name_path": [c.name_tag_def_origin1],
+ "id_parent_persistent": None,
+ "id_persistent": c.id_persistent_tag_def_origin1,
+ "type": "STRING",
+ "owner": "test-user",
+ "curated": False,
+ "hidden": True,
+ "disabled": False,
+ },
+ }
+ ],
)
assert_versioned(
- assigned["origin"],
- {
- "name": c.name_tag_def_origin,
- "name_path": [c.name_tag_def_origin],
- "id_persistent": c.id_persistent_tag_def_origin,
- "id_parent_persistent": None,
- "type": "STRING",
- "owner": "test-user1",
- "curated": False,
- "hidden": False,
- },
+ json["assigned"],
+ [
+ {
+ "created_at": format_datetime(c.time_merge_request),
+ "id_persistent": c.id_persistent_merge_request,
+ "created_by": {
+ "user_name": cu.test_username1,
+ "id_persistent": cu.test_uuid1,
+ "permission_group": "APPLICANT",
+ },
+ "assigned_to": {
+ "user_name": cu.test_username,
+ "id_persistent": cu.test_uuid,
+ "permission_group": "APPLICANT",
+ },
+ "state": "OPEN",
+ "disable_origin_on_merge": False,
+ "destination": {
+ "id_persistent": c.id_persistent_tag_def_destination,
+ "id_parent_persistent": None,
+ "name": c.name_tag_def_destination,
+ "name_path": [c.name_tag_def_destination],
+ "type": "STRING",
+ "owner": "test-user",
+ "curated": False,
+ "hidden": False,
+ "disabled": False,
+ },
+ "origin": {
+ "name": c.name_tag_def_origin,
+ "name_path": [c.name_tag_def_origin],
+ "id_persistent": c.id_persistent_tag_def_origin,
+ "id_parent_persistent": None,
+ "type": "STRING",
+ "owner": "test-user1",
+ "curated": False,
+ "hidden": False,
+ "disabled": False,
+ },
+ }
+ ],
)
@@ -250,6 +250,7 @@ def test_includes_curated(
"assigned_to": None,
"created_at": format_datetime(c.time_merge_request_curated),
"state": "OPEN",
+ "disable_origin_on_merge": False,
"destination": {
"id_persistent": "2ec43995-338b-4f4b-b1cc-4bfc71466fc5",
"id_parent_persistent": None,
@@ -259,6 +260,7 @@ def test_includes_curated(
"owner": None,
"curated": True,
"hidden": False,
+ "disabled": False,
},
"origin": {
"id_persistent": "52d5de0a-2fdb-457f-80d0-6e10131ad1b9",
@@ -269,6 +271,7 @@ def test_includes_curated(
"type": "STRING",
"curated": False,
"hidden": False,
+ "disabled": False,
},
}
],
diff --git a/tests/merge_request/api/integration/patch_merge_request_test.py b/tests/merge_request/api/integration/patch_merge_request_test.py
new file mode 100644
index 00000000..0e502903
--- /dev/null
+++ b/tests/merge_request/api/integration/patch_merge_request_test.py
@@ -0,0 +1,108 @@
+# pylint: disable=missing-module-docstring, missing-function-docstring,redefined-outer-name,invalid-name,unused-argument,too-many-statements
+from unittest.mock import MagicMock, patch
+
+import tests.user.common as cu
+from tests.merge_request import common as c
+from tests.merge_request.api.integration import requests as req
+from tests.utils import assert_versioned, format_datetime
+from vran.exception import NotAuthenticatedException
+from vran.merge_request.models_django import TagMergeRequest
+
+
+def test_unknown_user(auth_server):
+ mock = MagicMock()
+ mock.side_effect = NotAuthenticatedException()
+ server, cookies = auth_server
+ with patch("vran.merge_request.api.check_user", mock):
+ rsp = req.patch_merge_request(
+ server.url, c.id_persistent_merge_request, {}, cookies=cookies
+ )
+ assert rsp.status_code == 401
+
+
+def test_no_cookies(auth_server):
+ server, _ = auth_server
+ rsp = req.patch_merge_request(server.url, c.id_persistent_merge_request, {})
+ assert rsp.status_code == 401
+
+
+def test_wrong_user(auth_server_commissioner, merge_request_user1):
+ server, cookies = auth_server_commissioner
+ rsp = req.patch_merge_request(
+ server.url, merge_request_user1.id_persistent, {}, cookies
+ )
+ assert rsp.status_code == 403
+
+
+def test_set_disable_on_merge(auth_server, merge_request_user):
+ server, cookies = auth_server
+ rsp = req.patch_merge_request(
+ server.url,
+ merge_request_user.id_persistent,
+ {"disable_origin_on_merge": True},
+ cookies,
+ )
+ assert rsp.status_code == 200
+ assert (
+ TagMergeRequest.objects.filter( # pylint: disable=no-member
+ id_persistent=merge_request_user.id_persistent
+ )
+ .get()
+ .disable_origin_on_merge
+ )
+
+ rsp = req.patch_merge_request(
+ server.url,
+ merge_request_user.id_persistent,
+ {"disable_origin_on_merge": False},
+ cookies,
+ )
+ assert rsp.status_code == 200
+ assert (
+ not TagMergeRequest.objects.filter( # pylint: disable=no-member
+ id_persistent=merge_request_user.id_persistent
+ )
+ .get()
+ .disable_origin_on_merge
+ )
+ assert_versioned(
+ rsp.json(),
+ {
+ "created_at": format_datetime(c.time_merge_request),
+ "id_persistent": c.id_persistent_merge_request,
+ "created_by": {
+ "user_name": cu.test_username1,
+ "id_persistent": cu.test_uuid1,
+ "permission_group": "APPLICANT",
+ },
+ "assigned_to": {
+ "user_name": cu.test_username,
+ "id_persistent": cu.test_uuid,
+ "permission_group": "APPLICANT",
+ },
+ "state": "OPEN",
+ "disable_origin_on_merge": False,
+ "destination": {
+ "id_persistent": c.id_persistent_tag_def_destination,
+ "id_parent_persistent": None,
+ "name": c.name_tag_def_destination,
+ "name_path": [c.name_tag_def_destination],
+ "type": "STRING",
+ "owner": "test-user",
+ "curated": False,
+ "hidden": False,
+ "disabled": False,
+ },
+ "origin": {
+ "name": c.name_tag_def_origin,
+ "name_path": [c.name_tag_def_origin],
+ "id_persistent": c.id_persistent_tag_def_origin,
+ "id_parent_persistent": None,
+ "type": "STRING",
+ "owner": "test-user1",
+ "curated": False,
+ "hidden": False,
+ "disabled": False,
+ },
+ },
+ )
diff --git a/tests/merge_request/api/integration/requests.py b/tests/merge_request/api/integration/requests.py
index 71c8872f..3ba3cb1c 100644
--- a/tests/merge_request/api/integration/requests.py
+++ b/tests/merge_request/api/integration/requests.py
@@ -56,3 +56,12 @@ def post_start_merge(url, id_merge_request_persistent, cookies=None):
cookies=cookies,
timeout=900,
)
+
+
+def patch_merge_request(url, id_merge_request_persistent, patch_dict, cookies=None):
+ return requests.patch(
+ url + f"/vran/api/merge_requests/{id_merge_request_persistent}",
+ json=patch_dict,
+ cookies=cookies,
+ timeout=900,
+ )
diff --git a/tests/merge_request/conftest.py b/tests/merge_request/conftest.py
index 5293f1dd..3db243fe 100644
--- a/tests/merge_request/conftest.py
+++ b/tests/merge_request/conftest.py
@@ -5,12 +5,16 @@
import tests.merge_request.common as c
from vran.contribution.models_django import ContributionCandidate
from vran.merge_request.models_django import TagConflictResolution, TagMergeRequest
-from vran.tag.models_django import TagDefinition, TagInstanceHistory
+from vran.tag.models_django import (
+ TagDefinition,
+ TagDefinitionHistory,
+ TagInstanceHistory,
+)
@pytest.fixture
def destination_tag_def_for_mr(db, user):
- return TagDefinition.objects.create( # pylint: disable=no-member
+ return TagDefinitionHistory.objects.create( # pylint: disable=no-member
name=c.name_tag_def_destination,
id_persistent=c.id_persistent_tag_def_destination,
type=TagDefinition.STRING,
@@ -21,7 +25,7 @@ def destination_tag_def_for_mr(db, user):
@pytest.fixture
def destination_tag_def_for_mr_changed(destination_tag_def_for_mr):
- tag_def, _ = TagDefinition.change_or_create(
+ tag_def, _ = TagDefinitionHistory.change_or_create(
id_persistent=destination_tag_def_for_mr.id_persistent,
version=destination_tag_def_for_mr.id,
name="changed tag definition test",
@@ -33,7 +37,7 @@ def destination_tag_def_for_mr_changed(destination_tag_def_for_mr):
@pytest.fixture
def destination_tag_def_for_mr_user1(db, user1):
- return TagDefinition.objects.create( # pylint: disable=no-member
+ return TagDefinitionHistory.objects.create( # pylint: disable=no-member
name=c.name_tag_def_destination,
id_persistent=c.id_persistent_tag_def_destination_fast_forward,
type=TagDefinition.STRING,
@@ -44,7 +48,7 @@ def destination_tag_def_for_mr_user1(db, user1):
@pytest.fixture
def origin_tag_def_for_mr(db, user1):
- return TagDefinition.objects.create( # pylint: disable=no-member
+ return TagDefinitionHistory.objects.create( # pylint: disable=no-member
name=c.name_tag_def_origin,
id_persistent=c.id_persistent_tag_def_origin,
type=TagDefinition.STRING,
@@ -55,7 +59,7 @@ def origin_tag_def_for_mr(db, user1):
@pytest.fixture
def origin_tag_def_for_mr_changed(origin_tag_def_for_mr):
- tag_def, _ = TagDefinition.change_or_create(
+ tag_def, _ = TagDefinitionHistory.change_or_create(
id_persistent=origin_tag_def_for_mr.id_persistent,
version=origin_tag_def_for_mr.id,
name="changed tag definition test",
@@ -92,6 +96,22 @@ def merge_request_user_fast_forward(
)
+@pytest.fixture
+def merge_request_user_fast_forward_disable_origin(
+ db, origin_tag_def_for_mr, destination_tag_def_for_mr_user1, contribution_for_mr
+):
+ return TagMergeRequest.objects.create( # pylint: disable=no-member
+ id_origin_persistent=origin_tag_def_for_mr.id_persistent,
+ id_destination_persistent=destination_tag_def_for_mr_user1.id_persistent,
+ created_by=origin_tag_def_for_mr.owner,
+ assigned_to=destination_tag_def_for_mr_user1.owner,
+ created_at=c.time_merge_request,
+ id_persistent=c.id_persistent_merge_request_fast_forward,
+ contribution_candidate=contribution_for_mr,
+ disable_origin_on_merge=True,
+ )
+
+
@pytest.fixture
def merge_request_user(
db, origin_tag_def_for_mr, destination_tag_def_for_mr, contribution_for_mr
@@ -107,12 +127,28 @@ def merge_request_user(
)
+@pytest.fixture
+def merge_request_user_disable_origin(
+ db, origin_tag_def_for_mr, destination_tag_def_for_mr, contribution_for_mr
+):
+ return TagMergeRequest.objects.create( # pylint: disable=no-member
+ id_origin_persistent=origin_tag_def_for_mr.id_persistent,
+ id_destination_persistent=destination_tag_def_for_mr.id_persistent,
+ created_by=origin_tag_def_for_mr.owner,
+ assigned_to=destination_tag_def_for_mr.owner,
+ created_at=c.time_merge_request,
+ id_persistent=c.id_persistent_merge_request,
+ contribution_candidate=contribution_for_mr,
+ disable_origin_on_merge=True,
+ )
+
+
@pytest.fixture
def destination_tag_def_for_mr1(db, user1):
- return TagDefinition.objects.create( # pylint: disable=no-member
+ return TagDefinitionHistory.objects.create( # pylint: disable=no-member
name=c.name_tag_def_destination1,
id_persistent=c.id_persistent_tag_def_destination1,
- type=TagDefinition.STRING,
+ type=TagDefinitionHistory.STRING,
time_edit=c.time_tag_def_destination1,
owner=user1,
)
@@ -120,7 +156,7 @@ def destination_tag_def_for_mr1(db, user1):
@pytest.fixture
def origin_tag_def_for_mr1(db, user):
- return TagDefinition.objects.create( # pylint: disable=no-member
+ return TagDefinitionHistory.objects.create( # pylint: disable=no-member
name=c.name_tag_def_origin1,
id_persistent=c.id_persistent_tag_def_origin1,
type=TagDefinition.STRING,
diff --git a/tests/merge_request/entity/api/integration/get_entity_conflicts_test.py b/tests/merge_request/entity/api/integration/get_entity_conflicts_test.py
index 69d34a93..dc006a72 100644
--- a/tests/merge_request/entity/api/integration/get_entity_conflicts_test.py
+++ b/tests/merge_request/entity/api/integration/get_entity_conflicts_test.py
@@ -106,7 +106,7 @@ def test_conflicts_no_resolution(
"tag_definition": {
"name_path": [ct.name_tag_def_test],
"id_parent_persistent": None,
- "id_persistent": ct.id_tag_def_persistent_test_user,
+ "id_persistent": ct.id_tag_def_persistent_test,
"curated": False,
"hidden": False,
},
@@ -257,7 +257,7 @@ def test_conflicts_resolved(
"tag_definition": {
"name_path": [ct.name_tag_def_test],
"id_parent_persistent": None,
- "id_persistent": ct.id_tag_def_persistent_test_user,
+ "id_persistent": ct.id_tag_def_persistent_test,
"curated": False,
"hidden": False,
},
diff --git a/tests/merge_request/entity/api/integration/post_resolution_test.py b/tests/merge_request/entity/api/integration/post_resolution_test.py
index 3524020c..5dea4c41 100644
--- a/tests/merge_request/entity/api/integration/post_resolution_test.py
+++ b/tests/merge_request/entity/api/integration/post_resolution_test.py
@@ -183,7 +183,7 @@ def test_resolve_conflicts(
"tag_definition": {
"name_path": [ct.name_tag_def_test],
"id_parent_persistent": None,
- "id_persistent": ct.id_tag_def_persistent_test_user,
+ "id_persistent": ct.id_tag_def_persistent_test,
"curated": False,
"hidden": False,
},
diff --git a/tests/merge_request/entity/api/integration/requests.py b/tests/merge_request/entity/api/integration/requests.py
index 0cbe3bd3..d259eae1 100644
--- a/tests/merge_request/entity/api/integration/requests.py
+++ b/tests/merge_request/entity/api/integration/requests.py
@@ -34,7 +34,7 @@ def post_reverse_origin_destination(url, id_merge_request_persistent, cookies=No
def get_merge_requests(url, cookies=None):
return requests.get(
- url + "/vran/api/merge_requests/entities", cookies=cookies, timeout=900
+ url + "/vran/api/merge_requests/entities/all", cookies=cookies, timeout=900
)
diff --git a/tests/merge_request/entity/api/integration/revere_origin_destination_test.py b/tests/merge_request/entity/api/integration/revere_origin_destination_test.py
index fba925da..67af83e0 100644
--- a/tests/merge_request/entity/api/integration/revere_origin_destination_test.py
+++ b/tests/merge_request/entity/api/integration/revere_origin_destination_test.py
@@ -193,7 +193,7 @@ def test_double_reverse(
"tag_definition": {
"name_path": [ct.name_tag_def_test],
"id_parent_persistent": None,
- "id_persistent": ct.id_tag_def_persistent_test_user,
+ "id_persistent": ct.id_tag_def_persistent_test,
"curated": False,
},
"tag_instance_origin": {
diff --git a/tests/merge_request/entity/conftest.py b/tests/merge_request/entity/conftest.py
index 892e9f33..e0efc458 100644
--- a/tests/merge_request/entity/conftest.py
+++ b/tests/merge_request/entity/conftest.py
@@ -7,7 +7,7 @@
EntityConflictResolution,
EntityMergeRequest,
)
-from vran.tag.models_django import TagDefinition, TagInstanceHistory
+from vran.tag.models_django import TagDefinitionHistory, TagInstanceHistory
@pytest.fixture
@@ -199,7 +199,7 @@ def instance_merge_request_destination_user_same_value1(merge_request_user):
@pytest.fixture()
def tag_def_for_mr_changed(tag_def1):
- tag_def, _ = TagDefinition.change_or_create(
+ tag_def, _ = TagDefinitionHistory.change_or_create(
id_persistent=tag_def1.id_persistent,
version=tag_def1.id,
time_edit=c.time_tag_def_changed,
@@ -236,6 +236,25 @@ def conflict_resolution_replace(
)
+@pytest.fixture
+def conflict_resolution_replace_empty_destination(
+ merge_request_user,
+ origin_entity_for_mr,
+ destination_entity_for_mr,
+ tag_def1,
+ instances_merge_request_origin_user,
+):
+ return EntityConflictResolution.objects.create( # pylint: disable=no-member
+ tag_definition=tag_def1,
+ entity_origin=origin_entity_for_mr,
+ entity_destination=destination_entity_for_mr,
+ tag_instance_origin=instances_merge_request_origin_user[1],
+ tag_instance_destination=None,
+ merge_request=merge_request_user,
+ replace=True,
+ )
+
+
@pytest.fixture
def conflict_resolution_keep(
merge_request_user,
diff --git a/tests/merge_request/entity/models_django_test.py b/tests/merge_request/entity/models_django_test.py
index c0fcd09e..b812317f 100644
--- a/tests/merge_request/entity/models_django_test.py
+++ b/tests/merge_request/entity/models_django_test.py
@@ -2,7 +2,7 @@
from datetime import datetime
from vran.merge_request.entity.models_django import EntityConflictResolution
-from vran.tag.models_django import TagDefinition
+from vran.tag.models_django import TagDefinition, TagDefinitionHistory
def test_no_change_user(merge_request_user, conflict_resolution_replace, user):
@@ -345,7 +345,7 @@ def test_change_all(
conflict_resolution_replace,
):
old_tag_def = conflict_resolution_replace.tag_definition
- TagDefinition.change_or_create(
+ TagDefinitionHistory.change_or_create(
id_persistent=old_tag_def.id_persistent,
time_edit=datetime(1912, 4, 7),
name="edited tag definition",
diff --git a/tests/merge_request/entity/queue_test.py b/tests/merge_request/entity/queue_test.py
index eb5e4806..ec192e3a 100644
--- a/tests/merge_request/entity/queue_test.py
+++ b/tests/merge_request/entity/queue_test.py
@@ -21,9 +21,43 @@ def test_creates_tag_merge_requests(conflict_resolution_replace):
tag_merge_requests = TagMergeRequest.objects.all() # pylint: disable=no-member
assert len(tag_merge_requests) == 3
assert len({mr.id_destination_persistent for mr in tag_merge_requests}) == 3
- tag_defs_including_hidden = TagDefinition.most_recent_query_set(include_hidden=True)
+ for mr in tag_merge_requests:
+ assert mr.disable_origin_on_merge
+ tag_defs_including_hidden = TagDefinition.query_set(include_hidden=True)
assert len(tag_defs_including_hidden) == 6
- assert len(TagDefinition.most_recent_query_set()) == 3
+ assert len(TagDefinition.query_set()) == 3
+ hidden_tag_def_instances = (
+ TagInstance.objects.all() # pylint: disable=no-member
+ .annotate(
+ hidden=models.Subquery(
+ tag_defs_including_hidden.filter(
+ id_persistent=models.OuterRef("id_tag_definition_persistent")
+ ).values("hidden")
+ )
+ )
+ .filter(hidden=True)
+ )
+ assert len(hidden_tag_def_instances) == 3
+
+
+def test_creates_tag_merge_requests_empty_destination(
+ conflict_resolution_replace_empty_destination,
+):
+ merge_request = conflict_resolution_replace_empty_destination.merge_request
+ merge_request.state = EntityMergeRequest.RESOLVED
+ merge_request.save()
+ user = merge_request.created_by
+ apply_entity_merge_request(merge_request.id_persistent, user.id_persistent)
+ most_recent = Entity.most_recent().get()
+ assert most_recent.display_txt == c.display_txt_entity_destination
+ tag_merge_requests = TagMergeRequest.objects.all() # pylint: disable=no-member
+ assert len(tag_merge_requests) == 3
+ assert len({mr.id_destination_persistent for mr in tag_merge_requests}) == 3
+ for mr in tag_merge_requests:
+ assert mr.disable_origin_on_merge
+ tag_defs_including_hidden = TagDefinition.query_set(include_hidden=True)
+ assert len(tag_defs_including_hidden) == 6
+ assert len(TagDefinition.query_set()) == 3
hidden_tag_def_instances = (
TagInstance.objects.all() # pylint: disable=no-member
.annotate(
@@ -48,8 +82,8 @@ def test_applies_resolutions(conflict_resolution_replace, user1):
tag_merge_requests = TagMergeRequest.objects.all() # pylint: disable=no-member
assert len(tag_merge_requests) == 2
assert len({mr.id_destination_persistent for mr in tag_merge_requests}) == 2
- assert len(TagDefinition.most_recent_query_set(include_hidden=True)) == 5
- assert len(TagDefinition.most_recent_query_set()) == 3
+ assert len(TagDefinition.query_set(include_hidden=True)) == 5
+ assert len(TagDefinition.query_set()) == 3
def test_creates_tag_merge_request_for_updated(
@@ -66,9 +100,9 @@ def test_creates_tag_merge_request_for_updated(
tag_merge_requests = TagMergeRequest.objects.all() # pylint: disable=no-member
assert len(tag_merge_requests) == 3
assert len({mr.id_destination_persistent for mr in tag_merge_requests}) == 3
- tag_defs_including_hidden = TagDefinition.most_recent_query_set(include_hidden=True)
+ tag_defs_including_hidden = TagDefinition.query_set(include_hidden=True)
assert len(tag_defs_including_hidden) == 6
- assert len(TagDefinition.most_recent_query_set()) == 3
+ assert len(TagDefinition.query_set()) == 3
hidden_tag_def_instances = (
TagInstance.objects.all() # pylint: disable=no-member
.annotate(
diff --git a/tests/merge_request/queue_test.py b/tests/merge_request/queue_test.py
index 6c770057..0a0ae75d 100644
--- a/tests/merge_request/queue_test.py
+++ b/tests/merge_request/queue_test.py
@@ -2,7 +2,7 @@
import vran.merge_request.queue as q
from vran.merge_request.models_django import TagMergeRequest
-from vran.tag.models_django import TagInstance
+from vran.tag.models_django import TagDefinition, TagInstance
def test_fast_forward_destination_empty(
@@ -14,6 +14,25 @@ def test_fast_forward_destination_empty(
merge_request_user_fast_forward.created_by,
)
assert merge_request_after.state == TagMergeRequest.MERGED
+ assert not TagDefinition.most_recent_by_id(
+ merge_request_user_fast_forward.id_origin_persistent
+ ).disabled
+
+
+def test_fast_forward_destination_empty_with_disable(
+ merge_request_user_fast_forward_disable_origin, instances_merge_request_origin_user
+):
+ q.merge_request_fast_forward(
+ merge_request_user_fast_forward_disable_origin.id_persistent
+ )
+ merge_request_after = TagMergeRequest.by_id_persistent(
+ merge_request_user_fast_forward_disable_origin.id_persistent,
+ merge_request_user_fast_forward_disable_origin.created_by,
+ )
+ assert merge_request_after.state == TagMergeRequest.MERGED
+ assert TagDefinition.most_recent_by_id(
+ merge_request_user_fast_forward_disable_origin.id_origin_persistent
+ ).disabled
def test_fast_forward_origin_empty(
@@ -84,6 +103,24 @@ def test_applies_resolutions(
assert instance.value == "value origin 1"
+def test_applies_resolutions_disable_origin(merge_request_user_disable_origin):
+ q.merge_request_resolve_conflicts(merge_request_user_disable_origin.id_persistent)
+ merge_request = TagMergeRequest.by_id_persistent(
+ merge_request_user_disable_origin.id_persistent,
+ merge_request_user_disable_origin.assigned_to,
+ )
+ assert merge_request.state == TagMergeRequest.MERGED
+ instances = list(
+ TagInstance.objects.filter( # pylint: disable=no-member
+ id_tag_definition_persistent=merge_request_user_disable_origin.id_destination_persistent
+ )
+ )
+ assert len(instances) == 0
+ assert TagDefinition.most_recent_by_id(
+ merge_request_user_disable_origin.id_origin_persistent
+ ).disabled
+
+
def test_incomplete_resolution_stays_open_keep(
merge_request_user, conflict_resolution_keep
):
diff --git a/tests/person/api/conversion_test.py b/tests/person/api/conversion_test.py
index deb0daf8..e3f210f2 100644
--- a/tests/person/api/conversion_test.py
+++ b/tests/person/api/conversion_test.py
@@ -154,11 +154,12 @@ def test_conversion_db_to_api_tag_def_in_cache():
cache_display_txt = "cache display_txt"
id_entity_persistent = "873eccfb-cf6c-4ade-bdb4-5aae8f9668e2"
cache_tag_def = {
- "id_persistent": ct.id_tag_persistent_test,
+ "id_persistent": ct.id_tag_def_persistent_test,
"id_parent_persistent": None,
"name": ct.name_tag_def_test,
"type": "STR",
"hidden": False,
+ "disabled": False,
"curated": True,
"owner": None,
"id": 500,
@@ -175,13 +176,14 @@ def test_conversion_db_to_api_tag_def_in_cache():
person_api_expected = api.PersonNatural(
display_txt=cache_display_txt,
display_txt_details={
- "id_persistent": ct.id_tag_persistent_test,
+ "id_persistent": ct.id_tag_def_persistent_test,
"id_parent_persistent": None,
"name": ct.name_tag_def_test,
"name_path": [ct.name_tag_def_test],
"type": "STRING",
"hidden": False,
"curated": True,
+ "disabled": False,
"owner": None,
"version": 500,
},
diff --git a/tests/tag/api/integration/conftest.py b/tests/tag/api/integration/conftest.py
index dd6d63ee..cdf24b07 100644
--- a/tests/tag/api/integration/conftest.py
+++ b/tests/tag/api/integration/conftest.py
@@ -17,7 +17,6 @@ def child_tag_def():
@pytest.fixture
def float_tag(tag_def_user, entity0):
- entity0.save()
return {
"value": "2.0",
"id_tag_definition_persistent": tag_def_user.id_persistent,
diff --git a/tests/tag/api/integration/get_ownership_requests_test.py b/tests/tag/api/integration/get_ownership_requests_test.py
index b290e54b..c11c40eb 100644
--- a/tests/tag/api/integration/get_ownership_requests_test.py
+++ b/tests/tag/api/integration/get_ownership_requests_test.py
@@ -55,6 +55,7 @@ def test_get_request(auth_server, ownership_request_curated, ownership_request_u
"name_path": [c.name_tag_def_curated_test],
"owner": None,
"hidden": False,
+ "disabled": False,
},
"id_persistent": c.id_ownership_request_curated_test,
}
@@ -80,6 +81,7 @@ def test_get_request(auth_server, ownership_request_curated, ownership_request_u
"name_path": [c.name_tag_def_test_user],
"owner": cu.test_username,
"hidden": False,
+ "disabled": False,
},
"id_persistent": c.id_ownership_request_test,
}
@@ -122,6 +124,7 @@ def test_get_request_commissioner(
"name_path": [c.name_tag_def_curated_test],
"owner": None,
"hidden": False,
+ "disabled": False,
},
"id_persistent": c.id_ownership_request_curated_test,
}
diff --git a/tests/tag/api/integration/post_tag_def_children_test.py b/tests/tag/api/integration/post_tag_def_children_test.py
index 6da06768..16f44c9d 100644
--- a/tests/tag/api/integration/post_tag_def_children_test.py
+++ b/tests/tag/api/integration/post_tag_def_children_test.py
@@ -1,9 +1,10 @@
-# pylint: disable=missing-module-docstring, missing-function-docstring,redefined-outer-name,invalid-name
+# pylint: disable=missing-module-docstring, missing-function-docstring,redefined-outer-name,invalid-name,unused-argument
from unittest.mock import MagicMock, patch
from django.db import DatabaseError
from tests.tag.api.integration import requests as r
+from tests.utils import assert_versioned, sort_versioned
def test_empty_db(auth_server):
@@ -36,9 +37,10 @@ def test_multi_root(auth_server, root_tag_def):
req = r.post_tag_def_children(live_server.url, None, cookies=cookies)
assert req.status_code == 200
tag_definitions = req.json()["tag_definitions"]
- assert len(tag_definitions) == 2
- assert tag_definitions[0] == root_tag_def_rsps[0]
- assert tag_definitions[1] == root_tag_def_rsps[1]
+ assert_versioned(
+ sort_versioned(tag_definitions),
+ sort_versioned(root_tag_def_rsps),
+ )
def test_single_child(auth_server, root_tag_def, child_tag_def):
@@ -77,12 +79,17 @@ def test_multi_child(auth_server, root_tag_def, child_tag_def):
)
assert req.status_code == 200
tag_definitions = req.json()["tag_definitions"]
- assert len(tag_definitions) == 2
- assert tag_definitions[0] == child_tag_def_rsps[0]
- assert tag_definitions[1] == child_tag_def_rsps[1]
+ assert sort_versioned(tag_definitions) == sort_versioned(child_tag_def_rsps)
+
+
+def test_does_not_include_disabled(auth_server, tag_def_disabled):
+ live_server, cookies = auth_server
+ rsp = r.post_tag_def_children(live_server.url, None, cookies=cookies)
+ assert rsp.status_code == 200
+ assert rsp.json() == {"tag_definitions": []}
-def test_multi_child_no_disabled(auth_server, root_tag_def, child_tag_def):
+def test_multi_child_include_hidden_for_owner(auth_server, root_tag_def, child_tag_def):
live_server, cookies = auth_server
req = r.post_tag_def(live_server.url, root_tag_def, cookies=cookies)
assert req.status_code == 200
@@ -95,19 +102,46 @@ def test_multi_child_no_disabled(auth_server, root_tag_def, child_tag_def):
)
assert req.status_code == 200
child_tag_def_rsps = req.json()["tag_definitions"]
+ assert len(child_tag_def_rsps) == 2
req = r.post_tag_def_children(
live_server.url, root_tag_def_rsp_id_persistent, cookies=cookies
)
assert req.status_code == 200
tag_definitions = req.json()["tag_definitions"]
- assert tag_definitions == [child_tag_def_rsps[0]]
+ assert_versioned(
+ sort_versioned(tag_definitions), sort_versioned(child_tag_def_rsps)
+ )
+
+
+def test_multi_child_exclude_hidden_for_non_owner(
+ auth_server1, root_tag_def, child_tag_def
+):
+ live_server, cookies, cookies1 = auth_server1
+ req = r.post_tag_def(live_server.url, root_tag_def, cookies=cookies)
+ assert req.status_code == 200
+ root_tag_def_rsp_id_persistent = req.json()["tag_definitions"][0]["id_persistent"]
+ child_tag_def["id_parent_persistent"] = root_tag_def_rsp_id_persistent
+ child_tag_def1 = child_tag_def.copy()
+ child_tag_def1["hidden"] = True
+ req = r.post_tag_defs(
+ live_server.url, [child_tag_def, child_tag_def1], cookies=cookies
+ )
+ assert req.status_code == 200
+ child_tag_def_rsps = req.json()["tag_definitions"]
+ assert len(child_tag_def_rsps) == 2
+ req = r.post_tag_def_children(
+ live_server.url, root_tag_def_rsp_id_persistent, cookies=cookies1
+ )
+ assert req.status_code == 200
+ tag_definitions = req.json()["tag_definitions"]
+ assert_versioned(tag_definitions, [child_tag_def_rsps[0]])
def test_bad_db(auth_server):
live_server, cookies = auth_server
mock = MagicMock()
mock.side_effect = DatabaseError()
- with patch("vran.tag.models_django.TagDefinition.most_recent_children", mock):
+ with patch("vran.tag.models_django.TagDefinition.children_query_set", mock):
req = r.post_tag_def_children(live_server.url, None, cookies=cookies)
assert req.status_code == 500
assert req.json()["msg"] == "Database Error."
diff --git a/tests/tag/api/integration/post_tag_defs_test.py b/tests/tag/api/integration/post_tag_defs_test.py
index 00491597..ddf606e8 100644
--- a/tests/tag/api/integration/post_tag_defs_test.py
+++ b/tests/tag/api/integration/post_tag_defs_test.py
@@ -127,7 +127,7 @@ def test_bad_db(auth_server, root_tag_def):
live_server, cookies = auth_server
mock = MagicMock()
mock.side_effect = IntegrityError()
- with patch("vran.tag.models_django.TagDefinition.save", mock):
+ with patch("vran.tag.models_django.TagDefinitionHistory.save", mock):
req = r.post_tag_def(live_server.url, root_tag_def, cookies=cookies)
assert req.status_code == 500
assert req.json()["msg"] == "Provided data not consistent with database."
diff --git a/tests/tag/api/integration/post_tag_instance_chunks_test.py b/tests/tag/api/integration/post_tag_instance_chunks_test.py
index c5f44e42..d2e28639 100644
--- a/tests/tag/api/integration/post_tag_instance_chunks_test.py
+++ b/tests/tag/api/integration/post_tag_instance_chunks_test.py
@@ -11,7 +11,6 @@
def test_empty_chunk(auth_server, tag_def):
- tag_def.save()
live_server, cookies = auth_server
rsp = post_tag_instance_chunks(
live_server.url, tag_def.id_persistent, 0, 20, cookies=cookies
@@ -64,7 +63,6 @@ def test_can_slice(auth_server, tag_def_user, entity0):
def test_non_existent_slice(auth_server, tag_def, entity0):
live_server, cookies = auth_server
- tag_def.save()
entity0.save()
instances = [
{
diff --git a/tests/tag/api/integration/post_tag_instances_test.py b/tests/tag/api/integration/post_tag_instances_test.py
index b91c60c6..0343937d 100644
--- a/tests/tag/api/integration/post_tag_instances_test.py
+++ b/tests/tag/api/integration/post_tag_instances_test.py
@@ -33,6 +33,20 @@ def test_no_id_version(auth_server, float_tag):
)
+def test_disabled_tag(auth_server, tag_def_disabled, entity0):
+ live_server, cookies = auth_server
+ req = r.post_tag_instance(
+ live_server.url,
+ {
+ "id_tag_definition_persistent": tag_def_disabled.id_persistent,
+ "id_entity_persistent": entity0.id_persistent,
+ "value": "some_value",
+ },
+ cookies=cookies,
+ )
+ assert req.status_code == 403
+
+
def test_concurrent_modification(auth_server, float_tag):
live_server, cookies = auth_server
req = r.post_tag_instance(live_server.url, float_tag, cookies=cookies)
@@ -114,7 +128,6 @@ def test_no_tag_def(auth_server, entity0):
def test_no_entity(auth_server, tag_def):
live_server, cookies = auth_server
- tag_def.save()
tag_inst = {
"value": "2.0",
"id_tag_definition_persistent": tag_def.id_persistent,
diff --git a/tests/tag/common.py b/tests/tag/common.py
index 39b91c05..e63580af 100644
--- a/tests/tag/common.py
+++ b/tests/tag/common.py
@@ -4,7 +4,9 @@
name_tag_def_test = "name tag test"
name_tag_def_test_user = "name tag test_user"
name_tag_def_test1 = "name tag test1"
+name_tag_def_parent_test = "tag_def_parent_test"
name_tag_def_curated_test = "name curated tag test"
+name_tag_def_disabled_test = "name tag def disabled test"
time_edit_test = datetime(2022, 12, 20, tzinfo=timezone.utc)
time_edit_test1 = datetime(2022, 12, 21, tzinfo=timezone.utc)
time_edit_curated_test = datetime(2022, 12, 22, tzinfo=timezone.utc)
@@ -12,11 +14,12 @@
id_tag_def_persistent_test = "b17463e5-8f95-4b12-bc31-b469030f813a"
id_tag_def_parent_persistent_test = "5a682460-9a91-414e-8c87-b5e1cb00dd97"
id_tag_persistent_test = "934e25f9-ebc4-4fcb-97ea-a33c4186bfc3"
-id_tag_def_persistent_test_user = "934e25f9-ebc4-4fcb-97ea-a33c4186bfc3"
+id_tag_def_persistent_test_user = "e37a05ca-d5f1-4bff-ba6f-d2f3a1f45e76"
id_tag_def_persistent_test_user1 = "52d5de0a-2fdb-457f-80d0-6e10131ad1b9"
id_tag_def_persistent_child_0 = "f2a2e623-404d-494c-9f6d-3436f5d0ad48"
id_tag_def_persistent_child_1 = "e0a3ec8d-3365-4979-8e51-6fcc3e445afd"
id_tag_def_curated_test = "2ec43995-338b-4f4b-b1cc-4bfc71466fc5"
+id_tag_def_disabled_test = "6698156c-a425-40d1-b792-014d81ca216f"
id_instance_test0 = "efee09fd-cee7-402f-8e8e-6ca790352e41"
id_instance_test1 = "3f7f1a90-cf62-4b73-8dee-8982bd422edf"
id_instance_test2 = "602364a9-1e75-4c93-833d-1c4fa0296f04"
diff --git a/tests/tag/conftest.py b/tests/tag/conftest.py
index 62881324..7b9e1b79 100644
--- a/tests/tag/conftest.py
+++ b/tests/tag/conftest.py
@@ -5,24 +5,36 @@
import tests.entity.common as ce
import tests.tag.common as c
-from vran.tag.models_django import OwnershipRequest, TagDefinition, TagInstanceHistory
+from vran.tag.models_django import (
+ OwnershipRequest,
+ TagDefinition,
+ TagDefinitionHistory,
+ TagInstanceHistory,
+)
@pytest.fixture
-def tag_def():
+def tag_def_history(db):
"Shared tag definition for tests."
- return TagDefinition(
+ tag_def, _ = TagDefinitionHistory.change_or_create(
id_persistent=c.id_tag_def_persistent_test,
type=TagDefinition.FLOAT,
id_parent_persistent=None,
name=c.name_tag_def_test,
time_edit=c.time_edit_test,
)
+ tag_def.save()
+ return tag_def
+
+
+@pytest.fixture
+def tag_def(tag_def_history):
+ return TagDefinition.objects.get(id=tag_def_history.id) # pylint: disable=no-member
@pytest.fixture
-def tag_def_user(user):
- tag_def = TagDefinition( # pylint: disable=no-member
+def tag_def_user_history(user):
+ tag_def = TagDefinitionHistory( # pylint: disable=no-member
id_persistent=c.id_tag_def_persistent_test_user,
type=TagDefinition.FLOAT,
id_parent_persistent=None,
@@ -34,9 +46,16 @@ def tag_def_user(user):
return tag_def
+@pytest.fixture
+def tag_def_user(tag_def_user_history):
+ return TagDefinition.objects.get( # pylint: disable=no-member
+ id=tag_def_user_history.id
+ )
+
+
@pytest.fixture
def tag_def_user1(user):
- tag_def = TagDefinition( # pylint: disable=no-member
+ tag_def = TagDefinitionHistory( # pylint: disable=no-member
id_persistent=c.id_tag_def_persistent_test_user1,
type=TagDefinition.FLOAT,
id_parent_persistent=None,
@@ -50,10 +69,10 @@ def tag_def_user1(user):
@pytest.fixture
def tag_def_parent(db):
- tag_def = TagDefinition(
+ tag_def = TagDefinitionHistory(
id_persistent=c.id_tag_def_parent_persistent_test,
type=TagDefinition.FLOAT,
- name="tag_def_parent_test",
+ name=c.name_tag_def_parent_test,
time_edit=c.time_edit_test + timedelta(seconds=5),
)
tag_def.save()
@@ -61,33 +80,51 @@ def tag_def_parent(db):
@pytest.fixture
-def tag_def_child_0():
+def tag_def_child_0_history():
"A shared child tag definition for tests"
- return TagDefinition(
+ tag_def, _ = TagDefinitionHistory.change_or_create(
id_persistent=c.id_tag_def_persistent_child_0,
type=TagDefinition.FLOAT,
id_parent_persistent=c.id_tag_def_parent_persistent_test,
name="test tag definition child 0",
time_edit=c.time_edit_test + timedelta(seconds=10),
)
+ tag_def.save()
+ return tag_def
@pytest.fixture
-def tag_def_child_1():
+def tag_def_child_0(tag_def_child_0_history):
+ return TagDefinition.objects.get( # pylint: disable=no-member
+ id=tag_def_child_0_history.id
+ )
+
+
+@pytest.fixture
+def tag_def_child_1_history():
"Another shared child tag definition for tests"
- return TagDefinition(
+ tag_def, _ = TagDefinitionHistory.change_or_create(
id_persistent=c.id_tag_def_persistent_child_1,
type=TagDefinition.FLOAT,
id_parent_persistent=c.id_tag_def_parent_persistent_test,
name="test tag definition child 1",
time_edit=c.time_edit_test + timedelta(seconds=10),
)
+ tag_def.save()
+ return tag_def
+
+
+@pytest.fixture
+def tag_def_child_1(tag_def_child_1_history):
+ return TagDefinition.objects.get( # pylint: disable=no-member
+ id=tag_def_child_1_history.id
+ )
@pytest.fixture
def tag_def_curated():
"A curated tag definition for tests"
- return TagDefinition.objects.create( # pylint: disable=no-member
+ return TagDefinitionHistory.objects.create( # pylint: disable=no-member
id_persistent=c.id_tag_def_curated_test,
type=TagDefinition.INNER,
name=c.name_tag_def_curated_test,
diff --git a/tests/tag/models_django_definitions_test.py b/tests/tag/models_django_definitions_test.py
index da3e75ff..6a408274 100644
--- a/tests/tag/models_django_definitions_test.py
+++ b/tests/tag/models_django_definitions_test.py
@@ -1,4 +1,4 @@
-# pylint: disable=missing-module-docstring, missing-function-docstring,redefined-outer-name,invalid-name,unused-argument
+# pylint: disable=missing-module-docstring, missing-function-docstring,redefined-outer-name,invalid-name,unused-argument,protected-access
from datetime import timedelta
import pytest
@@ -9,72 +9,73 @@
NoParentTagException,
TagDefinitionExistsException,
)
-from vran.tag.models_django import TagDefinition
+from vran.tag.models_django import TagDefinition, TagDefinitionHistory
from vran.util import timestamp
@pytest.mark.django_db
-def test_different_name(tag_def):
- tag_def1 = TagDefinition(
- id_persistent=tag_def.id_persistent,
- time_edit=tag_def.time_edit,
+def test_different_name(tag_def_history):
+ tag_def1 = TagDefinitionHistory(
+ id_persistent=tag_def_history.id_persistent,
+ time_edit=tag_def_history.time_edit,
name="changed tag name",
- type=tag_def.type,
+ type=tag_def_history.type,
)
- assert tag_def.check_different_before_save(tag_def1)
- assert tag_def1.check_different_before_save(tag_def)
+ assert tag_def_history.check_different_before_save(tag_def1)
+ assert tag_def1.check_different_before_save(tag_def_history)
@pytest.mark.django_db
-def test_different_id_parent(tag_def):
- tag_def1 = TagDefinition(
- id_persistent=tag_def.id_persistent,
- time_edit=tag_def.time_edit,
+def test_different_id_parent(tag_def_history):
+ tag_def1 = TagDefinitionHistory(
+ id_persistent=tag_def_history.id_persistent,
+ time_edit=tag_def_history.time_edit,
id_parent_persistent=c.id_tag_def_parent_persistent_test,
name=c.name_tag_def_test,
- type=tag_def.type,
+ type=tag_def_history.type,
)
- assert tag_def.check_different_before_save(tag_def1)
- assert tag_def1.check_different_before_save(tag_def)
+ assert tag_def_history.check_different_before_save(tag_def1)
+ assert tag_def1.check_different_before_save(tag_def_history)
@pytest.mark.django_db
-def test_different_type(tag_def):
- tag_def1 = TagDefinition(
- id_persistent=tag_def.id_persistent,
- time_edit=tag_def.time_edit,
+def test_different_type(tag_def_history):
+ tag_def1 = TagDefinitionHistory(
+ id_persistent=tag_def_history.id_persistent,
+ time_edit=tag_def_history.time_edit,
name=c.name_tag_def_test,
type=TagDefinition.INNER,
)
- assert tag_def.check_different_before_save(tag_def1)
- assert tag_def1.check_different_before_save(tag_def)
+ assert tag_def_history.check_different_before_save(tag_def1)
+ assert tag_def1.check_different_before_save(tag_def_history)
@pytest.mark.django_db
-def test_same(tag_def):
- tag_def1 = TagDefinition(
- id_persistent=tag_def.id_persistent,
- time_edit=tag_def.time_edit,
+def test_same(tag_def_history):
+ tag_def1 = TagDefinitionHistory(
+ id_persistent=tag_def_history.id_persistent,
+ time_edit=tag_def_history.time_edit,
name=c.name_tag_def_test,
type=TagDefinition.FLOAT,
)
- assert not tag_def.check_different_before_save(tag_def1)
- assert not tag_def1.check_different_before_save(tag_def)
+ assert not tag_def_history.check_different_before_save(tag_def1)
+ assert not tag_def1.check_different_before_save(tag_def_history)
@pytest.mark.django_db
-def test_store_and_retrieve_tag_def(tag_def):
- tag_def.save()
+def test_store_and_retrieve_tag_def(tag_def_history):
+ tag_def_history.save()
retrieved = TagDefinition.objects.get( # pylint: disable=no-member
name=c.name_tag_def_test
)
- assert retrieved == tag_def
+ assert retrieved.id == tag_def_history.id
+ assert not tag_def_history.check_different_before_save(retrieved)
@pytest.mark.django_db
def test_missing_parent():
with pytest.raises(NoParentTagException) as exc:
- TagDefinition.change_or_create(
+ TagDefinitionHistory.change_or_create(
c.id_tag_def_persistent_test,
c.time_edit_test,
c.name_tag_def_test,
@@ -84,11 +85,11 @@ def test_missing_parent():
@pytest.mark.django_db
-def test_valid_parent_same_name(tag_def):
- tag_def.id_persistent = c.id_tag_def_parent_persistent_test
- tag_def.type = TagDefinition.INNER
- tag_def.save()
- ret, _ = TagDefinition.change_or_create(
+def test_valid_parent_same_name(tag_def_history):
+ tag_def_history.id_persistent = c.id_tag_def_parent_persistent_test
+ tag_def_history.type = TagDefinition.INNER
+ tag_def_history.save()
+ ret, _ = TagDefinitionHistory.change_or_create(
c.id_tag_def_persistent_test,
c.time_edit_test,
c.name_tag_def_test,
@@ -99,10 +100,9 @@ def test_valid_parent_same_name(tag_def):
@pytest.mark.django_db
def test_tag_exists_root(tag_def):
- tag_def.save()
with pytest.raises(TagDefinitionExistsException) as exc:
- TagDefinition.change_or_create(
+ TagDefinitionHistory.change_or_create(
None,
c.time_edit_test,
c.name_tag_def_test,
@@ -114,11 +114,8 @@ def test_tag_exists_root(tag_def):
@pytest.mark.django_db
-def test_tag_exists_child(tag_def):
- tag_def.id_persistent = c.id_tag_def_parent_persistent_test
- tag_def.type = TagDefinition.INNER
- tag_def.save()
- old, _ = TagDefinition.change_or_create(
+def test_tag_exists_child(tag_def_parent):
+ old, _ = TagDefinitionHistory.change_or_create(
c.id_tag_def_persistent_test,
c.time_edit_test,
c.name_tag_def_test,
@@ -127,7 +124,7 @@ def test_tag_exists_child(tag_def):
old.save()
with pytest.raises(TagDefinitionExistsException) as exc:
- TagDefinition.change_or_create(
+ TagDefinitionHistory.change_or_create(
"other_tag_def_id_test",
c.time_edit_test,
c.name_tag_def_test,
@@ -139,23 +136,17 @@ def test_tag_exists_child(tag_def):
@pytest.mark.django_db
-def test_tag_exists_rename(tag_def):
- tag_def.type = TagDefinition.INNER
- tag_def.id_persistent = c.id_tag_def_parent_persistent_test
- tag_def.save()
- TagDefinition.change_or_create(
- c.id_tag_def_persistent_test,
- c.time_edit_test,
- c.name_tag_def_test,
- c.id_tag_def_parent_persistent_test,
- )
+def test_tag_exists_rename(tag_def, tag_def_user):
with pytest.raises(TagDefinitionExistsException) as exc:
- TagDefinition.change_or_create(
- c.id_tag_def_persistent_test, c.time_edit_test, c.name_tag_def_test, None
+ TagDefinitionHistory.change_or_create(
+ c.id_tag_def_persistent_test,
+ c.time_edit_test,
+ c.name_tag_def_test_user,
+ None,
)
- assert exc.value.args[0] == c.name_tag_def_test
- assert exc.value.args[1] == c.id_tag_def_parent_persistent_test
+ assert exc.value.args[0] == c.name_tag_def_test_user
+ assert exc.value.args[1] == c.id_tag_def_persistent_test_user
assert exc.value.args[2] is None
@@ -174,7 +165,7 @@ def test_float_check_invalid(tag_def):
@pytest.mark.django_db
-def test_strint_check_valid(tag_def):
+def test_string_check_valid(tag_def):
tag_def.type = TagDefinition.STRING
tag_def.check_value("foo")
@@ -212,61 +203,50 @@ def test_inner_check_invalid(tag_def):
@pytest.mark.django_db
-def test_childrens(tag_def, tag_def_child_0, tag_def_child_1):
- tag_def.type = TagDefinition.INNER
- tag_def.id_persistent = c.id_tag_def_parent_persistent_test
- tag_def.save()
- tag_def_child_0.save()
- tag_def_child_1.save()
- ret = TagDefinition.most_recent_children(c.id_tag_def_parent_persistent_test)
- assert ret == [tag_def_child_0, tag_def_child_1]
+def test_childrens(tag_def_parent, tag_def_child_0, tag_def_child_1):
+ ret = TagDefinition.children_query_set(c.id_tag_def_parent_persistent_test)
+ assert set(ret) == {tag_def_child_0, tag_def_child_1}
@pytest.mark.django_db
-def test_children_updated(tag_def, tag_def_child_0, tag_def_child_1):
- tag_def.type = TagDefinition.INNER
- tag_def.id_persistent = c.id_tag_def_parent_persistent_test
- tag_def.save()
- tag_def_child_0.save()
- tag_def_child_1.save()
- tag_def_child_0_updated = TagDefinition(
+def test_children_updated(tag_def_parent, tag_def_child_0, tag_def_child_1):
+ tag_def_child_0_updated_history, _ = TagDefinitionHistory.change_or_create(
id_persistent=tag_def_child_0.id_persistent,
type=TagDefinition.FLOAT,
id_parent_persistent=c.id_tag_def_parent_persistent_test,
name=tag_def_child_0.name + "modified",
time_edit=tag_def_child_0.time_edit + timedelta(seconds=10),
- previous_version=tag_def_child_0,
+ version=tag_def_child_0.id,
+ )
+ tag_def_child_0_updated_history.save()
+ tag_def_child_0_updated = TagDefinition.objects.get( # pylint: disable=no-member
+ id=tag_def_child_0_updated_history.id
)
- tag_def_child_0_updated.save()
- ret = TagDefinition.most_recent_children(c.id_tag_def_parent_persistent_test)
- assert ret == [tag_def_child_1, tag_def_child_0_updated]
+ ret = TagDefinition.children_query_set(c.id_tag_def_parent_persistent_test)
+ assert set(ret) == {tag_def_child_1, tag_def_child_0_updated}
@pytest.mark.django_db
-def test_children_empty(tag_def):
- tag_def.type = TagDefinition.INNER
- tag_def.save()
- ret = TagDefinition.most_recent_children(c.id_tag_def_parent_persistent_test)
+def test_children_empty(tag_def_parent):
+ ret = TagDefinition.children_query_set(c.id_tag_def_parent_persistent_test)
assert not ret
@pytest.mark.django_db
def test_children_root(tag_def):
- tag_def.save()
- ret = TagDefinition.most_recent_children(None)
- assert ret == [tag_def]
+ ret = TagDefinition.children_query_set(None)
+ assert list(ret) == [tag_def]
@pytest.mark.django_db
def test_only_for_user(tag_def_user, tag_def):
- tag_def.save()
ret = TagDefinition.for_user(tag_def_user.owner).get()
assert ret == tag_def_user
@pytest.mark.django_db
def test_most_recent_for_user(tag_def_user):
- tag_def_edited, _ = TagDefinition.change_or_create(
+ tag_def_edited, _ = TagDefinitionHistory.change_or_create(
id_persistent=tag_def_user.id_persistent,
id_parent_persistent=None,
time_edit=timestamp(),
@@ -276,13 +256,13 @@ def test_most_recent_for_user(tag_def_user):
)
tag_def_edited.save()
ret = TagDefinition.for_user(tag_def_user.owner).get()
- assert ret == tag_def_edited
+ assert ret._get_history_entry() == tag_def_edited
@pytest.mark.django_db
def test_can_create_hidden():
- tag_def, _ = TagDefinition.change_or_create(
- id_persistent=c.id_tag_persistent_test,
+ tag_def, _ = TagDefinitionHistory.change_or_create(
+ id_persistent=c.id_tag_def_persistent_test,
id_parent_persistent=None,
time_edit=timestamp(),
name="new_name",
@@ -290,5 +270,5 @@ def test_can_create_hidden():
hidden=True,
)
tag_def.save()
- retrieved = TagDefinition.most_recent_by_id(c.id_tag_persistent_test)
+ retrieved = TagDefinition.most_recent_by_id(c.id_tag_def_persistent_test)
assert retrieved.hidden
diff --git a/tests/tag/models_django_instance_test.py b/tests/tag/models_django_instance_test.py
index c68fb719..bcd90aa0 100644
--- a/tests/tag/models_django_instance_test.py
+++ b/tests/tag/models_django_instance_test.py
@@ -7,10 +7,11 @@
import tests.tag.common as c
from vran.exception import (
EntityMissingException,
+ TagDefinitionDisabledException,
TagDefinitionMissingException,
TagDefinitionPermissionException,
)
-from vran.tag.models_django import TagDefinition, TagInstance, TagInstanceHistory
+from vran.tag.models_django import TagInstance, TagInstanceHistory
@pytest.fixture
@@ -129,10 +130,23 @@ def test_tag_def_missing(entity0, user):
assert exc.value.args[0] == c.id_tag_def_persistent_test
+@pytest.mark.django_db
+def test_disabled_tag(tag_def_disabled, entity0):
+ id_persistent = "7693b6cd-b0da-4207-adc1-e15f367b010a"
+ with pytest.raises(TagDefinitionDisabledException):
+ TagInstanceHistory.change_or_create(
+ id_persistent=id_persistent,
+ id_tag_definition_persistent=tag_def_disabled.id_persistent,
+ id_entity_persistent=entity0.id_persistent,
+ value="some value",
+ user=tag_def_disabled.owner,
+ time_edit=c.time_edit_test,
+ )
+
+
@pytest.mark.django_db
def test_tag_def_no_permission(entity0, tag_def_user, user1):
entity0.save()
- tag_def_user.save()
with pytest.raises(TagDefinitionPermissionException) as exc:
TagInstanceHistory.change_or_create(
id_persistent=c.id_tag_persistent_test,
@@ -142,42 +156,12 @@ def test_tag_def_no_permission(entity0, tag_def_user, user1):
id_entity_persistent=entity0.id_persistent,
id_tag_definition_persistent=c.id_tag_def_persistent_test_user,
)
- assert exc.value.args[0] == tag_def_user
+ assert exc.value.args[0] == tag_def_user.id_persistent
@pytest.mark.django_db
def test_add_tag_root(entity0, tag_def_user):
entity0.save()
- tag_def_user.save()
- ret, _ = TagInstanceHistory.change_or_create(
- id_persistent=c.id_tag_persistent_test,
- time_edit=c.time_edit_test,
- user=tag_def_user.owner,
- id_entity_persistent=entity0.id_persistent,
- id_tag_definition_persistent=tag_def_user.id_persistent,
- value="2.0",
- )
- assert ret.value == "2.0"
- assert ret.id_persistent == c.id_tag_persistent_test
- assert ret.id_entity_persistent == entity0.id_persistent
- assert ret.id_tag_definition_persistent == tag_def_user.id_persistent
- assert ret.time_edit == c.time_edit_test
- assert ret.previous_version is None
-
-
-@pytest.mark.django_db
-def test_add_tag_child(entity0, tag_def_user):
- parent_tag, _ = TagDefinition.change_or_create(
- id_persistent=c.id_tag_def_parent_persistent_test,
- id_parent_persistent=None,
- time_edit=c.time_edit_test,
- name=c.name_tag_def_test,
- type=TagDefinition.INNER,
- )
- parent_tag.save()
- entity0.save()
- tag_def_user.id_parent_persistent = c.id_tag_def_parent_persistent_test
- tag_def_user.save()
ret, _ = TagInstanceHistory.change_or_create(
id_persistent=c.id_tag_persistent_test,
time_edit=c.time_edit_test,
@@ -196,14 +180,12 @@ def test_add_tag_child(entity0, tag_def_user):
@pytest.mark.django_db
def test_empty_chunk(tag_def):
- tag_def.save()
ret = TagInstance.by_tag_chunked(tag_def.id_persistent, 2, 3)
assert ret == []
@pytest.mark.django_db
def test_chunk_versions(tag_def):
- tag_def.save()
last_values = []
last_ids = []
for i in range(10):
@@ -229,7 +211,6 @@ def test_chunk_versions(tag_def):
@pytest.mark.django_db
def test_chunk_filter_tag_instance(tag_def):
- tag_def.save()
for i in range(10):
tag = TagInstanceHistory(
id_persistent=f"id_tag_test{i}",
diff --git a/tests/tag/queue_test.py b/tests/tag/queue_test.py
index c7dfe9e0..28c533fe 100644
--- a/tests/tag/queue_test.py
+++ b/tests/tag/queue_test.py
@@ -1,4 +1,4 @@
-# pylint: disable=missing-module-docstring, missing-function-docstring,redefined-outer-name,invalid-name
+# pylint: disable=missing-module-docstring, missing-function-docstring,redefined-outer-name,invalid-name,unused-argument
from unittest.mock import MagicMock, call, patch
import pytest
@@ -24,8 +24,6 @@ def test_name_as_default_path_and_enqueues(tag_def_user):
def test_enqueues_children(tag_def_parent, tag_def_child_0, tag_def_child_1):
- tag_def_child_0.save()
- tag_def_child_1.save()
mock = MagicMock()
with patch("vran.tag.queue.enqueue", mock):
q.update_tag_definition_name_path(tag_def_parent.id_persistent)
@@ -44,13 +42,13 @@ def test_enqueues_children(tag_def_parent, tag_def_child_0, tag_def_child_1):
tag_def_child_1.id_persistent,
[tag_def_parent.name],
),
- ]
+ ],
+ any_order=True,
)
@pytest.mark.django_db
-def test_uses_provided_parent_path(tag_def_child_0):
- tag_def_child_0.save()
+def test_uses_provided_parent_path(tag_def_parent, tag_def_child_0):
q.update_tag_definition_name_path(
tag_def_child_0.id_persistent, ["name", "path", "parent", "test"]
)
diff --git a/tests/user/conftest.py b/tests/user/conftest.py
index f53379ce..cc0d1811 100644
--- a/tests/user/conftest.py
+++ b/tests/user/conftest.py
@@ -2,12 +2,12 @@
import pytest
import tests.user.common as c
-from vran.tag.models_django import TagDefinition
+from vran.tag.models_django import TagDefinition, TagDefinitionHistory
@pytest.fixture
def tag_def_user_profile():
- return TagDefinition.objects.create(
+ return TagDefinitionHistory.objects.create(
name=c.name_tag_def,
id_persistent=c.id_tag_def_persistent,
time_edit=c.time_edit_tag_def,
@@ -17,7 +17,7 @@ def tag_def_user_profile():
@pytest.fixture
def tag_def_user_profile1():
- return TagDefinition.objects.create(
+ return TagDefinitionHistory.objects.create(
name=c.name_tag_def1,
id_persistent=c.id_tag_def_persistent1,
time_edit=c.time_edit_tag_def1,
@@ -27,7 +27,7 @@ def tag_def_user_profile1():
@pytest.fixture
def tag_def_user_profile2():
- return TagDefinition.objects.create(
+ return TagDefinitionHistory.objects.create(
name=c.name_tag_def2,
id_persistent=c.id_tag_def_persistent2,
time_edit=c.time_edit_tag_def2,
@@ -37,7 +37,7 @@ def tag_def_user_profile2():
@pytest.fixture
def tag_def_user_profile3():
- return TagDefinition.objects.create(
+ return TagDefinitionHistory.objects.create(
name=c.name_tag_def3,
id_persistent=c.id_tag_def_persistent3,
time_edit=c.time_edit_tag_def3,
diff --git a/tests/utils.py b/tests/utils.py
index 326319e4..7ef5f1ed 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -6,20 +6,31 @@ def format_datetime(datetime):
return datetime.isoformat() + "Z"
-def assert_versioned(actual, expected, path=None):
+def version_sort_key(dictionary):
+ "Sort key for sorting dicts according to entry with key 'version'"
+ return dictionary["version"]
+
+
+def sort_versioned(lst):
+ "Sort a list of dictionaries according to their entries with key 'version'"
+ return sorted(lst, key=version_sort_key)
+
+
+def assert_versioned(actual, expected, path=None, version_key="version"):
"""Helper function for checking nested dictionaries with version information.
- The actual value of the version is ignored, as it may change depending on test order."""
+ The actual value of the version is ignored, as it may change depending on test order.
+ """
if path is None:
path = []
if isinstance(actual, dict):
assert isinstance(expected, dict)
if len(actual) == len(expected) + 1:
- assert "version" in actual
- assert "version" not in expected
+ assert version_key in actual
+ assert version_key not in expected
else:
assert len(actual) == len(expected)
for key in actual:
- if key != "version":
+ if key != version_key:
assert_versioned(actual[key], expected[key], path + [key])
elif isinstance(actual, list):
assert isinstance(expected, list)
diff --git a/ui/src/App.tsx b/ui/src/App.tsx
index 331dd699..67fee11a 100644
--- a/ui/src/App.tsx
+++ b/ui/src/App.tsx
@@ -47,7 +47,7 @@ export function VranRoot() {
VrAN
-