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)
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)
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))
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))
def test_order_respected_by_list(self): expected = [ TaggingTestNotSubTag, TaggingTestPatientList, TaggingTestSameTagPatientList, InvisibleList, DisplayList, IconicList ] self.assertEqual(expected, list(PatientList.list()))
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)
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 )
def test_order_respected_by_list(self): expected = [ TaggingTestNotSubTag, TaggingTestPatientList, TaggingTestSameTagPatientList, InvisibleList, ] self.assertEqual(expected, list(PatientList.list()))
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))
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 )
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))
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)
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)
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) )
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) )
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
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
def slack_lists(context): from opal.core.patient_lists import PatientList return dict(lists=PatientList.for_user(context['request'].user))
def test_known_abstract_subclasses_not_in_list(self): lists = list(PatientList.list()) self.assertNotIn(TaggedPatientList, lists)
def test_get_template_names_default(self): self.assertEqual(['patient_lists/layouts/spreadsheet_list.html'], PatientList().get_template_names())
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)
def test_for_user_restricted_only(self): self.assertEqual([], list(PatientList.for_user(self.restricted_user)))
def test_for_user(self): self.assertIn(TaggingTestPatientList, list(PatientList.for_user(self.user))) self.assertIn(TaggingTestNotSubTag, list(PatientList.for_user(self.user)))
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())
def test_unimplemented_queryset(self): with self.assertRaises(ValueError): queryset = PatientList().queryset
def test_unimplemented_schema(self): with self.assertRaises(ValueError): schema = PatientList().schema
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='******')