Exemplo n.º 1
0
    def get_template_from_model(self):
        list_prefixes = None

        if self.list_slug:
            patient_list = PatientList.get(self.list_slug)()
            list_prefixes = patient_list.get_template_prefixes()
        return self.column.get_modal_template(prefixes=list_prefixes)
Exemplo n.º 2
0
 def test_to_dict_passes_queryset(self, serialised):
     serialised.return_value = {}
     with patch.object(PatientList, 'get_queryset') as gq:
         with patch.object(PatientList, 'queryset', new_callable=PropertyMock) as q:
             dicted = PatientList().to_dict('my_user')
             gq.assert_called_with(user='******')
             self.assertEqual({}, dicted)
Exemplo n.º 3
0
 def retrieve(self, request, pk=None):
     try:
         patientlist = PatientList.get(pk)()
     except ValueError:
         return json_response({'error': 'List does not exist'},
                              status_code=status.HTTP_404_NOT_FOUND)
     return json_response(patientlist.to_dict(request.user))
Exemplo n.º 4
0
 def get(self, *args, **kwargs):
     # while we manage transition lets allow a fall back to the old way
     name = kwargs['tag']
     if 'subtag' in kwargs:
         name += '-' + kwargs['subtag']
     patient_list = PatientList.get(name)()
     return _build_json_response(patient_list.to_dict(self.request.user))
Exemplo n.º 5
0
 def test_order_respected_by_list(self):
     expected = [
         TaggingTestNotSubTag, TaggingTestPatientList,
         TaggingTestSameTagPatientList, InvisibleList, DisplayList,
         IconicList
     ]
     self.assertEqual(expected, list(PatientList.list()))
Exemplo n.º 6
0
    def test_mine(self):
        ''' given to episodes, calling mine should only return the one tagged with
            the user
        '''
        self.episode_1.set_tag_names(["mine"], self.user)
        self.assertIn(Mine, PatientList.list())

        mock_request = MagicMock(name='Mock request')
        mock_request.user = self.user

        patient_list = PatientList.get("mine")()
        self.assertEqual(
            [self.episode_1], [i for i in patient_list.get_queryset()]
        )
        serialized = patient_list.to_dict(self.user)
        self.assertEqual(len(serialized), 1)
        self.assertEqual(serialized[0]["id"], 1)
Exemplo n.º 7
0
    def get_template_from_model(self):
        patient_list = None

        if self.list_slug:
            patient_list = PatientList.get(self.list_slug)()
        return self.column.get_modal_template(
            patient_list=patient_list
        )
Exemplo n.º 8
0
 def test_order_respected_by_list(self):
     expected = [
         TaggingTestNotSubTag,
         TaggingTestPatientList,
         TaggingTestSameTagPatientList,
         InvisibleList,
     ]
     self.assertEqual(expected, list(PatientList.list()))
Exemplo n.º 9
0
 def retrieve(self, request, pk=None):
     try:
         patientlist = PatientList.get(pk)()
     except ValueError:
         return json_response(
             {'error': 'List does not exist'},
             status_code=status.HTTP_404_NOT_FOUND
         )
     return json_response(patientlist.to_dict(request.user))
Exemplo n.º 10
0
    def get_template_from_model(self):
        list_prefixes = None

        if self.list_slug:
            patient_list = PatientList.get(self.list_slug)()
            list_prefixes = patient_list.get_template_prefixes()
        return self.column.get_modal_template(
            prefixes=list_prefixes
        )
Exemplo n.º 11
0
 def get_context_data(self, **kwargs):
     context = super(PatientListTemplateView,
                     self).get_context_data(**kwargs)
     list_slug = None
     if self.patient_list:
         list_slug = self.patient_list.get_slug()
     context['list_slug'] = list_slug
     context['patient_list'] = self.patient_list
     context['lists'] = PatientList.for_user(self.request.user)
     context['columns'] = self.get_column_context(**kwargs)
     return context
    def test_get_all_patient_lists(self):
        # this should not be taken as a reason not to do more indepth unit tests!
        # its just a nice sanity check
        patient_lists = PatientList.list()
        for pl in patient_lists:
            slug = pl.get_slug()
            url = reverse("patient_list_template_view", kwargs={"slug": slug})

            self.assertStatusCode(
                url,
                200,
                msg="Failed to load the template for {}".format(slug))
Exemplo n.º 13
0
    def test_tagging_set_without_subtag(self):
        ''' given an episode with certain tags and the required request we should
            only return episodes with those tags
        '''
        self.episode_2.set_tag_names(["carnivore"], self.user)

        patient_list = PatientList.get("carnivore")()
        self.assertEqual([self.episode_2],
                         [i for i in patient_list.get_queryset()])
        serialized = patient_list.to_dict(self.user)
        self.assertEqual(len(serialized), 1)
        self.assertEqual(serialized[0]["id"], self.episode_2.id)
Exemplo n.º 14
0
    def test_tagging_set_without_subtag(self):
        ''' given an episode with certain tags and the required request we should
            only return episodes with those tags
        '''
        self.episode_2.set_tag_names(["carnivore"], self.user)

        patient_list = PatientList.get("carnivore")()
        self.assertEqual(
            [self.episode_2], [i for i in patient_list.get_queryset()]
        )
        serialized = patient_list.to_dict(self.user)
        self.assertEqual(len(serialized), 1)
        self.assertEqual(serialized[0]["id"], 2)
