-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
reference form attachments in case attachments instead of copying #13200
Changes from 5 commits
21da5e6
9b5e7bc
d46dfa6
69c20ef
7d039ed
995cb48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,13 +14,14 @@ | |||||||||||||||
from casexml.apps.case.tests.util import TEST_DOMAIN_NAME | ||||||||||||||||
from casexml.apps.case.xml import V2 | ||||||||||||||||
from corehq.apps.receiverwrapper.util import submit_form_locally | ||||||||||||||||
from corehq.blobs import get_blob_db | ||||||||||||||||
from corehq.blobs.tests.util import TemporaryS3BlobDB | ||||||||||||||||
from corehq.form_processor.interfaces.dbaccessors import CaseAccessors, FormAccessors | ||||||||||||||||
from couchforms.models import XFormInstance | ||||||||||||||||
from dimagi.utils.parsing import json_format_datetime | ||||||||||||||||
from corehq.form_processor.interfaces.processor import FormProcessorInterface | ||||||||||||||||
from corehq.form_processor.tests.utils import FormProcessorTestUtils, run_with_all_backends | ||||||||||||||||
from corehq.util.test_utils import TestFileMixin | ||||||||||||||||
|
||||||||||||||||
from corehq.util.test_utils import TestFileMixin, trap_extra_setup | ||||||||||||||||
|
||||||||||||||||
TEST_CASE_ID = "EOL9FIAKIQWOFXFOH0QAMWU64" | ||||||||||||||||
CREATE_XFORM_ID = "6RGAZTETE3Z2QC0PE2DKM88MO" | ||||||||||||||||
|
@@ -300,3 +301,33 @@ def test_sync_log_invalidation_bug(self): | |||||||||||||||
# this used to fail before we fixed http://manage.dimagi.com/default.asp?158373 | ||||||||||||||||
self._doSubmitUpdateWithMultimedia(new_attachments=['commcare_logo_file'], removes=[], | ||||||||||||||||
sync_token=sync_log._id) | ||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
class CaseMultimediaS3DBTest(BaseCaseMultimediaTest): | ||||||||||||||||
""" | ||||||||||||||||
Tests new attachments for cases and case properties | ||||||||||||||||
Spec: https://github.com/dimagi/commcare/wiki/CaseAttachmentAPI | ||||||||||||||||
""" | ||||||||||||||||
|
||||||||||||||||
def setUp(self): | ||||||||||||||||
super(CaseMultimediaS3DBTest, self).setUp() | ||||||||||||||||
with trap_extra_setup(AttributeError, msg="S3_BLOB_DB_SETTINGS not configured"): | ||||||||||||||||
config = settings.S3_BLOB_DB_SETTINGS | ||||||||||||||||
self.s3db = TemporaryS3BlobDB(config) | ||||||||||||||||
assert get_blob_db() is self.s3db, (get_blob_db(), self.s3db) | ||||||||||||||||
|
||||||||||||||||
def tearDown(self): | ||||||||||||||||
self.s3db.close() | ||||||||||||||||
super(CaseMultimediaS3DBTest, self).tearDown() | ||||||||||||||||
|
||||||||||||||||
@run_with_all_backends | ||||||||||||||||
def test_case_attachment(self): | ||||||||||||||||
single_attach = 'fruity_file' | ||||||||||||||||
xform, case = self._doCreateCaseWithMultimedia(attachments=[single_attach]) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sends attachments to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Case attachments come from form attachments hence the call to commcare-hq/corehq/ex-submodules/casexml/apps/case/tests/test_multimedia.py Lines 94 to 100 in 9a9de02
The SQL backend uses the blobdb for all attachments (form and case). I also see that boto S3 has a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying out the copy API right now. Will have a PR soon, hopefully. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||
|
||||||||||||||||
self.assertEqual(1, len(case.case_attachments)) | ||||||||||||||||
self.assertTrue(single_attach in case.case_attachments) | ||||||||||||||||
self.assertEqual( | ||||||||||||||||
self._calc_file_hash(single_attach), | ||||||||||||||||
hashlib.md5(case.get_attachment(single_attach)).hexdigest() | ||||||||||||||||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the above two lines don't need to (and probably shouldn't) be in the
with trap_extra_setup
block.