def setUp(self): self.client = ClientFactory(name='PETCARE') self.physician_role = RoleFactory( name='Physician', priority=RolePriority.PHYSICIAN.value) self.admin_role = RoleFactory(name='Hospital Admin', priority=RolePriority.ADMIN.value) self.user = UserFactory(email='*****@*****.**', name='Old Benny Name')
def setUp(self): self.client_1, self.client_2 = ClientFactory.create_batch(2) manufacturer = ManufacturerFactory(image=ImageField( filename='biotronik.jpg')) product = ProductFactory(manufacturer=manufacturer) self.item_1 = ItemFactory(cost=randint(110, 150), cost_type=UNIT_COST, device=DeviceFactory(client=self.client_1, product=product)) self.item_2 = ItemFactory(cost=randint(210, 290), cost_type=UNIT_COST, device=DeviceFactory(client=self.client_1)) self.item_3 = ItemFactory(cost=randint(400, 500), device=DeviceFactory(client=self.client_2)) self.item_4 = ItemFactory(cost=1000, cost_type=UNIT_COST, device=DeviceFactory( client=self.client_1, product=ProductFactory( manufacturer=manufacturer, category=product.category))) physician_role = RoleFactory(priority=RolePriority.PHYSICIAN.value) self.physician_1 = AccountFactory(client=self.client_1, role=physician_role) self.physician_2 = AccountFactory(client=self.client_2, role=physician_role, user=self.physician_1.user) self.physician_3 = AccountFactory(client=self.client_1, role=physician_role)
def setUp(self): super().setUp() self.client_1 = ClientFactory() self.today = datetime.utcnow().date() self.path = reverse('api:hospital:tracker:saving_by_date', args=(self.client_1.id, '2017-08')) physician = AccountFactory( user=self.user, client=self.client_1, role=RoleFactory(priority=RolePriority.PHYSICIAN.value)) device_1 = DeviceFactory(client=self.client_1) self.item_1, self.item_2 = ItemFactory.create_batch(2, device=device_1, saving=200, cost=1000) RepCaseFactory(client=self.client_1, physician=physician, items=[self.item_1, self.item_2], procedure_date=date(2017, 8, 1)) device_2 = DeviceFactory(client=self.client_1) self.item_3 = ItemFactory(device=device_2, saving=150, cost=1000) RepCaseFactory(client=self.client_1, physician=physician, items=[self.item_3], procedure_date=date(2017, 7, 5)) self.item_4 = ItemFactory(device=device_2, saving=200, cost=900) RepCaseFactory(client=self.client_1, items=[self.item_4], procedure_date=date(2015, 1, 1))
def setUp(self): doctor = RoleFactory(name='Physician', priority=1) hospital_admin = RoleFactory(name='Hospital Administrator', priority=10) self.client_1, self.client_2 = ClientFactory.create_batch(2) self.account_1 = AccountFactory(client=self.client_1, role=doctor) self.account_2 = AccountFactory(client=self.client_1, role=hospital_admin) self.account_3, self.account_4 = AccountFactory.create_batch( 2, client=self.client_2, role=doctor) super(ClientAccountsListingAdminTestCase, self).setUp() self.log_in_master_admin() self.visit_reverse('admin:hospital_account_changelist') self.wait_for_element_contains_text('#content h1', 'Select user account to change')
def setUp(self): super().setUp() self.client_1 = ClientFactory() AccountFactory(client=self.client_1, user=self.user, role=RoleFactory(priority=RolePriority.PHYSICIAN.value)) self.category = CategoryFactory() self.path = reverse('api:hospital:tracker:app:purchase_price', args=(self.client_1.id, self.category.id, 'entry', 'unit_cost')) PurchasePriceFactory(category=self.category, client=self.client_1, cost_type=UNIT_COST, level=ProductLevel.ENTRY.value, year=datetime.utcnow().year, min=1000, max=1200, avg=1100) PurchasePriceFactory(category=self.category, client=self.client_1, cost_type=SYSTEM_COST, level=ProductLevel.ADVANCED.value, year=datetime.utcnow().year, min=1200, max=1400, avg=1300)
def test_post_method_with_valid_data(self): self.assertEqual(AuthToken.objects.count(), 0) admin_client = AccountFactory( user=self.user, role=RoleFactory(priority=RolePriority.ADMIN.value)).client response = self.client.post(self.path, { 'email': '*****@*****.**', 'password': '******' }) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertEqual(response.data, {'detail': 'Unauthorized physician access'}) AccountFactory(user=self.user, role=RoleFactory(priority=RolePriority.PHYSICIAN.value)) for token_count in range(1, 3): response = self.client.post(self.path, { 'email': '*****@*****.**', 'password': '******' }) response_data = response.data self.assertEqual(response.status_code, status.HTTP_200_OK) token = response_data.pop('token') self.assertDictEqual( response_data, { 'user': { 'email': '*****@*****.**', 'name': 'Dr. Admin', 'default_client': None, 'admin_client': { 'id': admin_client.id, 'name': admin_client.name, 'image': None } } }) self.assertIsNotNone(token) self.assertEqual(AuthToken.objects.count(), token_count) user, auth_token = TokenAuthentication().authenticate_credentials( token.encode()) self.assertEqual(user, self.user) self.assertEqual(AuthToken.objects.filter(user=self.user).count(), 2)
def setUp(self): super().setUp() self.client_1 = ClientFactory() self.today = datetime.utcnow().date() self.manufacturer_1, self.manufacturer_2 = ManufacturerFactory.create_batch(2) self.physician = AccountFactory(client=self.client_1, role=RoleFactory(priority=RolePriority.PHYSICIAN.value), user=self.user) self.path = reverse('api:hospital:device:marketshare', args=(self.client_1.id,))
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(AccountsInlineAdminTestCase, self).setUp() self.log_in_master_admin() self.client = ClientFactory(name='NS Global') self.client2 = ClientFactory(name='NS Vietnam') self.role = RoleFactory(name='Physician') self.user1 = UserFactory(email='*****@*****.**') self.user2 = UserFactory(email='*****@*****.**') self.specialty_1, self.specialty_2 = SpecialtyFactory.create_batch(2)
def setUp(self): super().setUp() self.client = ClientFactory(name='Central Dental Hospital') self.physician = AccountFactory( user=UserFactory(email='*****@*****.**'), client=self.client).user self.admin = AccountFactory( user=UserFactory(email='*****@*****.**'), client=self.client, role=RoleFactory(priority=RolePriority.ADMIN.value)).user
def test_non_physician_post_request(self): response = self.authorized_client.post(self.path) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data, {'detail': 'Not found.'}) AccountFactory(user=self.user, client=self.hospital, role=RoleFactory(priority=RolePriority.ADMIN.value)) response = self.authorized_client.post(self.path) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.data, {'detail': 'Not found.'})
def setUp(self): super().setUp() self.client_1 = ClientFactory() self.category = CategoryFactory() self.physician = AccountFactory( client=self.client_1, user=self.user, role=RoleFactory(priority=RolePriority.PHYSICIAN.value)) self.path = reverse('api:hospital:tracker:app:physician_app', args=(self.client_1.id, self.category.id, 'entry', 'unit_cost'))
def test_physician_without_any_order(self): client = AccountFactory( role=RoleFactory(priority=RolePriority.PHYSICIAN.value), user=self.user).client path = reverse('api:hospital:order:ordersummary', args=(client.id, )) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertDictEqual(response.data['physician'], { 'id': self.user.id, 'count': 0, 'name': self.user.name })
def setUp(self): super().setUp() self.log_in_master_admin() self.visit_reverse('admin:tracker_repcase_add') self.wait_for_element_contains_text('#content h1', 'Add rep case') physician = RoleFactory(name='Physician', priority=RolePriority.PHYSICIAN.value) admin = RoleFactory(name='Admin', priority=RolePriority.ADMIN.value) client = ClientFactory(name='NSINC') AccountFactory(user=UserFactory(email='*****@*****.**'), role=physician, client=client) AccountFactory(user=UserFactory(email='*****@*****.**'), role=admin, client=client) client = ClientFactory(name='EA') AccountFactory(user=UserFactory(email='*****@*****.**'), role=admin, client=client) ClientFactory(name='UVMC')
def test_physician_post_request_invalid_data(self): AccountFactory(user=self.user, client=self.hospital, role=RoleFactory(priority=RolePriority.PHYSICIAN.value)) response = self.authorized_client.post(self.path) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertDictEqual( response.data, { 'product': ['This field is required.'], 'procedure_datetime': ['This field is required.'], 'preference_questions': ['This field is required.'] }) data = { 'product': 1, 'procedure_datetime': '10:20:30 21-12-2020', 'cost_type': 3, 'discounts': [ { 'name': 'CCO', 'value': 10, 'order': 1 }, { 'name': 'Repless', 'value': 20, 'order': 2 }, ], 'preference_questions': [10] } response = self.authorized_client.post(self.path, data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertDictEqual( response.data, { 'product': ['Invalid pk "1" - object does not exist.'], 'procedure_datetime': [ 'Datetime has wrong format. Use one of these formats instead: ' 'YYYY-MM-DDThh:mm[:ss[.uuuuuu]][+HH:MM|-HH:MM|Z].' ], 'cost_type': ['"3" is not a valid choice.'], 'preference_questions': ['Invalid pk "10" - object does not exist.'] })
def test_view_order_of_other_client(self): client = ClientFactory() path = reverse('api:hospital:order:ordersummary_by_category', args=(client.id, self.category_1.id)) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertDictEqual(response.data, {'detail': 'Unauthorized physician access'}) AccountFactory(client=client, user=self.user, role=RoleFactory(priority=RolePriority.ADMIN.value)) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertDictEqual(response.data, {'detail': 'Unauthorized physician access'})
def setUp(self): super().setUp() specialty = SpecialtyFactory() self.account = AccountFactory.create( role=RoleFactory(priority=RolePriority.PHYSICIAN.value), user=self.user, specialties=(specialty, )) self.category_1 = CategoryFactory(specialty=specialty) self.category_2 = CategoryFactory(specialty=specialty) self.manufacturer_1 = ManufacturerFactory(image=ImageField( filename='Abbott.jpg')) self.manufacturer_2 = ManufacturerFactory(image=ImageField( filename='Simon.jpg')) self.product_1 = ProductFactory(category=self.category_1, manufacturer=self.manufacturer_1) self.product_2 = ProductFactory(category=self.category_2, manufacturer=self.manufacturer_2) self.product_3 = ProductFactory(category=self.category_1, manufacturer=self.manufacturer_2) faker = Faker() self.product_1_orders = faker.random_int(min=1, max=5) self.category_2_orders = faker.random_int(min=1, max=4) self.other_orders = faker.random_int(min=1, max=3) self.total_num_orders = self.product_1_orders + self.category_2_orders + self.other_orders OrderFactory.create_batch(self.product_1_orders, physician=self.account, product=self.product_1) OrderFactory.create_batch(self.category_2_orders, physician=self.account, product=self.product_2) OrderFactory.create_batch( self.other_orders, physician=AccountFactory(client=self.account.client), product=self.product_3) self.path = reverse('api:hospital:order:ordersummary_by_category', args=(self.account.client.id, self.category_1.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 setUp(self): super().setUp() specialty = SpecialtyFactory() self.account = AccountFactory.create( role=RoleFactory(priority=RolePriority.PHYSICIAN.value), user=self.user, specialties=(specialty, )) self.account_foo = AccountFactory.create(user=self.account.user, specialties=(specialty, )) self.category_1 = CategoryFactory(specialty=specialty) self.category_2 = CategoryFactory(specialty=specialty) faker = Faker() self.category_1_orders = faker.random_int(min=1, max=20) self.category_2_orders = faker.random_int(min=1, max=20) self.other_orders = faker.random_int(min=1, max=20) self.total_num_orders = self.category_1_orders + self.category_2_orders + self.other_orders OrderFactory.create_batch( self.category_1_orders, physician=self.account, product=ProductFactory(category=self.category_1)) OrderFactory.create_batch( self.category_2_orders, physician=self.account, product=ProductFactory(category=self.category_2)) OrderFactory.create_batch( self.other_orders, physician=AccountFactory(client=self.account.client), product=ProductFactory(category=self.category_2)) OrderFactory.create_batch( 3, physician=self.account_foo, product=ProductFactory(category=self.category_1)) self.path = reverse('api:hospital:order:ordersummary', args=(self.account.client.id, ))
def setUp(self): super().setUp() self.client_1 = ClientFactory() physician = AccountFactory( client=self.client_1, user=self.user, role=RoleFactory(priority=RolePriority.PHYSICIAN.value)) self.category_1, self.category_2, self.category_3 = CategoryFactory.create_batch( 3) device_1 = DeviceFactory( client=self.client_1, product=ProductFactory(category=self.category_1)) device_2 = DeviceFactory( client=self.client_1, product=ProductFactory(category=self.category_2)) device_3 = DeviceFactory( client=self.client_1, product=ProductFactory(category=self.category_3)) rep_case = RepCaseFactory(client=self.client_1, physician=physician) ItemFactory(device=device_1, rep_case=rep_case, is_used=True) ItemFactory(device=device_2, rep_case=rep_case, is_used=True) ItemFactory(device=device_3, rep_case=RepCaseFactory(), is_used=True) self.path = reverse('api:hospital:tracker:app:categories', args=(self.client_1.id, ))
def test_role_to_string(self): role = RoleFactory() self.assertEqual(str(role), role.name)
def test_account_to_string(self): account = AccountFactory(user=UserFactory(email='*****@*****.**'), role=RoleFactory(name='admin')) self.assertEqual(str(account), 'admin [email protected]')
def setUp(self): super().setUp() self.log_in_master_admin() self.client = ClientFactory(name='NSINC') self.product_1 = ProductFactory( name='Accolade VR', manufacturer=ManufacturerFactory(short_name='MDT')) self.product_2 = ProductFactory( name='Evera MRI XT', manufacturer=ManufacturerFactory(short_name='BIO')) ClientPriceFactory(client=self.client, product=self.product_1, system_cost=100, discounts=[ DiscountFactory(name='CCO', cost_type=SYSTEM_COST, discount_type=PERCENT_DISCOUNT, percent=20, order=2, apply_type=ON_DOCTOR_ORDER), DiscountFactory(name='Repless', cost_type=SYSTEM_COST, discount_type=VALUE_DISCOUNT, value=20, order=1, apply_type=ON_DOCTOR_ORDER), ]) bulk_discount = DiscountFactory(name='Bulk', cost_type=UNIT_COST, discount_type=VALUE_DISCOUNT, value=50, order=1, apply_type=PRE_DOCTOR_ORDER) ClientPriceFactory(client=self.client, product=self.product_2, unit_cost=200, discounts=[ DiscountFactory(name='Repless', cost_type=UNIT_COST, percent=10, order=1, apply_type=ON_DOCTOR_ORDER), bulk_discount ]) device = Device.objects.get(client=self.client, product=self.product_2) item = ItemFactory(device=device, is_used=False, serial_number='SER1234', discounts=[bulk_discount], cost_type=UNIT_COST, purchased_date=date(2018, 1, 1)) self.assertEqual(item.cost, 150) physician = AccountFactory( role=RoleFactory(priority=RolePriority.PHYSICIAN.value), client=self.client) self.rep_case = RepCaseFactory(client=self.client, owners=[physician], physician=physician, procedure_date=date(2018, 9, 10)) self.visit_reverse('admin:tracker_repcase_change', self.rep_case.id) self.wait_for_element_contains_text('#content h1', 'Change rep case')