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.log_in_master_admin() biotronic = ManufacturerFactory(name='Biotronic') medtronik = ManufacturerFactory(name='Medtronik') ClientFactory(name='Children Hospital') ClientFactory(name='Central hospital') category = CategoryFactory(name='Balloons', specialty=SpecialtyFactory(name='Accessories')) ProductFactory(name='Entrisa', manufacturer=medtronik, category=CategoryFactory(name='DDD pacemaker', specialty=SpecialtyFactory(name='CRD'))) ProductFactory(name='Apex', manufacturer=medtronik, category=category) ProductFactory(name='NC Quantum', manufacturer=biotronic, category=category)
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 setUp(self): super().setUp() self.category = CategoryFactory() self.client_1 = ClientFactory() AccountFactory.create(user=self.user, client=self.client_1) self.product_1, self.product_2 = ProductFactory.create_batch(2, category=self.category) self.feature_1 = FeatureFactory(name='Wireless', product=self.product_2, shared_image=SharedImageFactory(image=ImageField(filename='wireless.jpg'))) self.feature_2, self.feature_3 = FeatureFactory.create_batch(2, product=self.product_2) price_1 = ClientPriceFactory(client=self.client_1, product=self.product_1, unit_cost=200, system_cost=300) price_2 = ClientPriceFactory(client=self.client_1, product=self.product_2, unit_cost=250, system_cost=300) ClientPriceFactory(client=self.client_1, unit_cost=250, system_cost=300, product=ProductFactory(enabled=False),) self.discount_1 = DiscountFactory( client_price=price_1, discount_type=VALUE_DISCOUNT, value=50, name='CCO', order=1, percent=0, apply_type=ON_DOCTOR_ORDER, cost_type=UNIT_COST, shared_image=SharedImageFactory(image=ImageField(filename='CCO.png')) ) self.discount_2 = DiscountFactory( client_price=price_2, discount_type=PERCENT_DISCOUNT, percent=10, cost_type=SYSTEM_COST, order=2, apply_type=ON_DOCTOR_ORDER, name='Repless', shared_image=SharedImageFactory(image=ImageField(filename='repless.png')) ) self.discount_3 = DiscountFactory( client_price=price_1, discount_type=PERCENT_DISCOUNT, value=0, name='Bulk', order=2, percent=15, apply_type=PRE_DOCTOR_ORDER, cost_type=UNIT_COST, shared_image=None) device = self.client_1.device_set.get(product=self.product_1) ItemFactory(device=device, discounts=[self.discount_3], purchase_type=BULK_PURCHASE, is_used=False, cost_type=UNIT_COST) self.path = reverse('api:hospital:device:products', args=(self.client_1.id, self.category.id,))
def test_update_cost(self): client = ClientFactory() product = ProductFactory() discount_1 = DiscountFactory(cost_type=UNIT_COST, value=10, discount_type=VALUE_DISCOUNT, apply_type=PRE_DOCTOR_ORDER) discount_2 = DiscountFactory(cost_type=SYSTEM_COST, percent=20, discount_type=PERCENT_DISCOUNT, apply_type=ON_DOCTOR_ORDER) client_price = ClientPriceFactory(product=product, client=client, unit_cost=100, system_cost=150, discounts=[discount_1, discount_2]) device = client.device_set.get(product=product) unit_item = ItemFactory(device=device, cost_type=UNIT_COST, purchased_date=date(2017, 9, 8)) system_item = ItemFactory(device=device, cost_type=SYSTEM_COST, is_used=True, rep_case=RepCaseFactory(procedure_date=date(2018, 7, 9))) item = ItemFactory(cost=1000) unit_item.update_cost(discounts=[]) system_item.update_cost(discounts=[]) item.update_cost(discounts=[]) self.assertEqual((unit_item.cost, unit_item.saving), (client_price.unit_cost, 0)) self.assertEqual((system_item.cost, system_item.saving), (client_price.system_cost, 0)) self.assertEqual((item.cost, item.saving), (item.cost, 0)) unit_item.update_cost(discounts=[discount_1, discount_2]) system_item.update_cost(discounts=[discount_1, discount_2]) item.update_cost(discounts=[discount_1, discount_2]) self.assertEqual((unit_item.cost, unit_item.saving), (Decimal('90.00'), 0)) self.assertEqual((system_item.cost, system_item.saving), (Decimal('120.00'), 30)) self.assertEqual((item.cost, item.saving), (Decimal('1000.00'), 0))
def test_get_method_return_403_permission_denied(self): path = reverse('api:hospital:tracker:app:categories', args=(ClientFactory().id, )) 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() 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 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): self.client = ClientFactory(name='UVMC') manufacturer = ManufacturerFactory(name='Medtronic') self.product = ProductFactory(model_number='SESR01', manufacturer=manufacturer) client_price = ClientPriceFactory(product=self.product, client=self.client) self.bulk_discount = DiscountFactory(name='Bulk', client_price=client_price, apply_type=PRE_DOCTOR_ORDER, cost_type=UNIT_COST, discount_type=PERCENT_DISCOUNT, percent=10, value=0, order=1) self.discount_2 = DiscountFactory(client_price=client_price, apply_type=ON_DOCTOR_ORDER, cost_type=SYSTEM_COST) self.device = self.product.device_set.get(client=self.client) self.device.hospital_number = '70669' self.device.save() self.item = ItemFactory(device=self.device, serial_number='PJN7204267', cost_type=SYSTEM_COST, discounts=[self.discount_2]) self.xls_file_path = os.path.join(FIXTURE_DIR, 'items.xls') self._prepare_xls_file()
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): self.client_price = ClientPriceFactory( product=ProductFactory(name='product', model_number='001'), client=ClientFactory(name='Central hospital'), unit_cost=18000, system_cost=9000) self.unit_cost_discount_1 = DiscountFactory( cost_type=UNIT_COST, order=1, client_price=self.client_price, percent=15, name='Bulk', apply_type=PRE_DOCTOR_ORDER) self.unit_cost_discount_2 = DiscountFactory( cost_type=UNIT_COST, order=2, client_price=self.client_price, percent=10, name='CCO') self.system_cost_discount_1 = DiscountFactory( cost_type=SYSTEM_COST, order=4, client_price=self.client_price, percent=15, name='Bulk', apply_type=PRE_DOCTOR_ORDER) self.system_cost_discount_2 = DiscountFactory( cost_type=SYSTEM_COST, order=2, client_price=self.client_price, percent=10, name='CCO')
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_view_order_of_other_client(self): super().setUp(self.account.user) response = self.authorized_client.get( reverse('api:hospital:order:ordersummary', args=(ClientFactory().id, ))) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) self.assertDictEqual(response.data, {'detail': 'Unauthorized physician access'})
def setUp(self): super().setUp() self.path = reverse('api:hospital:clients') self.client_1, self.client_2 = ClientFactory.create_batch(2) AccountFactory(user=self.user, client=self.client_1) AccountFactory(user=self.user, client=self.client_2) AccountFactory(client=self.client_2) AccountFactory.create_batch(2)
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 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 setUp(self): super().setUp() self.log_in_master_admin() self.specialty = SpecialtyFactory(name='Cardiac Rhythm Management') self.client = ClientFactory() category = CategoryFactory(specialty=self.specialty) product = ProductFactory(category=category) DeviceFactory(client=self.client) ClientPriceFactory(client=self.client, product=product)
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 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 test_get_method_return_404_error(self): client = ClientFactory() path = reverse('api:hospital:device:items', args=(client.id, self.product.id)) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) product = ProductFactory() path = reverse('api:hospital:device:items', args=(self.client_1.id, product.id)) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def setUp(self): super(FilterClientsByDevicesAdminTestCase, self).setUp() self.client1 = ClientFactory(name='NS Global') self.client2 = ClientFactory(name='NS Vietnam') self.client3 = ClientFactory(name='International hospital') specialty = SpecialtyFactory(name='Structural Heart') specialty2 = SpecialtyFactory(name='Interventional Cardiology') SpecialtyFactory(name='Neuromodulation') self._create_product_for_client(product='LINQ', category='TAVR Delivery System', specialty=specialty, client=self.client3) self._create_product_for_client(product='Pacemaker', category='TAVR Implant System', specialty=specialty, client=self.client2) self._create_product_for_client(product='Assurity', category='Drug Eluting Stents', specialty=specialty2, client=self.client1) self.log_in_master_admin() self.visit_reverse('admin:hospital_client_changelist') self.wait_for_element_contains_text('.model-client.change-list #content h1', 'Select client to change')
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 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 setUp(self): super().setUp() self.log_in_master_admin() self.client = ClientFactory() self.product = ProductFactory() ClientPriceFactory(client=self.client, product=self.product) device = self.client.device_set.get(product=self.product) self.discounts = DiscountFactory.create_batch(2) self.item = ItemFactory(device=device, purchase_type=BULK_PURCHASE, is_used=False, discounts=self.discounts)
def setUp(self): super().setUp() self.client_1 = ClientFactory() self.product = ProductFactory() self.path = reverse('api:hospital:device:items', args=(self.client_1.id, self.product.id)) AccountFactory(client=self.client_1, user=self.user) ItemFactory.create_batch(2, device=DeviceFactory(product=self.product)) ItemFactory(device=DeviceFactory(client=self.client_1)) device = DeviceFactory(client=self.client_1, product=self.product) self.item_1, self.item_2 = ItemFactory.create_batch(2, device=device, is_used=False, purchase_type=BULK_PURCHASE) ItemFactory(device=device, purchase_type=CONSIGNMENT_PURCHASE, is_used=False) ItemFactory(device=device, purchase_type=BULK_PURCHASE, is_used=True)
def setUp(self): super().setUp() self.log_in_master_admin() self.client = ClientFactory(name='EA') specialty_1 = SpecialtyFactory(name='Structure Heart') specialty_2 = SpecialtyFactory(name='Orthopedic') CategoryFactory(name='DDD Pacemakers', specialty=specialty_1) CategoryFactory(name='VVI ICD', specialty=specialty_2) QuestionFactory(name='Longevity') QuestionFactory(name='Remote support') self.visit_reverse('admin:order_preference_add') self.wait_for_element_contains_text('.model-preference.change-form', 'Add preference')
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 setUp(self): super().setUp() self.category_1, self.category_2 = CategoryFactory.create_batch(2) self.client_1, self.client_2 = ClientFactory.create_batch(2) self.user.default_client = self.client_1 self.user.save() self.path = reverse('api:hospital:device:categories', args=(self.client_1.id,)) self.account_1 = AccountFactory.create(user=self.user, client=self.client_1) self.account_2 = AccountFactory.create(user=self.user, client=self.client_2) ClientPriceFactory(client=self.client_1, product=ProductFactory(category=self.category_1)) ClientPriceFactory(client=self.client_1, product=ProductFactory(category=self.category_2)) ClientPriceFactory(client=self.client_2, product=ProductFactory(category=self.category_1)) ClientPriceFactory.create_batch(3)
def test_upload_client_image(self): with patch('django.core.files.storage.default_storage._wrapped', self.storage_mock): client = ClientFactory(name='Central Hospital', image=None) upload_file_path = os.path.join(settings.FIXTURE_DIR, 'client_image.png') self.visit_reverse('admin:hospital_client_change', client.id) self.wait_for_element_contains_text('#content h1', 'Change client') self.assert_element_to_disappear('.file-upload') self.fill_form_field_with_text('image', upload_file_path) self.click_save_and_continue() self.wait_for_element_contains_text('.file-upload', 'Currently: test_image.jpg') self.assert_element_attribute_value('.file-upload img', self.image_data, attr='src')
def test_prefetch_price_with_discounts(self): client_1, client_2 = ClientFactory.create_batch(2) client_price_1 = ClientPriceFactory(product=self.product_1, client=client_1) client_price_2 = ClientPriceFactory(product=self.product_2, client=client_2) discount_1 = DiscountFactory(cost_type=UNIT_COST, client_price=client_price_1) discount_2 = DiscountFactory(cost_type=SYSTEM_COST, client_price=client_price_1) discount_3 = DiscountFactory(cost_type=SYSTEM_COST, client_price=client_price_2) ClientPriceFactory(product=self.product_1, client=ClientFactory()) products = Product.objects.prefetch_price_with_discounts( client_1).order_by('id') self.assertEqual(list(products), [self.product_1, self.product_2]) self.assertEqual(len(products[0].client_prices), 1) self.assertEqual(len(products[1].client_prices), 0) self.assertCountEqual(products[0].client_prices[0].unit_discounts, [discount_1]) self.assertCountEqual(products[0].client_prices[0].system_discounts, [discount_2]) products = Product.objects.prefetch_price_with_discounts( client_2).order_by('id') self.assertEqual(list(products), [self.product_1, self.product_2]) self.assertEqual(len(products[0].client_prices), 0) self.assertEqual(len(products[1].client_prices), 1) self.assertCountEqual(products[1].client_prices[0].unit_discounts, []) self.assertCountEqual(products[1].client_prices[0].system_discounts, [discount_3]) products = Product.objects.prefetch_price_with_discounts( ClientFactory()).order_by('id') self.assertEqual(list(products), [self.product_1, self.product_2]) self.assertEqual(len(products[0].client_prices), 0) self.assertEqual(len(products[1].client_prices), 0)