Skip to content

Commit

Permalink
Merge branch 'issue_773'
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed May 20, 2024
2 parents e7e55ca + ff9eecd commit 3f7b966
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 38 deletions.
169 changes: 150 additions & 19 deletions tests/field_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import sys
import os
import io
import unittest
import collections

Expand Down Expand Up @@ -34,7 +33,11 @@ def test_create_with_simple_field(self):

# Create a node with a simple field of cardinality 1, no subdelimiters.
self.field_definitions = {
"field_foo": {"cardinality": 1, "formatted_text": False}
"field_foo": {
"cardinality": 1,
"formatted_text": False,
"field_type": "text",
}
}

field = workbench_fields.SimpleField()
Expand Down Expand Up @@ -79,7 +82,11 @@ def test_create_with_simple_field(self):

# Create a node with a simple field of cardinality unlimited, no subdelimiters.
self.field_definitions = {
"field_foo": {"cardinality": -1, "formatted_text": False}
"field_foo": {
"cardinality": -1,
"formatted_text": False,
"field_type": "text",
}
}

field = workbench_fields.SimpleField()
Expand Down Expand Up @@ -115,7 +122,11 @@ def test_create_with_simple_field(self):

# Create a node with a simple field of cardinality limited, no subdelimiters.
self.field_definitions = {
"field_foo": {"cardinality": 2, "formatted_text": False}
"field_foo": {
"cardinality": 2,
"formatted_text": False,
"field_type": "text",
}
}

field = workbench_fields.SimpleField()
Expand Down Expand Up @@ -164,6 +175,72 @@ def test_create_with_simple_field(self):
r"simple_006 would exceed maximum number of allowed values \(2\)",
)

def test_create_with_simple_integer_field(self):
existing_node = {
"type": [{"target_id": "islandora_object", "target_type": "node_type"}],
"title": [{"value": "Test node"}],
"status": [{"value": 1}],
}

# Create a node with a simple integer field of cardinality 1, no subdelimiters.
self.field_definitions = {
"field_int": {
"cardinality": 1,
"formatted_text": False,
"field_type": "integer",
}
}

field = workbench_fields.SimpleField()
csv_record = collections.OrderedDict()
csv_record["id"] = "simple_001_int"
csv_record["field_int"] = "5"
node = field.create(
self.config, self.field_definitions, existing_node, csv_record, "field_int"
)
expected_node = {
"type": [{"target_id": "islandora_object", "target_type": "node_type"}],
"title": [{"value": "Test node"}],
"status": [{"value": 1}],
"field_int": [{"value": 5}],
}
self.assertDictEqual(node, expected_node)

def test_create_with_simple_float_field(self):
existing_node = {
"type": [{"target_id": "islandora_object", "target_type": "node_type"}],
"title": [{"value": "Test node"}],
"status": [{"value": 1}],
}

# Create a node with a simple integer field of cardinality 1, no subdelimiters.
self.field_definitions = {
"field_float": {
"cardinality": 1,
"formatted_text": False,
"field_type": "float",
}
}

field = workbench_fields.SimpleField()
csv_record = collections.OrderedDict()
csv_record["id"] = "simple_001_int"
csv_record["field_float"] = "6.0"
node = field.create(
self.config,
self.field_definitions,
existing_node,
csv_record,
"field_float",
)
expected_node = {
"type": [{"target_id": "islandora_object", "target_type": "node_type"}],
"title": [{"value": "Test node"}],
"status": [{"value": 1}],
"field_float": [{"value": 6.0}],
}
self.assertDictEqual(node, expected_node)

def test_simple_field_title_update_replace(self):
# Update the node title, first with an 'update_mode' of replace.
existing_node = {
Expand All @@ -172,7 +249,9 @@ def test_simple_field_title_update_replace(self):
"status": [{"value": 1}],
}

self.field_definitions = {"title": {"cardinality": 1, "formatted_text": False}}
self.field_definitions = {
"title": {"cardinality": 1, "formatted_text": False, "field_type": "text"}
}

self.config["task"] = "update"
self.config["update_mode"] = "replace"
Expand Down Expand Up @@ -204,7 +283,9 @@ def test_simple_field_title_update_append(self):
"status": [{"value": 1}],
}

self.field_definitions = {"title": {"cardinality": 1, "formatted_text": False}}
self.field_definitions = {
"title": {"cardinality": 1, "formatted_text": False, "field_type": "text"}
}

self.config["task"] = "update"
self.config["update_mode"] = "append"
Expand Down Expand Up @@ -242,7 +323,11 @@ def test_simple_field_update_replace_cardinality_1_no_subdelims(self):
}

self.field_definitions = {
"field_foo": {"cardinality": 1, "formatted_text": False}
"field_foo": {
"cardinality": 1,
"formatted_text": False,
"field_type": "text",
}
}

self.config["task"] = "update"
Expand Down Expand Up @@ -277,7 +362,11 @@ def test_simple_field_update_append_cardinality_1_no_subdelims(self):
}

