Пример #1
0
 def test_subrecords_if_empty_query(self, zipfile, subrecords):
     # if there are no subrecords we don't expect them to write to the file
     subrecords.return_value = [HatWearer, HouseOwner]
     extract.zip_archive(models.Episode.objects.all(), 'this', self.user)
     call_args = zipfile.ZipFile.return_value.__enter__.return_value.write.call_args_list
     self.assertEqual(2, len(call_args))
     self.assertTrue(call_args[0][0][0].endswith("data_dictionary.html"))
     self.assertTrue(call_args[1][0][0].endswith("episodes.csv"))
Пример #2
0
 def test_subrecords_if_empty_query(self, zipfile, subrecords):
     # if there are no subrecords we don't expect them to write to the file
     subrecords.return_value = [HatWearer, HouseOwner]
     extract.zip_archive(models.Episode.objects.all(), 'this', self.user)
     call_args = zipfile.ZipFile.return_value.__enter__.return_value.write.call_args_list
     self.assertEqual(2, len(call_args))
     self.assertTrue(call_args[0][0][0].endswith("data_dictionary.html"))
     self.assertTrue(call_args[1][0][0].endswith("episodes.csv"))
Пример #3
0
 def test_subrecords_if_none(self, zipfile, subrecords):
     # if there are no subrecords we don't expect them to write to the file
     patient, episode = self.new_patient_and_episode_please()
     subrecords.return_value = [HatWearer, HouseOwner]
     HouseOwner.objects.create(patient=patient)
     extract.zip_archive(models.Episode.objects.all(), 'this', self.user)
     call_args = zipfile.ZipFile.return_value.__enter__.return_value.write.call_args_list
     self.assertEqual(3, len(call_args))
     self.assertTrue(call_args[0][0][0].endswith("data_dictionary.html"))
     self.assertTrue(call_args[1][0][0].endswith("episodes.csv"))
     self.assertTrue(call_args[2][0][0].endswith("house_owner.csv"))
Пример #4
0
 def test_subrecords_if_none(self, zipfile, subrecords):
     # if there are no subrecords we don't expect them to write to the file
     patient, episode = self.new_patient_and_episode_please()
     subrecords.return_value = [HatWearer, HouseOwner]
     HouseOwner.objects.create(patient=patient)
     extract.zip_archive(models.Episode.objects.all(), 'this', self.user)
     call_args = zipfile.ZipFile.return_value.__enter__.return_value.write.call_args_list
     self.assertEqual(3, len(call_args))
     self.assertTrue(call_args[0][0][0].endswith("data_dictionary.html"))
     self.assertTrue(call_args[1][0][0].endswith("episodes.csv"))
     self.assertTrue(call_args[2][0][0].endswith("house_owner.csv"))
Пример #5
0
 def test_subrecords(self, zipfile, subrecords):
     patient, episode = self.new_patient_and_episode_please()
     subrecords.return_value = [HatWearer, HouseOwner]
     HatWearer.objects.create(name="Indiana", episode=episode)
     HouseOwner.objects.create(patient=patient)
     extract.zip_archive(models.Episode.objects.all(), 'this', self.user)
     call_args = zipfile.ZipFile.return_value.__enter__.return_value.write.call_args_list
     self.assertEqual(4, len(call_args))
     self.assertTrue(call_args[0][0][0].endswith("data_dictionary.html"))
     self.assertTrue(call_args[1][0][0].endswith("episodes.csv"))
     self.assertTrue(call_args[2][0][0].endswith("hat_wearer.csv"))
     self.assertTrue(call_args[3][0][0].endswith("house_owner.csv"))
Пример #6
0
 def test_subrecords(self, zipfile, subrecords):
     patient, episode = self.new_patient_and_episode_please()
     subrecords.return_value = [HatWearer, HouseOwner]
     HatWearer.objects.create(name="Indiana", episode=episode)
     HouseOwner.objects.create(patient=patient)
     extract.zip_archive(models.Episode.objects.all(), 'this', self.user)
     call_args = zipfile.ZipFile.return_value.__enter__.return_value.write.call_args_list
     self.assertEqual(4, len(call_args))
     self.assertTrue(call_args[0][0][0].endswith("data_dictionary.html"))
     self.assertTrue(call_args[1][0][0].endswith("episodes.csv"))
     self.assertTrue(call_args[2][0][0].endswith("hat_wearer.csv"))
     self.assertTrue(call_args[3][0][0].endswith("house_owner.csv"))
Пример #7
0
Файл: tasks.py Проект: wjt/opal
def extract(user, criteria):
    from opal.core.search import queries, extract
    print criteria
    query = queries.SearchBackend(user, criteria)
    episodes = query.get_episodes()
    fname = extract.zip_archive(episodes, query.description(), user)
    return fname
Пример #8
0
    def post(self, *args, **kwargs):
        if getattr(settings, 'EXTRACT_ASYNC', None):
            criteria = _get_request_data(self.request)['criteria']
            extract_id = async_extract(self.request.user, json.loads(criteria))
            return json_response({'extract_id': extract_id})

        query = queries.create_query(self.request.user,
                                     json.loads(self.request.POST['criteria']))
        episodes = query.get_episodes()
        fname = zip_archive(episodes, query.description(), self.request.user)
        resp = HttpResponse(open(fname, 'rb').read())
        disp = 'attachment; filename="{0}extract{1}.zip"'.format(
            settings.OPAL_BRAND_NAME,
            datetime.datetime.now().isoformat())
        resp['Content-Disposition'] = disp
        return resp
Пример #9
0
    def post(self, *args, **kwargs):
        if getattr(settings, 'EXTRACT_ASYNC', None):
            criteria = _get_request_data(self.request)['criteria']
            extract_id = async_extract(
                self.request.user,
                json.loads(criteria)
            )
            return _build_json_response({'extract_id': extract_id})

        query = queries.SearchBackend(
            self.request.user, json.loads(self.request.POST['criteria'])
        )
        episodes = query.get_episodes()
        fname = zip_archive(episodes, query.description(), self.request.user)
        resp = HttpResponse(open(fname, 'rb').read())
        disp = 'attachment; filename="{0}extract{1}.zip"'.format(
            settings.OPAL_BRAND_NAME, datetime.datetime.now().isoformat())
        resp['Content-Disposition'] = disp
        return resp
Пример #10
0
def extract(user, criteria):
    from opal.core.search import queries, extract
    query = queries.create_query(user, criteria)
    episodes = query.get_episodes()
    fname = extract.zip_archive(episodes, query.description(), user)
    return fname
Пример #11
0
 def test_exclude_patient_subrecords(self, zipfile, subrecords):
     extract.zip_archive(models.Episode.objects.all(), 'this', self.user)
     subs = [a[0][1] for a in subrecords.call_args_list]
     self.assertFalse(PatientColour in subs)
Пример #12
0
 def test_episode_subrecords(self, zipfile, patient_subrecords, episode_subrecords):
     episode_subrecords.return_value = [HatWearer]
     patient_subrecords.return_value = [HouseOwner]
     extract.zip_archive(models.Episode.objects.all(), 'this', self.user)
     self.assertEqual(4, zipfile.ZipFile.return_value.__enter__.return_value.write.call_count)
Пример #13
0
 def test_episode_subrecords(self, zipfile):
     extract.zip_archive(models.Episode.objects.all(), 'this', self.user)
     expected = len([i for i in subrecords.episode_subrecords()]) + 7
     self.assertEqual(
         expected, zipfile.ZipFile.return_value.__enter__.return_value.
         write.call_count)