Tests for case where we have bad display_order numbers.
I.e., 0, 1, 1, 1
This commit is contained in:
parent
9bd012c822
commit
a35d122a03
|
@ -107,3 +107,64 @@ class TestWorkflowSpecCategoryReorder(BaseTest):
|
|||
reordered = session.query(WorkflowSpecCategoryModel).order_by(WorkflowSpecCategoryModel.display_order).all()
|
||||
self.assertEqual(ordered, reordered)
|
||||
|
||||
def test_workflow_spec_category_up_too_far(self):
|
||||
self.load_example_data()
|
||||
self._load_test_categories()
|
||||
ordered = session.query(WorkflowSpecCategoryModel).order_by(WorkflowSpecCategoryModel.display_order).all()
|
||||
|
||||
# Try to move 0 up
|
||||
rv = self.app.put(f"/v1.0/workflow-specification-category/0/reorder?direction=up",
|
||||
headers=self.logged_in_headers())
|
||||
# Make sure we don't get an error
|
||||
self.assert_success(rv)
|
||||
|
||||
# Make sure we get the original list back.
|
||||
reordered = session.query(WorkflowSpecCategoryModel).order_by(WorkflowSpecCategoryModel.display_order).all()
|
||||
self.assertEqual(ordered, reordered)
|
||||
|
||||
def test_workflow_spec_category_bad_order(self):
|
||||
self.load_example_data()
|
||||
self._load_test_categories()
|
||||
ordered = session.query(WorkflowSpecCategoryModel).order_by(WorkflowSpecCategoryModel.display_order).all()
|
||||
# Create bad display_orders
|
||||
# 3 of them have 1 as their display_order
|
||||
wf_spec_category_model = ordered[0]
|
||||
wf_spec_category_model.display_order = 1
|
||||
session.add(wf_spec_category_model)
|
||||
wf_spec_category_model = ordered[1]
|
||||
wf_spec_category_model.display_order = 1
|
||||
session.add(wf_spec_category_model)
|
||||
wf_spec_category_model = ordered[2]
|
||||
wf_spec_category_model.display_order = 1
|
||||
session.add(wf_spec_category_model)
|
||||
session.commit()
|
||||
|
||||
bad_ordered = session.query(WorkflowSpecCategoryModel).order_by(WorkflowSpecCategoryModel.display_order).all()
|
||||
# Confirm the bad display_orders
|
||||
self.assertEqual('Test Category 1', bad_ordered[0].display_name)
|
||||
self.assertEqual(1, bad_ordered[0].display_order)
|
||||
self.assertEqual('Test Category', bad_ordered[1].display_name)
|
||||
self.assertEqual(1, bad_ordered[1].display_order)
|
||||
self.assertEqual('Test Category 2', bad_ordered[2].display_name)
|
||||
self.assertEqual(1, bad_ordered[2].display_order)
|
||||
self.assertEqual('Test Category 3', bad_ordered[3].display_name)
|
||||
self.assertEqual(3, bad_ordered[3].display_order)
|
||||
|
||||
# Reorder 2 up
|
||||
# This should cause a cleanup of the display_orders
|
||||
# I don't know how Postgres/SQLAlchemy determine the order when
|
||||
# multiple categories have the same display_order
|
||||
# But, it ends up
|
||||
# Test Category 1, Test Category, Test Category 2, Test Category 3
|
||||
# So, after moving 2 up, we should end up with
|
||||
# Test Category 1, Test Category 2, Test Category, Test Category 3
|
||||
rv = self.app.put(f"/v1.0/workflow-specification-category/2/reorder?direction=up",
|
||||
headers=self.logged_in_headers())
|
||||
self.assertEqual('Test Category 1', rv.json[0]['display_name'])
|
||||
self.assertEqual(0, rv.json[0]['display_order'])
|
||||
self.assertEqual('Test Category 2', rv.json[1]['display_name'])
|
||||
self.assertEqual(1, rv.json[1]['display_order'])
|
||||
self.assertEqual('Test Category', rv.json[2]['display_name'])
|
||||
self.assertEqual(2, rv.json[2]['display_order'])
|
||||
self.assertEqual('Test Category 3', rv.json[3]['display_name'])
|
||||
self.assertEqual(3, rv.json[3]['display_order'])
|
||||
|
|
|
@ -106,14 +106,20 @@ class TestWorkflowSpecReorder(BaseTest):
|
|||
self.assertEqual(3, rv.json[3]['display_order'])
|
||||
|
||||
# Check what new order is in the DB
|
||||
reordered = session.query(WorkflowSpecModel).order_by(WorkflowSpecModel.display_order).all()
|
||||
reordered = session.query(WorkflowSpecModel).\
|
||||
filter(WorkflowSpecModel.category_id == 0).\
|
||||
order_by(WorkflowSpecModel.display_order).\
|
||||
all()
|
||||
self.assertEqual('test_spec_2', reordered[3].id)
|
||||
|
||||
def test_workflow_spec_reorder_down_bad(self):
|
||||
self.load_example_data()
|
||||
self._load_sample_workflow_specs()
|
||||
|
||||
ordered = session.query(WorkflowSpecModel).order_by(WorkflowSpecModel.display_order).all()
|
||||
ordered = session.query(WorkflowSpecModel).\
|
||||
filter(WorkflowSpecModel.category_id == 0).\
|
||||
order_by(WorkflowSpecModel.display_order).\
|
||||
all()
|
||||
|
||||
# Try to move test_spec_3 down
|
||||
rv = self.app.put(f"/v1.0/workflow-specification/test_spec_3/reorder?direction=down",
|
||||
|
@ -122,5 +128,62 @@ class TestWorkflowSpecReorder(BaseTest):
|
|||
self.assert_success(rv)
|
||||
|
||||
# Make sure we get the original list back.
|
||||
reordered = session.query(WorkflowSpecModel).order_by(WorkflowSpecModel.display_order).all()
|
||||
reordered = session.query(WorkflowSpecModel).\
|
||||
filter(WorkflowSpecModel.category_id == 0).\
|
||||
order_by(WorkflowSpecModel.display_order).\
|
||||
all()
|
||||
self.assertEqual(ordered, reordered)
|
||||
|
||||
def test_workflow_spec_reorder_bad_order(self):
|
||||
self.load_example_data()
|
||||
self._load_sample_workflow_specs()
|
||||
ordered = session.query(WorkflowSpecModel).\
|
||||
filter(WorkflowSpecModel.category_id == 0).\
|
||||
order_by(WorkflowSpecModel.display_order).\
|
||||
all()
|
||||
|
||||
# Set bad display_orders
|
||||
spec_model = ordered[0]
|
||||
spec_model.display_order = 1
|
||||
session.add(spec_model)
|
||||
spec_model = ordered[1]
|
||||
spec_model.display_order = 1
|
||||
session.add(spec_model)
|
||||
spec_model = ordered[2]
|
||||
spec_model.display_order = 1
|
||||
session.add(spec_model)
|
||||
session.commit()
|
||||
|
||||
bad_orders = session.query(WorkflowSpecModel).\
|
||||
filter(WorkflowSpecModel.category_id == 0).\
|
||||
order_by(WorkflowSpecModel.display_order).\
|
||||
all()
|
||||
# Not sure how Postgres chooses an order
|
||||
# when we have multiple specs with display_order == 1
|
||||
# but it is
|
||||
# test_spec_1, random_fact, test_spec_2, test_spec_3
|
||||
self.assertEqual(1, bad_orders[0].display_order)
|
||||
self.assertEqual('test_spec_1', bad_orders[0].name)
|
||||
self.assertEqual(1, bad_orders[1].display_order)
|
||||
self.assertEqual('random_fact', bad_orders[1].name)
|
||||
self.assertEqual(1, bad_orders[2].display_order)
|
||||
self.assertEqual('test_spec_2', bad_orders[2].name)
|
||||
self.assertEqual(3, bad_orders[3].display_order)
|
||||
self.assertEqual('test_spec_3', bad_orders[3].name)
|
||||
|
||||
# Move test_spec_2 up
|
||||
# This should cause a cleanup of the bad display_order numbers
|
||||
rv = self.app.put(f"/v1.0/workflow-specification/test_spec_2/reorder?direction=up",
|
||||
headers=self.logged_in_headers())
|
||||
|
||||
# After moving 2 up, the order should be
|
||||
# test_spec_1, test_spec_2, random_fact, test_spec_3
|
||||
# Make sure we have good display_order numbers too
|
||||
self.assertEqual('test_spec_1', rv.json[0]['name'])
|
||||
self.assertEqual(0, rv.json[0]['display_order'])
|
||||
self.assertEqual('test_spec_2', rv.json[1]['name'])
|
||||
self.assertEqual(1, rv.json[1]['display_order'])
|
||||
self.assertEqual('random_fact', rv.json[2]['name'])
|
||||
self.assertEqual(2, rv.json[2]['display_order'])
|
||||
self.assertEqual('test_spec_3', rv.json[3]['name'])
|
||||
self.assertEqual(3, rv.json[3]['display_order'])
|
||||
|
|
Loading…
Reference in New Issue