本文整理汇总了Python中casexml.apps.case.mock.CaseFactory.create_case方法的典型用法代码示例。如果您正苦于以下问题:Python CaseFactory.create_case方法的具体用法?Python CaseFactory.create_case怎么用?Python CaseFactory.create_case使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类casexml.apps.case.mock.CaseFactory
的用法示例。
在下文中一共展示了CaseFactory.create_case方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_simple_delete
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def test_simple_delete(self):
factory = CaseFactory()
case = factory.create_case()
[case] = factory.create_or_update_case(
CaseStructure(case_id=case.case_id, attrs={'update': {'foo': 'bar'}})
)
self.assertIsNotNone(self.casedb.get_case(case.case_id))
self.assertEqual(2, len(case.xform_ids))
for form_id in case.xform_ids:
self.assertIsNotNone(self.formdb.get_form(form_id))
with capture_kafka_changes_context(topics.FORM_SQL, topics.CASE_SQL) as change_context:
safe_hard_delete(case)
if should_use_sql_backend(case.domain):
self.assertEqual(3, len(change_context.changes))
expected_ids = {case.case_id} | set(case.xform_ids)
self.assertEqual(expected_ids, {change.id for change in change_context.changes})
for change in change_context.changes:
self.assertTrue(change.deleted)
with self.assertRaises(CaseNotFound):
self.casedb.get_case(case.case_id)
for form_id in case.xform_ids:
with self.assertRaises(XFormNotFound):
self.formdb.get_form(form_id)
示例2: test_form_extras_default
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def test_form_extras_default(self):
domain = uuid.uuid4().hex
# have to enable loose sync token validation for the domain or create actual SyncLog documents.
# this is the easier path.
token_id = uuid.uuid4().hex
factory = CaseFactory(domain=domain, form_extras={'last_sync_token': token_id})
case = factory.create_case()
form = FormAccessors(domain).get_form(case.xform_ids[0])
self.assertEqual(token_id, form.last_sync_token)
示例3: test_no_walk_related
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def test_no_walk_related(self):
factory = CaseFactory()
parent = factory.create_case()
child_updates = factory.create_or_update_case(
CaseStructure(attrs={'create': True}, walk_related=False, relationships=[
CaseRelationship(CaseStructure(case_id=parent._id))
]),
)
self.assertEqual(1, len(child_updates))
self.assertEqual(parent._id, child_updates[0].indices[0].referenced_id)
示例4: test_form_extras_default
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def test_form_extras_default(self):
domain = uuid.uuid4().hex
# have to enable loose sync token validation for the domain or create actual SyncLog documents.
# this is the easier path.
LOOSE_SYNC_TOKEN_VALIDATION.set(domain, True, namespace='domain')
token_id = uuid.uuid4().hex
factory = CaseFactory(domain=domain, form_extras={'last_sync_token': token_id})
case = factory.create_case()
form = XFormInstance.get(case.xform_ids[0])
self.assertEqual(token_id, form.last_sync_token)
示例5: setUp
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def setUp(self):
# can't do this in setUpClass until Django 1.9 since @override_settings
# doesn't apply to classmethods
from corehq.apps.commtrack.tests import get_single_balance_block
factory = CaseFactory(domain=self.domain)
self.case = factory.create_case()
submit_case_blocks([
get_single_balance_block(self.case.case_id, self.product._id, 10)
], self.domain)
ledger_values = LedgerAccessorSQL.get_ledger_values_for_case(self.case.case_id)
self.assertEqual(1, len(ledger_values))
示例6: test_simple_delete
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def test_simple_delete(self):
factory = CaseFactory()
case = factory.create_case()
[case] = factory.create_or_update_case(CaseStructure(case_id=case._id, attrs={'update': {'foo': 'bar'}}))
self.assertTrue(CommCareCase.get_db().doc_exist(case._id))
self.assertEqual(2, len(case.xform_ids))
for form_id in case.xform_ids:
self.assertTrue(XFormInstance.get_db().doc_exist(form_id))
safe_hard_delete(case)
self.assertFalse(CommCareCase.get_db().doc_exist(case._id))
for form_id in case.xform_ids:
self.assertFalse(XFormInstance.get_db().doc_exist(form_id))
示例7: TestCaseHistory
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
class TestCaseHistory(TestCase):
def setUp(self):
self.domain = "isildur"
self.factory = CaseFactory(self.domain)
self.case = self.factory.create_case(owner_id='owner', case_name="Aragorn", update={"prop_1": "val1"})
self.other_case = self.factory.create_case()
def tearDown(self):
delete_all_xforms()
delete_all_cases()
@run_with_all_backends
def test_case_history(self):
self.factory.create_or_update_case(
CaseStructure(
self.case.case_id,
attrs={
"update": {
'prop_1': "val1",
'prop_2': "val1",
'prop_3': "val1",
},
}),
)
self.factory.create_or_update_case(
CaseStructure(
self.case.case_id,
attrs={
"update": {
'prop_1': "val2",
'prop_2': "val2",
'prop_4': "val",
},
}),
)
case = CaseAccessors(self.domain).get_case(self.case.case_id)
history = get_case_history(case)
self.assertEqual(history[0]['prop_1'], "val1")
self.assertEqual(history[1]['prop_2'], "val1")
self.assertEqual(history[2]['prop_2'], "val2")
示例8: test_delete_with_related
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def test_delete_with_related(self):
factory = CaseFactory()
parent = factory.create_case()
[child] = factory.create_or_update_case(
CaseStructure(attrs={'create': True}, walk_related=False, relationships=[
CaseRelationship(CaseStructure(case_id=parent._id))
]),
)
# deleting the parent should not be allowed because the child still references it
with self.assertRaises(CommCareCaseError):
safe_hard_delete(parent)
# deleting the child is ok
safe_hard_delete(child)
self.assertTrue(CommCareCase.get_db().doc_exist(parent._id))
self.assertFalse(CommCareCase.get_db().doc_exist(child._id))
示例9: test_simple_delete
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def test_simple_delete(self):
factory = CaseFactory()
case = factory.create_case()
[case] = factory.create_or_update_case(CaseStructure(case_id=case._id, attrs={'update': {'foo': 'bar'}}))
self.assertIsNotNone(FormProcessorInterface.get_case(case.id))
self.assertEqual(2, len(case.xform_ids))
for form_id in case.xform_ids:
self.assertIsNotNone(FormProcessorInterface.get_xform(form_id))
FormProcessorInterface.hard_delete_case(case)
with self.assertRaises(CaseNotFound):
FormProcessorInterface.get_case(case.id)
for form_id in case.xform_ids:
with self.assertRaises(XFormNotFound):
FormProcessorInterface.get_xform(form_id)
示例10: test_delete_with_related
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def test_delete_with_related(self):
factory = CaseFactory()
parent = factory.create_case()
[child] = factory.create_or_update_case(
CaseStructure(attrs={'create': True}, walk_related=False, indices=[
CaseIndex(CaseStructure(case_id=parent._id))
]),
)
# deleting the parent should not be allowed because the child still references it
with self.assertRaises(CommCareCaseError):
FormProcessorInterface.hard_delete_case(parent)
# deleting the child is ok
FormProcessorInterface.hard_delete_case(child)
self.assertIsNotNone(FormProcessorInterface.get_case(parent.id))
with self.assertRaises(CaseNotFound):
FormProcessorInterface.get_case(child.id)
示例11: create_docs
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def create_docs(cls, domain, count):
from corehq.apps.commtrack.tests.util import get_single_balance_block
from corehq.apps.hqcase.utils import submit_case_blocks
from corehq.apps.commtrack.helpers import make_product
from corehq.form_processor.parsers.ledgers.helpers import UniqueLedgerReference
cls.product = make_product(cls.domain, 'A Product', 'prodcode_a')
factory = CaseFactory(cls.domain)
case_ids = [factory.create_case().case_id for i in range(count)]
for case_id in case_ids:
submit_case_blocks([
get_single_balance_block(case_id, cls.product._id, 10)
], domain)
return [
UniqueLedgerReference(case_id, 'stock', cls.product._id).as_id()
for case_id in case_ids
]
示例12: post
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def post(self, request, *args, **kwargs):
domain = request.GET.get('domain')
case_type = request.GET.get('case_type')
owner_id = request.GET.get('owner_id')
properties = json.loads(request.body)
case_name = properties.pop('case_name')
user_name = request.GET.get('user')
if not case_type or not owner_id or not domain or not case_name:
return HttpResponseBadRequest('Please fill in all required fields')
couch_user = CommCareUser.get_by_username(user_name)
if not couch_user.is_member_of(domain):
return HttpResponseForbidden("This user does not have access to this domain.")
factory = CaseFactory(domain=domain)
new_case = factory.create_case(
case_type=case_type,
owner_id=owner_id,
case_name=case_name,
update=properties
)
return HttpResponse("Created case with id {case_id}".format(case_id=str(new_case.case_id)))
示例13: test_override_defaults
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def test_override_defaults(self):
owner_id = uuid.uuid4().hex
factory = CaseFactory(case_defaults={"owner_id": owner_id})
case = factory.create_case(owner_id="notthedefault")
self.assertEqual("notthedefault", case.owner_id)
示例14: test_simple_create
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
def test_simple_create(self):
factory = CaseFactory()
case = factory.create_case()
self.assertIsNotNone(CaseAccessors().get_case(case.case_id))
示例15: ImporterTest
# 需要导入模块: from casexml.apps.case.mock import CaseFactory [as 别名]
# 或者: from casexml.apps.case.mock.CaseFactory import create_case [as 别名]
#.........这里部分代码省略.........
[parent_case] = self.factory.create_or_update_case(CaseStructure(attrs={'create': True}))
self.assertEqual(1, len(self.accessor.get_case_ids_in_domain()))
file = make_worksheet_wrapper(
['parent_id', 'name', 'case_id'],
[parent_case.case_id, 'name-0', 'case_id-0'],
[parent_case.case_id, 'name-1', 'case_id-1'],
[parent_case.case_id, 'name-2', 'case_id-2'],
)
file_missing = make_worksheet_wrapper(
['parent_id', 'name', 'case_id'],
['parent_id-0', 'name-0', 'case_id-0'],
['parent_id-1', 'name-1', 'case_id-1'],
['parent_id-2', 'name-2', 'case_id-2'],
)
# Should successfully match on `rows` cases
res = do_import(file, config, self.domain)
self.assertEqual(rows, res['created_count'])
# Should be unable to find parent case on `rows` cases
res = do_import(file_missing, config, self.domain)
error_column_name = 'parent_id'
self.assertEqual(rows,
len(res['errors'][ImportErrors.InvalidParentId][error_column_name]['rows']),
"All cases should have missing parent")
def import_mock_file(self, rows):
config = self._config(rows[0])
xls_file = make_worksheet_wrapper(*rows)
return do_import(xls_file, config, self.domain)
@run_with_all_backends
def testLocationOwner(self):
# This is actually testing several different things, but I figure it's
# worth it, as each of these tests takes a non-trivial amount of time.
non_case_sharing = LocationType.objects.create(
domain=self.domain, name='lt1', shares_cases=False
)
case_sharing = LocationType.objects.create(
domain=self.domain, name='lt2', shares_cases=True
)
location = make_loc('loc-1', 'Loc 1', self.domain, case_sharing.code)
make_loc('loc-2', 'Loc 2', self.domain, case_sharing.code)
duplicate_loc = make_loc('loc-3', 'Loc 2', self.domain, case_sharing.code)
improper_loc = make_loc('loc-4', 'Loc 4', self.domain, non_case_sharing.code)
res = self.import_mock_file([
['case_id', 'name', 'owner_id', 'owner_name'],
['', 'location-owner-id', location.group_id, ''],
['', 'location-owner-code', '', location.site_code],
['', 'location-owner-name', '', location.name],
['', 'duplicate-location-name', '', duplicate_loc.name],
['', 'non-case-owning-name', '', improper_loc.name],
])
case_ids = self.accessor.get_case_ids_in_domain()
cases = {c.name: c for c in list(self.accessor.get_cases(case_ids))}
self.assertEqual(cases['location-owner-id'].owner_id, location.group_id)
self.assertEqual(cases['location-owner-code'].owner_id, location.group_id)
self.assertEqual(cases['location-owner-name'].owner_id, location.group_id)
error_message = ImportErrors.DuplicateLocationName
error_column_name = None
self.assertIn(error_message, res['errors'])
self.assertEqual(res['errors'][error_message][error_column_name]['rows'], [5])
error_message = ImportErrors.InvalidOwnerId
self.assertIn(error_message, res['errors'])
error_column_name = 'owner_id'
self.assertEqual(res['errors'][error_message][error_column_name]['rows'], [6])
@run_with_all_backends
def test_opened_on(self):
case = self.factory.create_case()
new_date = '2015-04-30T14:41:53.000000Z'
with flag_enabled('BULK_UPLOAD_DATE_OPENED'):
self.import_mock_file([
['case_id', 'date_opened'],
[case.case_id, new_date]
])
case = CaseAccessors(self.domain).get_case(case.case_id)
self.assertEqual(case.opened_on, PhoneTime(parse_datetime(new_date)).done())
@run_with_all_backends
def test_columns_and_rows_align(self):
case_owner = CommCareUser.create(self.domain, 'username', 'pw')
res = self.import_mock_file([
['case_id', 'name', '', 'favorite_color', 'owner_id'],
['', 'Jeff', '', 'blue', case_owner._id],
['', 'Caroline', '', 'yellow', case_owner._id],
])
self.assertEqual(res['errors'], {})
case_ids = self.accessor.get_case_ids_in_domain()
cases = {c.name: c for c in list(self.accessor.get_cases(case_ids))}
self.assertEqual(cases['Jeff'].owner_id, case_owner._id)
self.assertEqual(cases['Jeff'].get_case_property('favorite_color'), 'blue')
self.assertEqual(cases['Caroline'].owner_id, case_owner._id)
self.assertEqual(cases['Caroline'].get_case_property('favorite_color'), 'yellow')