Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anticipate v8 breaking change to TileModel.nodegroup #1565

Open
wants to merge 3 commits into
base: dev/2.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arches_for_science/management/commands/update_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ def handle_export(self, options):
path = self.get_inbound_path(node)

if options["count"] and graph.isresource:
c = archesmodels.TileModel.objects.filter(nodegroup=node.nodegroup).count()
c = archesmodels.TileModel.objects.filter(nodegroup_id=node.nodegroup.pk).count()
else:
c = -1
writer.writerow(
Expand Down
4 changes: 3 additions & 1 deletion arches_for_science/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@
"ENGINE": "django.contrib.gis.db.backends.postgis",
"HOST": "localhost",
"NAME": "arches_for_science",
"OPTIONS": {},
"OPTIONS": {
"options": "-c cursor_tuple_fraction=1",
},
"PASSWORD": "postgis",
"PORT": "5432",
"POSTGIS_TEMPLATE": "template_postgis",
Expand Down
16 changes: 8 additions & 8 deletions arches_for_science/views/analysis_area_and_sample_taking.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def save_node(self, request, resourceinstanceid, nodegroupid, nodeid, transactio
tile = Tile.objects.get(pk=tileid)
else:
try:
tile = Tile.objects.get(resourceinstance=resourceinstanceid, nodegroup=nodegroupid)
tile = Tile.objects.get(resourceinstance=resourceinstanceid, nodegroup_id=nodegroupid)
except ObjectDoesNotExist as e:
tile = Tile.get_blank_tile(nodeid=nodeid, resourceid=resourceinstanceid)
tile.data[nodeid] = nodevalue
Expand Down Expand Up @@ -73,7 +73,7 @@ def save_related_resource_node(
tile.data[nodeid][0]["resourceId"] = related_resourceid
else:
try:
tile = Tile.objects.get(resourceinstance=resourceinstanceid, nodegroup=nodeid)
tile = Tile.objects.get(resourceinstance=resourceinstanceid, nodegroup_id=nodeid)
except ObjectDoesNotExist as e:
tile = Tile.get_blank_tile(nodeid=nodeid, resourceid=resourceinstanceid)
related_resource_template = get_related_resource_template(related_resourceid, relationship_type, inverse_relationship_type)
Expand All @@ -100,7 +100,7 @@ def add_to_related_resource_list_tile(self, request, resourceinstanceid, nodeid,
tile = Tile.objects.get(pk=tileid)
else:
try:
tile = Tile.objects.get(resourceinstance=resourceinstanceid, nodegroup=nodeid)
tile = Tile.objects.get(resourceinstance=resourceinstanceid, nodegroup_id=nodeid)
except ObjectDoesNotExist as e:
tile = Tile.get_blank_tile(nodeid=nodeid, resourceid=resourceinstanceid)
tile.data[nodeid] = []
Expand All @@ -125,7 +125,7 @@ def save_physical_thing_name(self, request, resourceid, transactionid, name, til
tile = Tile.objects.get(pk=tileid)
else:
try:
tile = Tile.objects.get(resourceinstance=resourceid, nodegroup=physical_thing_name_nodegroupid)
tile = Tile.objects.get(resourceinstance=resourceid, nodegroup_id=physical_thing_name_nodegroupid)
except ObjectDoesNotExist as e:
tile = Tile.get_blank_tile(nodeid=physical_thing_name_nodeid, resourceid=resourceid)
tile.data[physical_thing_name_nodeid] = {}
Expand Down Expand Up @@ -294,7 +294,7 @@ def save_sampling_unit_tile(
else:
tile = None
try:
tiles = Tile.objects.filter(resourceinstance=sampling_activity_resourceid, nodegroup=sampling_unit_nodegroupid)
tiles = Tile.objects.filter(resourceinstance=sampling_activity_resourceid, nodegroup_id=sampling_unit_nodegroupid)
for t in tiles:
if t.data[sampling_area_nodeid][0]["resourceId"] == sample_area_physical_thing_resourceid:
tile = t
Expand Down Expand Up @@ -340,7 +340,7 @@ def save_sample_statement_tile(self, request, resourceid, statement, type, tilei
else:
tile = None
try:
tiles = Tile.objects.filter(resourceinstance=resourceid, nodegroup=statement_nodegroupid)
tiles = Tile.objects.filter(resourceinstance=resourceid, nodegroup_id=statement_nodegroupid)
for t in tiles:
if statement_types[type] in t.data[statement_type_nodeid]:
tile = t
Expand Down Expand Up @@ -402,7 +402,7 @@ def post(self, request):
sample_area_physical_thing_resourceid = part_identifier_assignment_tile_data[physical_part_of_object_nodeid][0]["resourceId"]

sample_physical_thing_resourceid = None
sampling_unit_tiles = Tile.objects.filter(resourceinstance=sampling_activity_resourceid, nodegroup=sampling_unit_nodegroupid)
sampling_unit_tiles = Tile.objects.filter(resourceinstance=sampling_activity_resourceid, nodegroup_id=sampling_unit_nodegroupid)
for sampling_unit_tile in sampling_unit_tiles:
if sampling_unit_tile.data[sampling_area_nodeid][0]["resourceId"] == sample_area_physical_thing_resourceid:
sample_physical_thing_resourceid = sampling_unit_tile.data[sampling_area_sample_created_nodeid][0]["resourceId"]
Expand Down Expand Up @@ -556,7 +556,7 @@ def post(self, request):

try:
sample_physical_thing_resourceid = None
sampling_unit_tiles = Tile.objects.filter(resourceinstance_id=sampling_activity_resourceid, nodegroup=sampling_unit_nodegroupid)
sampling_unit_tiles = Tile.objects.filter(resourceinstance_id=sampling_activity_resourceid, nodegroup_id=sampling_unit_nodegroupid)
for sampling_unit_tile in sampling_unit_tiles:
if sampling_unit_tile.data[sampling_area_nodeid][0]["resourceId"] == sample_area_physical_thing_resourceid:
sample_physical_thing_resourceid = sampling_unit_tile.data[sampling_area_sample_created_nodeid][0]["resourceId"]
Expand Down
2 changes: 1 addition & 1 deletion arches_for_science/views/update_resource_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def bulk_update(resources):
tile = Tile.objects.get(pk=tile_id)
else:
try:
tile = Tile.objects.get(resourceinstance=resource_id, nodegroup=member_of_set_node_id)
tile = Tile.objects.get(resourceinstance=resource_id, nodegroup_id=member_of_set_node_id)
except ObjectDoesNotExist as e:
tile = Tile.get_blank_tile(nodeid=member_of_set_node_id, resourceid=resource_id)
tile.data[member_of_set_node_id] = []
Expand Down
22 changes: 7 additions & 15 deletions tests/tests.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from django.core.management import call_command

from django.contrib.auth.models import User
from django.test import TestCase
from django.test.client import Client
from django.urls import reverse
from django.utils.translation import get_language

from arches.app.utils.betterJSONSerializer import JSONSerializer
from arches.app.models.models import GraphModel, Node, NodeGroup, ResourceInstance, ResourceXResource, TileModel
from arches.app.models.system_settings import settings
from arches.app.models.tile import Tile

PHYSICAL_THING_GRAPH_ID = "9519cb4f-b25b-11e9-8c7b-a4d18cec433a"
Expand All @@ -27,11 +24,6 @@ def setUpModule():


class AnalysisAreaAndSampleTakingTests(TestCase):
def login(self, username="dev", password="dev"):
client = Client()
client.login(username=username, password=password)
return client

def get_resource_instance(self, graph_id):
r = ResourceInstance(graph_id=graph_id)
r.save() # not part of the transaction, part of the setup
Expand All @@ -40,7 +32,7 @@ def get_resource_instance(self, graph_id):

def make_tile(self, parent_phys_thing, data, transaction_id):
arbitrary_nodegroup = NodeGroup.objects.first()
new_tile = TileModel(resourceinstance=parent_phys_thing, nodegroup=arbitrary_nodegroup)
new_tile = TileModel(resourceinstance=parent_phys_thing, nodegroup_id=arbitrary_nodegroup.pk)
new_tile.save()
# Set the transactionid
new_tile = Tile.objects.get(tileid=new_tile.pk)
Expand All @@ -52,7 +44,7 @@ def make_tile(self, parent_phys_thing, data, transaction_id):

def test_create_delete_analysis_area(self):
# TODO: fails with dev/dev? 🤔
client = self.login(username="ben", password="Test12345!")
self.client.login(username="ben", password="Test12345!")

transaction_id = "10000000-1000-1000-1000-100000000000"
parent_phys_thing = self.get_resource_instance(PHYSICAL_THING_GRAPH_ID)
Expand All @@ -71,7 +63,7 @@ def test_create_delete_analysis_area(self):
),
"analysisAreaName": "Test Analysis Area",
}
response = client.post(reverse("saveanalysisarea"), create_data)
response = self.client.post(reverse("saveanalysisarea"), create_data)
self.assertEqual(response.status_code, 200)

new_resource = ResourceInstance.objects.get(pk=response.json()["result"]["memberOfTile"]["resourceinstance_id"])
Expand All @@ -93,12 +85,12 @@ def test_create_delete_analysis_area(self):
}
delete_data = JSONSerializer().serialize(delete_data)
content_type = "application/json"
response = client.post(reverse("deleteanalysisarea"), delete_data, content_type=content_type)
response = self.client.post(reverse("deleteanalysisarea"), delete_data, content_type=content_type)

self.assertEqual(response.status_code, 200)

def test_create_delete_sample(self):
client = self.login()
self.client.login(username="dev", password="dev")

transaction_id = "10000000-1000-1000-1000-100000000001"
parent_phys_thing = self.get_resource_instance(PHYSICAL_THING_GRAPH_ID)
Expand All @@ -124,7 +116,7 @@ def test_create_delete_sample(self):
"sampleDescription": "Test Description",
"samplingActivityResourceId": str(sampling_activity.pk),
}
response = client.post(reverse("savesamplearea"), create_data)
response = self.client.post(reverse("savesamplearea"), create_data)
self.assertEqual(response.status_code, 200)

# Delete
Expand All @@ -151,6 +143,6 @@ def test_create_delete_sample(self):
}
delete_data = JSONSerializer().serialize(delete_data)
content_type = "application/json"
response = client.post(reverse("deletesamplearea"), delete_data, content_type=content_type)
response = self.client.post(reverse("deletesamplearea"), delete_data, content_type=content_type)

self.assertEqual(response.status_code, 200)
Loading