Exemplo n.º 15
0
    def test_get_all_patient_lists(self):
        # this should not be taken as a reason not to do more indepth unit tests!
        # its just a nice sanity check
        patient_lists = PatientList.list()
        for pl in patient_lists:
            slug = pl.get_slug()
            url = reverse(
                "patient_list_template_view", kwargs={"slug": slug}
            )

            self.assertStatusCode(
                url, 200,
                msg="Failed to load the template for {}".format(slug)
            )
Exemplo n.º 16
0
    def test_get_all_patient_api(self):
        # this should not be taken as a reason not to do more indepth unit tests!
        # its just a nice sanity check
        patient_lists = PatientList.list()
        request = self.factory.get("/")
        request.user = self.user
        for pl in patient_lists:
            slug = pl.get_slug()
            url = drf_reverse(
                "patientlist-detail", kwargs={"pk": slug}, request=request
            )

            self.assertStatusCode(
                url, 200,
                msg="Failed to load the template for {}".format(slug)
            )
Exemplo n.º 17
0
    def get_context_data(self, **kwargs):
        context = super(PatientListTemplateView,
                        self).get_context_data(**kwargs)
        list_slug = None
        if self.patient_list:
            list_slug = self.patient_list.get_slug()
        context['list_slug'] = list_slug
        context['patient_list'] = self.patient_list
        context['lists'] = PatientList.for_user(self.request.user)

        context['list_group'] = None
        if self.patient_list:
            group = TabbedPatientListGroup.for_list(self.patient_list)
            if group:
                if group.visible_to(self.request.user):
                    context['list_group'] = group

        context['columns'] = self.get_column_context(**kwargs)
        return context
Exemplo n.º 18
0
    def get_context_data(self, **kwargs):
        context = super(
            PatientListTemplateView, self
        ).get_context_data(**kwargs)
        list_slug = None
        if self.patient_list:
            list_slug = self.patient_list.get_slug()
        context['list_slug'] = list_slug
        context['patient_list'] = self.patient_list
        context['lists'] = list(PatientList.for_user(self.request.user))
        context['num_lists'] = len(context['lists'])

        context['list_group'] = None
        if self.patient_list:
            group = TabbedPatientListGroup.for_list(self.patient_list)
            if group:
                if group.visible_to(self.request.user):
                    context['list_group'] = group

        context['columns'] = self.get_column_context(**kwargs)
        return context
Exemplo n.º 19
0
def slack_lists(context):
    from opal.core.patient_lists import PatientList
    return dict(lists=PatientList.for_user(context['request'].user))
Exemplo n.º 20
0
 def test_known_abstract_subclasses_not_in_list(self):
     lists = list(PatientList.list())
     self.assertNotIn(TaggedPatientList, lists)
Exemplo n.º 21
0
 def test_get_template_names_default(self):
     self.assertEqual(['patient_lists/layouts/spreadsheet_list.html'],
                      PatientList().get_template_names())
Exemplo n.º 22
0
 def dispatch(self, *args, **kwargs):
     try:
         self.patient_list = PatientList.get(kwargs['slug'])
     except ValueError:
         self.patient_list = None
     return super(PatientListTemplateView, self).dispatch(*args, **kwargs)
Exemplo n.º 23
0
 def test_for_user_restricted_only(self):
     self.assertEqual([], list(PatientList.for_user(self.restricted_user)))
Exemplo n.º 24
0
 def test_for_user(self):
     self.assertIn(TaggingTestPatientList,
                   list(PatientList.for_user(self.user)))
     self.assertIn(TaggingTestNotSubTag,
                   list(PatientList.for_user(self.user)))
Exemplo n.º 25
0
 def test_get_queryset_default(self):
     mock_queryset = MagicMock('Mock Queryset')
     with patch.object(PatientList, 'queryset',
                       new_callable=PropertyMock) as queryset:
         queryset.return_value = mock_queryset
         self.assertEqual(mock_queryset, PatientList().get_queryset())
Exemplo n.º 26
0
 def test_unimplemented_queryset(self):
     with self.assertRaises(ValueError):
         queryset = PatientList().queryset
Exemplo n.º 27
0
 def test_unimplemented_schema(self):
     with self.assertRaises(ValueError):
         schema = PatientList().schema
Exemplo n.º 28
0
 def test_for_user(self):
     self.assertIn(TaggingTestPatientList, list(PatientList.for_user(self.user)))
     self.assertIn(TaggingTestNotSubTag, list(PatientList.for_user(self.user)))
Exemplo n.º 29
0
 def test_for_user_restricted_only(self):
     self.assertEqual([], list(PatientList.for_user(self.restricted_user)))
Exemplo n.º 30
0
 def test_known_abstract_subclasses_not_in_list(self):
     lists = list(PatientList.list())
     self.assertNotIn(TaggedPatientList, lists)
Exemplo n.º 31
0
 def test_to_dict_passes_queryset(self):
     with patch.object(PatientList, 'get_queryset') as gq:
         with patch.object(PatientList, 'queryset', new_callable=PropertyMock) as q:
             PatientList().to_dict('my_user')
             gq.assert_called_with(user='******')
Exemplo n.º 32
0
 def dispatch(self, *args, **kwargs):
     try:
         self.patient_list = PatientList.get(kwargs['slug'])
     except ValueError:
         self.patient_list = None
     return super(PatientListTemplateView, self).dispatch(*args, **kwargs)