Beispiel #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"))
Beispiel #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"))
Beispiel #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"))
Beispiel #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"))
Beispiel #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"))
Beispiel #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"))
Beispiel #7
0
Datei: tasks.py Projekt: 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
Beispiel #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
Beispiel #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
Beispiel #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
 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)
 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)
Beispiel #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)