Skip to content

Commit

Permalink
reject updates to deleted cases and change tests to reflect that
Browse files Browse the repository at this point in the history
also rearranged the precedence of case doc checks to check domains before anything else
  • Loading branch information
dannyroberts committed Jul 31, 2013
1 parent e6f2dcd commit 717b274
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
14 changes: 8 additions & 6 deletions casexml/apps/case/tests/test_bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.test import TestCase
import os
from casexml.apps.case import settings
from casexml.apps.case.exceptions import IllegalCaseId
from casexml.apps.case.models import CommCareCase
from casexml.apps.case.tests.util import CaseBlock, delete_all_cases
from casexml.apps.case.util import post_case_blocks
Expand Down Expand Up @@ -173,7 +174,7 @@ def testLotsOfSubcases(self):
self.assertEqual(11, len(CommCareCase.view("case/by_user", reduce=False).all()))

def testSubmitToDeletedCase(self):
# submitting to a deleted case should update the case but keep it as deleted
# submitting to a deleted case should fail and not affect the case
case_id = 'immagetdeleted'
deleted_doc_type = 'CommCareCase-Deleted'
post_case_blocks([
Expand All @@ -186,10 +187,11 @@ def testSubmitToDeletedCase(self):
case.doc_type = deleted_doc_type
case.save()
self.assertEqual(deleted_doc_type, case.doc_type)
post_case_blocks([
CaseBlock(create=False, case_id=case_id, user_id='whatever',
version=V2, update={'foo': 'not_bar'}).as_xml()
])
with self.assertRaises(IllegalCaseId):
post_case_blocks([
CaseBlock(create=False, case_id=case_id, user_id='whatever',
version=V2, update={'foo': 'not_bar'}).as_xml()
])
case = CommCareCase.get(case_id)
self.assertEqual('not_bar', case.foo)
self.assertEqual('bar', case.foo)
self.assertEqual(deleted_doc_type, case.doc_type)
10 changes: 7 additions & 3 deletions casexml/apps/case/xform.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ def __init__(self, domain=None, strip_history=False):
def validate_doc(self, doc):
# some forms recycle case ids as other ids (like xform ids)
# disallow that hard.
if doc.doc_type not in ["CommCareCase", "CommCareCase-Deleted"]:
if self.domain and doc.domain != self.domain:
raise IllegalCaseId("Bad case id")

if doc.doc_type == 'CommCareCase-Deleted':
raise IllegalCaseId("Case [%s] is deleted " % doc.get_id)

if doc.doc_type != 'CommCareCase':
raise IllegalCaseId(
"Bad case doc type! "
"This usually means you are using a bad value for case_id."
)
if self.domain and doc.domain != self.domain:
raise IllegalCaseId("Bad case id")

def get(self, case_id):
if case_id in self.cache:
Expand Down

0 comments on commit 717b274

Please sign in to comment.