self.field_definitions = {
"field_foo": {"cardinality": 1, "formatted_text": False}
"field_foo": {
"cardinality": 1,
"formatted_text": False,
"field_type": "text",
}
}

self.config["task"] = "update"
Expand Down Expand Up @@ -317,7 +406,11 @@ def test_simple_field_update_replace_cardinality_1_with_subdelims(self):
}

self.field_definitions = {
"field_foo": {"cardinality": 1, "formatted_text": False}
"field_foo": {
"cardinality": 1,
"formatted_text": False,
"field_type": "text",
}
}

self.config["task"] = "update"
Expand Down Expand Up @@ -358,7 +451,11 @@ def test_simple_field_update_replace_cardinality_unlimited_no_subdelims(self):
}

self.field_definitions = {
"field_foo": {"cardinality": -1, "formatted_text": False}
"field_foo": {
"cardinality": -1,
"formatted_text": False,
"field_type": "text",
}
}

self.config["task"] = "update"
Expand Down Expand Up @@ -394,7 +491,11 @@ def test_simple_field_update_replace_cardinality_unlimited_with_subdelims(self):
}

self.field_definitions = {
"field_foo": {"cardinality": -1, "formatted_text": False}
"field_foo": {
"cardinality": -1,
"formatted_text": False,
"field_type": "text",
}
}

self.config["task"] = "update"
Expand Down Expand Up @@ -422,7 +523,11 @@ def test_simple_field_update_replace_cardinality_unlimited_with_subdelims(self):

def test_simple_field_update_append_cardinality_unlimited_no_subdelims(self):
self.field_definitions = {
"field_foo": {"cardinality": -1, "formatted_text": False}
"field_foo": {
"cardinality": -1,
"formatted_text": False,
"field_type": "text",
}
}

self.config["task"] = "update"
Expand Down Expand Up @@ -500,7 +605,11 @@ def test_simple_field_update_append_cardinality_unlimited_with_subdelims(self):
}

self.field_definitions = {
"field_foo": {"cardinality": -1, "formatted_text": False}
"field_foo": {
"cardinality": -1,
"formatted_text": False,
"field_type": "text",
}
}

self.config["task"] = "update"
Expand Down Expand Up @@ -539,7 +648,11 @@ def test_simple_field_update_replace_cardinality_limited_no_subdelims(self):
}

self.field_definitions = {
"field_foo": {"cardinality": 2, "formatted_text": False}
"field_foo": {
"cardinality": 2,
"formatted_text": False,
"field_type": "text",
}
}

self.config["task"] = "update"
Expand Down Expand Up @@ -577,7 +690,11 @@ def test_simple_field_update_append_cardinality_limited_no_subdelims(self):
}

self.field_definitions = {
"field_foo": {"cardinality": 2, "formatted_text": False}
"field_foo": {
"cardinality": 2,
"formatted_text": False,
"field_type": "text",
}
}

self.config["task"] = "update"
Expand Down Expand Up @@ -623,7 +740,11 @@ def test_simple_field_update_replace_cardinality_limited_with_subdelims(self):
}

self.field_definitions = {
"field_foo": {"cardinality": 2, "formatted_text": False}
"field_foo": {
"cardinality": 2,
"formatted_text": False,
"field_type": "text",
}
}

self.config["task"] = "update"
Expand Down Expand Up @@ -668,7 +789,11 @@ def test_simple_field_update_append_cardinality_limited_with_subdelims(self):
}

self.field_definitions = {
"field_foo": {"cardinality": 3, "formatted_text": False}
"field_foo": {
"cardinality": 3,
"formatted_text": False,
"field_type": "text",
}
}

self.config["task"] = "update"
Expand Down Expand Up @@ -717,7 +842,11 @@ def test_simple_field_update_delete(self):
}

self.field_definitions = {
"field_foo": {"cardinality": 3, "formatted_text": False}
"field_foo": {
"cardinality": 3,
"formatted_text": False,
"field_type": "text",
}
}

self.config["update_mode"] = "delete"
Expand Down Expand Up @@ -941,7 +1070,9 @@ def test_simple_field_title_update_replace(self):
"status": [{"value": 1}],
}

self.field_definitions = {"title": {"cardinality": 1, "formatted_text": False}}
self.field_definitions = {
"title": {"cardinality": 1, "formatted_text": False, "field_type": "text"}
}

self.config["task"] = "update"
self.config["update_mode"] = "replace"
Expand Down
5 changes: 5 additions & 0 deletions tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,11 @@ def test_value_is_numeric(self):
res = workbench_utils.value_is_numeric(value)
self.assertTrue(res, "Value " + str(value) + " is not numeric.")

values = ["200.23", "0.5", 999.999]
for value in values:
res = workbench_utils.value_is_numeric(value, allow_decimals=True)
self.assertTrue(res, "Value " + str(value) + " is not numeric.")

def test_value_is_not_numeric(self):
values = ["n200", False, "999-1000"]
for value in values:
Expand Down
Loading

0 comments on commit 3f7b966

Please sign in to comment.