Skip to content

Commit 540941e

Browse files
authored
Merge pull request #2 from aplmicrons/rename_fix
Fix for lookup table corruption.
2 parents 337d347 + e848482 commit 540941e

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed

django/bosscore/lookup.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,9 @@ def update_lookup_experiment(lookup_key, boss_key, collection_name, experiment_n
198198

199199

200200
# update all channels that reference this experiment
201-
all_lookup_objs = BossLookup.objects.filter(experiment_name=old_experiment_name).exclude(
202-
lookup_key=lookup_key)
201+
all_lookup_objs = BossLookup.objects.filter(
202+
collection_name=collection_name, experiment_name=old_experiment_name).exclude(
203+
lookup_key=lookup_key)
203204
for item in all_lookup_objs:
204205

205206
split_key = item.boss_key.split('&')

django/bosscore/test/setup_db.py

+27-1
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,41 @@ def create_group(self, group_name):
9191
def insert_test_data(self):
9292

9393
self.add_collection('col1', 'Description for collection1')
94-
self.add_collection('col1-22', 'Description for collection1')
94+
self.add_collection('col1-22', 'Description for collection1-22')
9595
self.add_collection('col2', 'Description for collection2')
96+
9697
self.add_coordinate_frame('cf1', 'Description for cf1', 0, 1000, 0, 1000, 0, 1000, 4, 4, 4)
98+
9799
self.add_experiment('col1', 'exp1', 'cf1', 10, 10, 1)
98100
self.add_experiment('col1', 'exp22', 'cf1', 10, 500, 1)
101+
102+
self.add_channel('col1', 'exp1', 'channel1', 0, 0, 'uint8', 'image')
103+
self.add_channel('col1', 'exp1', 'channel2', 0, 0, 'uint8', 'image')
104+
self.add_channel('col1', 'exp1', 'channel3', 0, 0, 'uint64', 'annotation', ['channel1'])
105+
self.add_channel('col1', 'exp1', 'layer1', 0, 0, 'uint64', 'annotation', ['channel1'])
106+
107+
def insert_lookup_test_data(self):
108+
"""
109+
Test data for LookupTest test case.
110+
"""
111+
112+
self.add_collection('col1', 'Description for collection1')
113+
self.add_collection('col2', 'Description for collection2')
114+
115+
self.add_coordinate_frame('cf1', 'Description for cf1', 0, 1000, 0, 1000, 0, 1000, 4, 4, 4)
116+
117+
self.add_experiment('col1', 'exp1', 'cf1', 10, 10, 1)
118+
119+
# This experiment is _purposed_ named the same as the exp in col1.
120+
# Ensuring that renaming an experiment does not affect experiments with
121+
# the same name in other collections.
122+
self.add_experiment('col2', 'exp1', 'cf1', 10, 500, 1)
123+
99124
self.add_channel('col1', 'exp1', 'channel1', 0, 0, 'uint8', 'image')
100125
self.add_channel('col1', 'exp1', 'channel2', 0, 0, 'uint8', 'image')
101126
self.add_channel('col1', 'exp1', 'channel3', 0, 0, 'uint64', 'annotation', ['channel1'])
102127
self.add_channel('col1', 'exp1', 'layer1', 0, 0, 'uint64', 'annotation', ['channel1'])
128+
self.add_channel('col2', 'exp1', 'channel1', 0, 0, 'uinit8', 'image')
103129

104130
def insert_spatialdb_test_data(self):
105131

django/bosscore/test/test_lookup.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Copyright 2016 The Johns Hopkins University Applied Physics Laboratory
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from bosscore.lookup import LookUpKey
16+
from bosscore.models import Collection, Experiment, Channel
17+
from bosscore.models import BossLookup
18+
from rest_framework.test import APITestCase
19+
from .setup_db import SetupTestDB
20+
import unittest
21+
22+
23+
class LookupTest(APITestCase):
24+
def setUp(self):
25+
dbsetup = SetupTestDB()
26+
user = dbsetup.create_user('testuser')
27+
dbsetup.add_role('resource-manager')
28+
dbsetup.set_user(user)
29+
30+
self.client.force_login(user)
31+
dbsetup.insert_lookup_test_data()
32+
33+
def test_update_lookup_experiment(self):
34+
"""
35+
On an experiment rename, make sure only resources that are children of
36+
the experiment are changed.
37+
38+
This is a regression test.
39+
"""
40+
new_exp_name = 'new_exp'
41+
collection = 'col2'
42+
orig_exp_name = 'exp1'
43+
44+
collection_obj = Collection.objects.get(name=collection)
45+
experiment_obj = Experiment.objects.get(name=orig_exp_name, collection=collection_obj)
46+
lookup_key = str(collection_obj.pk) + '&' + str(experiment_obj.pk)
47+
boss_key = collection_obj.name + '&' + new_exp_name
48+
49+
# Method under test.
50+
LookUpKey.update_lookup_experiment(
51+
lookup_key, boss_key, collection_obj.name, new_exp_name)
52+
53+
# There should be still 5 rows in the lookup table with orig_exp_name
54+
# as the experiment name under col1. There should be the experiment
55+
# and 4 channels.
56+
all_lookup_objs = BossLookup.objects.filter(experiment_name=orig_exp_name)
57+
self.assertEqual(5, len(all_lookup_objs))

0 commit comments

Comments
 (0)