def setUp(self): super().setUp() client = ClientFactory(name='UVMC') specialty = SpecialtyFactory(name='CDM') category = CategoryFactory(name='Pacemaker', specialty=specialty) PreferenceFactory(name='Default for all products', client=None, content_type=None, object_id=None, questions=[QuestionFactory(name='Longevity')]) PreferenceFactory(name='Preferences for client', client=client, content_type=None, object_id=None, questions=[QuestionFactory(name='Size/shape')]) PreferenceFactory(name='Preferences for client:specialty', client=client, object_id=specialty.id, content_type=ContentType.objects.get( app_label='device', model='specialty'), questions=[QuestionFactory(name='Research')]) PreferenceFactory(name='Preferences for client:category', client=client, object_id=category.id, content_type=ContentType.objects.get( app_label='device', model='category'), questions=[QuestionFactory(name='cost')]) self.log_in_master_admin() self.visit_reverse('admin:order_preference_changelist') self.wait_for_element_contains_text('.model-preference #content h1', 'Select preference to change')
def test_get_preferences_when_has_category_but_not_client(self): question = QuestionFactory() PreferenceFactory(client=None, content_object=self.product.category, questions=[question]) PreferenceFactory(client=self.client, content_object=None) self.assertCountEqual( Preference.get_preferences_by_product_client(self.product, self.client), [question] )
def test_get_common_preferences(self): question = QuestionFactory() PreferenceFactory(client=None, content_object=None, questions=[question]) PreferenceFactory(client=ClientFactory()) self.assertCountEqual( Preference.get_preferences_by_product_client(self.product, self.client), [question] )
def test_get_preferences_when_only_client_preference_exist(self): question = QuestionFactory() PreferenceFactory(client=self.client, content_object=None, questions=[question]) product = ProductFactory() PreferenceFactory(client=ClientFactory()) PreferenceFactory(client=self.client, content_object=product.category) PreferenceFactory(client=self.client, content_object=product.category.specialty) self.assertCountEqual( Preference.get_preferences_by_product_client(self.product, self.client), [question] )
def test_get_preferences_when_specialty_preferences_exist(self): question_1, question_2 = QuestionFactory.create_batch(2) PreferenceFactory( content_object=self.product.category.specialty, client=self.client, questions=[question_1, question_2] ) PreferenceFactory(content_object=self.product.category.specialty) self.assertCountEqual( Preference.get_preferences_by_product_client(self.product, self.client), [question_1, question_2] )
def test_physician_post_request_valid_data(self): account = AccountFactory( user=self.user, client=self.hospital, role=RoleFactory(priority=RolePriority.PHYSICIAN.value)) product = ProductFactory() questions = PreferenceFactory( questions=QuestionFactory.create_batch(3)).questions.all() data = { 'product': product.id, 'procedure_datetime': '2020-12-21 10:15:20', 'cost_type': 2, 'discounts': [ { 'name': 'CCO', 'value': 10, 'order': 1 }, { 'name': 'Repless', 'value': 20, 'order': 2 }, ], 'preference_questions': [questions[1].id, questions[0].id] } self.assertEqual(Order.objects.count(), 0) response = self.authorized_client.post(self.path, data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(Order.objects.count(), 1) self.assertCountEqual(response.data.pop('preference_questions'), [questions[0].id, questions[1].id]) self.assertDictEqual( response.data, { 'product': product.id, 'procedure_datetime': '2020-12-21T10:15:20Z', 'cost_type': 2, 'discounts': [{ 'name': 'CCO', 'value': 10, 'order': 1 }, { 'name': 'Repless', 'value': 20, 'order': 2 }], 'physician': account.id, 'status': 'New' })
def setUp(self): super().setUp() self.client_1 = ClientFactory() self.product = ProductFactory() self.question_1, self.question_2 = PreferenceFactory( client=self.client_1, content_object=self.product.category, questions=QuestionFactory.create_batch(2)).questions.all() self.path = reverse('api:hospital:order:preferences', args=(self.client_1.id, self.product.id))
def setUp(self): super().setUp() self.account = AccountFactory( user=self.user, role=RoleFactory(priority=RolePriority.PHYSICIAN.value)) self.product = ProductFactory() preference = PreferenceFactory( client=self.account.client, questions=QuestionFactory.create_batch(3)) self.question_1, self.question_2, self.question_3 = preference.questions.all( ) OrderFactory.create_batch(2, physician=self.account, product=self.product, preference_questions=(self.question_1, self.question_2)) OrderFactory.create_batch(3, physician=self.account, product=self.product, preference_questions=(self.question_2, self.question_3)) self.path = reverse('api:hospital:order:order_preferences', args=(self.account.client.id, self.product.id))
def test_get_preferences_return_empty_list(self): PreferenceFactory(client=ClientFactory()) self.assertCountEqual( Preference.get_preferences_by_product_client(self.product, self.client), [] )
def test_preference_to_string(self): preference = PreferenceFactory(name='default preferences') self.assertEqual(str(preference), 'default preferences')