<commit_before>from django.test import TestCase, RequestFactory
import ipdb
from corehq.apps.users.models import CommCareUser
from casexml.apps.case.models import CommCareCase
from casexml.apps.case.tests import TEST_CASE_ID, BaseCaseMultimediaTest, TEST_DOMAIN
from django.test.client import Client
from corehq.apps.api.object_fetch_api import CaseAttachmentAPI, CachedObjectAPI


TEST_USER = 'tester'
TEST_PASSWORD = '<PASSWORD>'

class CaseObjectCacheTest(BaseCaseMultimediaTest):
    """
    test case object caching
    """

    def setUp(self):
        self.user = CommCareUser.create(TEST_DOMAIN, TEST_USER, TEST_PASSWORD)

    def tearDown(self):
        self.user.delete()

    def testGenericObjectCache(self):
        """
        Generic caching framework for assets that need downloads, like jad/jars
        """
        pass

    def _ref_get(self, url):
        rf = RequestFactory()
        req = rf.get(url)
        attach_api = CaseAttachmentAPI()
        return attach_api.get(req, 'tester')


    def testCreateMultimediaCase(self):
        attachments = ['dimagi_logo', 'commcare_logo']

        self._doCreateCaseWithMultimedia(attachments=attachments)
        case = CommCareCase.get(TEST_CASE_ID)
        self.assertEqual(2, len(case.case_attachments))
        c = Client()
        lresponse = c.post('/login/', {'username': TEST_USER, 'password': <PASSWORD>})

        for a in attachments:
            url = case.get_attachment_server_url(a)
            ipdb.set_trace()
            data = c.get(url)


<commit_msg>adding test conditions - wip<commit_after>import hashlib

from django.test import RequestFactory
from django.test.client import Client

from corehq.apps.users.models import CommCareUser
from casexml.apps.case.models import CommCareCase
from casexml.apps.case.tests import TEST_CASE_ID, BaseCaseMultimediaTest, TEST_DOMAIN
from corehq.apps.api.object_fetch_api import CaseAttachmentAPI


TEST_USER = 'tester'
TEST_PASSWORD = '<PASSWORD>'

class CaseObjectCacheTest(BaseCaseMultimediaTest):
    """
    test case object caching
    """

    def setUp(self):
        self.user = CommCareUser.create(TEST_DOMAIN, TEST_USER, TEST_PASSWORD)

    def tearDown(self):
        self.user.delete()

    def testGenericObjectCache(self):
        """
        Generic caching framework for assets that need downloads, like jad/jars
        """
        #API url not implemented yet, leaving this stub in as placeholder todo for full implementation
        pass

    def _ref_get(self, url):
        rf = RequestFactory()
        req = rf.get(url)
        attach_api = CaseAttachmentAPI()
        return attach_api.get(req, 'tester')


    def testCreateMultimediaCase(self):
        attachments = ['dimagi_logo', 'commcare_logo']

        self._doCreateCaseWithMultimedia(attachments=attachments)
        case = CommCareCase.get(TEST_CASE_ID)
        case.domain=TEST_DOMAIN
        self.assertEqual(2, len(case.case_attachments))
        c = Client()
        lresponse = c.post('/accounts/login/', {'username': TEST_USER, 'password': <PASSWORD>})

        for a in attachments:
            url = case.get_attachment_server_url(a)
            data = c.get(url)
            self.assertEqual(hashlib.md5(self._attachmentFileStream(a).read()).hexdigest(),
                             hashlib.md5(data.content).hexdigest())




{'fraction_non_alphanumeric': 0.0955509107196178, 'fraction_numerical': 0.0011943863839952225, 'mean_word_length': 3.1358024691358026, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2131088', 'n_tokens_mistral': 1010, 'n_tokens_neox': 971, 'n_words': 220}