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_session_authorized_admin_user(self): response = self.authorized_admin_client.get(self.path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data, []) product_1, product_2 = ProductFactory.create_batch(2, manufacturer=self.manufacturer) product_3 = ProductFactory(category=product_1.category, manufacturer=self.manufacturer) ProductFactory(category=CategoryFactory(specialty=product_2.category.specialty)) response = self.authorized_admin_client.get(self.path) self.assertCountEqual(response.data, [ {'id': product_1.id, 'name': product_1.name}, {'id': product_2.id, 'name': product_2.name}, {'id': product_3.id, 'name': product_3.name}, ]) path = reverse('api:staff:rebatable_items', args=(self.manufacturer.id, 'category')) self.assertEqual(path, f'/api/staff/manufacturers/{self.manufacturer.id}/category') response = self.authorized_admin_client.get(path) self.assertCountEqual(response.data, [ {'id': product_1.category.id, 'name': product_1.category.name}, {'id': product_2.category.id, 'name': product_2.category.name}, ]) path = reverse('api:staff:rebatable_items', args=(self.manufacturer.id, 'specialty')) self.assertEqual(path, f'/api/staff/manufacturers/{self.manufacturer.id}/specialty') response = self.authorized_admin_client.get(path) self.assertCountEqual(response.data, [ {'id': product_1.category.specialty.id, 'name': product_1.category.specialty.name}, {'id': product_2.category.specialty.id, 'name': product_2.category.specialty.name}, ]) path = f'/api/staff/manufacturers/{self.manufacturer.id}/manufacturer' response = self.authorized_admin_client.get(path) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
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 test_rebatable_items(self): for model_name in ['product', 'category', 'specialty']: self.assertCountEqual( self.manufacturer.rebatable_items(model_name), []) specialty_1, specialty_2 = SpecialtyFactory.create_batch(2) category_1 = CategoryFactory(specialty=specialty_1) category_2, category_3 = CategoryFactory.create_batch( 2, specialty=specialty_2) product_1 = ProductFactory(category=category_1, manufacturer=self.manufacturer) product_2 = ProductFactory(category=category_2, manufacturer=self.manufacturer) product_3 = ProductFactory(category=category_3, manufacturer=self.manufacturer) product_4 = ProductFactory(category=category_1, manufacturer=self.manufacturer) ProductFactory(category=category_3) self.assertCountEqual(self.manufacturer.rebatable_items('specialty'), [specialty_1, specialty_2]) self.assertCountEqual(self.manufacturer.rebatable_items('category'), [category_1, category_2, category_3]) self.assertCountEqual(self.manufacturer.rebatable_items('product'), [product_1, product_2, product_3, product_4]) self.assertCountEqual( self.manufacturer.rebatable_items('manufacturer'), [])
def test_return_marketshare_with_procedure_date(self): device = DeviceFactory(client=self.client_1, product=ProductFactory(manufacturer=self.manufacturer_1)) device_2 = DeviceFactory(client=self.client_1, product=ProductFactory(manufacturer=self.manufacturer_2)) item_1, item_2 = ItemFactory.create_batch(2, device=device) item_3, item_4 = ItemFactory.create_batch(2, device=device_2) RepCaseFactory(client=self.client_1, physician=self.physician, items=[item_1, item_3], procedure_date=date(2018, 5, 1)) RepCaseFactory(client=self.client_1, physician=self.physician, items=[item_2, item_4], procedure_date=date(2018, 4, 30)) path = reverse('api:hospital:device:marketshare_by_date', args=(self.client_1.id, '2018-5')) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, [ { 'name': 'May, 2018', 'marketshare': [{ 'spend': f'{item_1.cost:.2f}', 'units': 1, 'name': self.manufacturer_1.display_name, 'id': self.manufacturer_1.id, }, { 'spend': f'{item_3.cost:.2f}', 'units': 1, 'name': self.manufacturer_2.display_name, 'id': self.manufacturer_2.id, }], }, { 'name': f'2018 to Date', 'marketshare': [{ 'spend': f'{(item_1.cost + item_2.cost):.2f}', 'units': 2, 'name': self.manufacturer_1.display_name, 'id': self.manufacturer_1.id, }, { 'spend': f'{(item_3.cost + item_4.cost):.2f}', 'units': 2, 'name': self.manufacturer_2.display_name, 'id': self.manufacturer_2.id, }], } ]) path = reverse('api:hospital:device:marketshare_by_date', args=(self.client_1.id, '2018-04')) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, [ { 'name': 'April, 2018', 'marketshare': [{ 'spend': f'{item_2.cost:.2f}', 'units': 1, 'name': self.manufacturer_1.display_name, 'id': self.manufacturer_1.id, }, { 'spend': f'{item_4.cost:.2f}', 'units': 1, 'name': self.manufacturer_2.display_name, 'id': self.manufacturer_2.id, }], }, { 'name': f'2018 to Date', 'marketshare': [{ 'spend': f'{(item_1.cost + item_2.cost):.2f}', 'units': 2, 'name': self.manufacturer_1.display_name, 'id': self.manufacturer_1.id, }, { 'spend': f'{(item_3.cost + item_4.cost):.2f}', 'units': 2, 'name': self.manufacturer_2.display_name, 'id': self.manufacturer_2.id, }], } ])
def setUp(self): super(ProductAdminTestCase, self).setUp() self.log_in_master_admin() self.specialty = SpecialtyFactory(name='Cardiac Rhythm Management') CategoryFactory.create_batch(2, specialty=self.specialty) self.product_1, self.product_2 = ProductFactory.create_batch(2, model_number='1456Q-86') ProductFactory.create_batch(3)
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 test_devices_by_specialties(self): specialty1, specialty2 = SpecialtyFactory.create_batch(2) category1 = CategoryFactory(specialty=specialty1) category2, category3 = CategoryFactory.create_batch(2, specialty=specialty2) product1 = DeviceFactory(client=self.client, product=ProductFactory(name='Device1', category=category1)).product product2 = DeviceFactory(client=self.client, product=ProductFactory(name='Device2', category=category2)).product product3 = DeviceFactory(client=self.client, product=ProductFactory(name='Device3', category=category3)).product self.assertDictEqual(self.client.devices_by_specialties(), { specialty1.id: {'name': specialty1.name, 'products': [(product1.id, product1.name)]}, specialty2.id: {'name': specialty2.name, 'products': [(product2.id, product2.name), (product3.id, product3.name)]} })
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_return_marketshare_without_specify_procedure_date(self): device = DeviceFactory(client=self.client_1, product=ProductFactory(manufacturer=self.manufacturer_1)) item_1, item_2 = ItemFactory.create_batch(2, device=device) RepCaseFactory(client=self.client_1, physician=self.physician, items=[item_1, item_2], procedure_date=self.today) response = self.authorized_client.get(self.path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, [ { 'name': f'{month_name[self.today.month]}, {self.today.year}', 'marketshare': [ { 'spend': f'{(item_1.cost + item_2.cost):.2f}', 'units': 2, 'name': self.manufacturer_1.display_name, 'id': self.manufacturer_1.id, }, ], }, { 'name': f'{self.today.year} to Date', 'marketshare': [ { 'spend': f'{(item_1.cost + item_2.cost):.2f}', 'units': 2, 'name': self.manufacturer_1.display_name, 'id': self.manufacturer_1.id, }, ], } ])
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): 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 test_class_method_update_purchase_price(self): def update_client_purchase_price(): PurchasePrice.update(category=self.purchase_price.category, client=self.purchase_price.client, year=self.purchase_price.year, level=self.purchase_price.level, cost_type=self.purchase_price.cost_type) self.purchase_price.refresh_from_db() self.assertEqual(self.purchase_price.avg, Decimal(1000)) self.assertIsNone(self.purchase_price.min) self.assertEqual(self.purchase_price.max, 0) update_client_purchase_price() self.assertEqual(self.purchase_price.avg, Decimal(0)) self.assertIsNone(self.purchase_price.min) self.assertEqual(self.purchase_price.max, 0) item = ItemFactory(cost_type=self.purchase_price.cost_type, is_used=True, device=DeviceFactory(client=self.purchase_price.client, product=ProductFactory(category=self.purchase_price.category, level=self.purchase_price.level))) rep_case = RepCaseFactory(procedure_date=date(2017, 12, 31), items=[item]) update_client_purchase_price() self.assertEqual(self.purchase_price.avg, Decimal(0)) self.assertIsNone(self.purchase_price.min) self.assertEqual(self.purchase_price.max, 0) rep_case.procedure_date = date(2018, 1, 1) rep_case.save() update_client_purchase_price() self.assertEqual(self.purchase_price.avg, item.cost) self.assertEqual(self.purchase_price.min, item.cost) self.assertEqual(self.purchase_price.max, item.cost)
def _create_product_for_client(self, product, category, specialty, client): DeviceFactory( client=client, product=ProductFactory( name=product, category=CategoryFactory(name=category, specialty=specialty) ))
def test_view_order_preferences_without_any_order(self): other_product = ProductFactory() path = reverse('api:hospital:order:order_preferences', args=(self.account.client.id, other_product.id)) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, [])
def test_get_device_items(self): self.assertCountEqual( self.rebate.get_device_items(self.rebate.rebated_items), []) self.assertCountEqual( self.rebate.get_device_items(self.rebate.eligible_items), []) item_1 = ItemFactory(device=DeviceFactory(client=self.rebate.client, product=self.product_1), purchased_date=date(2018, 7, 16), is_used=False, purchase_type=BULK_PURCHASE) item_2 = ItemFactory(device=DeviceFactory(client=self.rebate.client, product=self.product_2), purchased_date=date(2018, 7, 31), is_used=True, purchase_type=BULK_PURCHASE) ItemFactory(device=DeviceFactory(client=self.rebate.client, product=ProductFactory()), purchased_date=date(2018, 7, 16), is_used=False, purchase_type=CONSIGNMENT_PURCHASE) ItemFactory(device=item_2.device, purchased_date=date(2017, 12, 31), is_used=False, purchase_type=CONSIGNMENT_PURCHASE) self.assertCountEqual( self.rebate.get_device_items(self.rebate.eligible_items), [item_1]) self.assertCountEqual( self.rebate.get_device_items(self.rebate.rebated_items), [item_1, item_2]) self.assertCountEqual( self.rebate.get_device_items(RebatableItem.objects.none()), [item_1, item_2])
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_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.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 test_get_method_requires_purchase_price_aggregation(self): path = reverse('api:hospital:tracker:app:purchase_price', args=(self.client_1.id, self.category.id, 'advanced', 'unit_cost')) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, {'min': None, 'max': 0, 'avg': 0}) path = reverse('api:hospital:tracker:app:purchase_price', args=(self.client_1.id, self.category.id, 'entry', 'system_cost')) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, {'min': None, 'max': 0, 'avg': 0}) entry = ProductLevel.ENTRY.value item_1 = ItemFactory(cost_type=SYSTEM_COST, cost=100, is_used=True, device=DeviceFactory(client=self.client_1, product=ProductFactory( category=self.category, level=entry))) item_2 = ItemFactory(cost_type=SYSTEM_COST, cost=203, is_used=True, device=DeviceFactory(client=self.client_1, product=ProductFactory( category=self.category, level=entry))) item_3 = ItemFactory(device=DeviceFactory(client=self.client_1), cost_type=UNIT_COST, cost=100, is_used=True) RepCaseFactory(procedure_date=datetime.utcnow().date(), items=[item_1, item_2]) RepCaseFactory(procedure_date=datetime.utcnow().date(), items=[item_3]) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, { 'min': '100.00', 'max': '200.00', 'avg': '151.50' })
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 test_show_list_of_categories(self): self.log_in_master_admin() self.specialty, specialty = SpecialtyFactory.create_batch(2) self.category = CategoryFactory(name='Total Knee System', specialty=self.specialty) CategoryFactory.create_batch(2, specialty=specialty) ProductFactory.create_batch(3, category=self.category) self.visit_reverse('admin:device_specialty_changelist') self.wait_for_element_contains_text('#content h1', 'Select specialty to change') self.assert_elements_count('#result_list tbody tr', count=2) self.find_link(self.specialty.name).click() self.wait_for_element_contains_text('#content h1', 'Select category to change') self.assert_elements_count('#result_list tbody tr', count=1) self.wait_for_element_contains_text('#result_list tbody tr', 'Total Knee System') self.find_link(self.category.name).click() self.wait_for_element_contains_text('#content h1', 'Select product to change') self.assert_elements_count('#result_list tbody tr', count=3)
def test_sub_categories_listing(self): self.category_2.parent = self.category_1 self.category_2.save() ProductFactory.create_batch(2, category=self.category_2) self.visit_reverse('admin:device_specialty_changelist') self.wait_for_element_contains_text('.model-specialty.change-list #content h1', 'Select specialty to change') self.assert_elements_count('#result_list tbody tr .field-specialty_name', count=1) self.find_link(self.specialty.name).click() self.wait_for_element_contains_text('.model-category.change-list #content h1', 'Select category to change') self.assert_elements_count('#result_list tbody tr .field-category_name', count=1) self.find_link(self.category_1.name).click() self.wait_for_element_contains_text('#result_list tbody tr .field-category_name', self.category_2.name) self.find_link(self.category_2.name).click() self.wait_for_element_contains_text('.model-product.change-list #content h1', 'Select product to change') self.assert_elements_count('#result_list tbody tr .field-name', count=2)
def setUp(self): product = ProductFactory() manufacturer = product.manufacturer client = ClientFactory() device = DeviceFactory(client=client, product=product) item_1 = ItemFactory(device=device, cost=100, purchased_date=date(2018, 4, 1), is_used=False) item_2 = ItemFactory(device=device, cost=120, purchased_date=date(2018, 4, 1), is_used=True) item_3 = ItemFactory(device=DeviceFactory( client=client, product=ProductFactory(manufacturer=manufacturer)), cost=500, purchased_date=date(2018, 12, 24), is_used=False) ItemFactory(device=device, cost=100, purchased_date=date(2017, 12, 23), is_used=True) self.rebate = RebateFactory(client=client, manufacturer=manufacturer, start_date=date(2018, 1, 1), end_date=date(2018, 12, 31)) self.tier = TierFactory(upper_bound=30, tier_type=MARKETSHARE, rebate=self.rebate) RebatableItemFactory(rebate=self.rebate, item_type=REBATED_ITEM, content_object=product) self.eligible_purchased_items = self.rebate.get_device_items( self.rebate.eligible_items) self.assertCountEqual(self.eligible_purchased_items, [item_1, item_2, item_3]) self.rebated_purchased_items = self.rebate.get_device_items( self.rebate.rebated_items) self.assertCountEqual(self.rebated_purchased_items, [item_1, item_2])
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_physician_without_any_order(self): client = self.account.client category = CategoryFactory() OrderFactory(physician=AccountFactory(client=client), product=ProductFactory(category=category)) path = reverse('api:hospital:order:ordersummary_by_category', args=(client.id, category.id)) response = self.authorized_client.get(path) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data, [])
def setUp(self): super().setUp() self.product = ProductFactory() self.shared_image = SharedImageFactory(name='url', image=ImageField(filename='test_image.jpg')) self.category_feature = CategoryFeatureFactory(name='website', category=self.product.category) self.feature_1 = FeatureFactory(name='size', value='24/11', product=self.product, category_feature=None) self.feature_2 = FeatureFactory(name='website', value='http://biotronik.com', shared_image=self.shared_image, category_feature=self.category_feature, product=self.product) self.feature_3 = FeatureFactory(name='shock', value='yes', shared_image=self.shared_image, product=self.product, category_feature=None) FeatureFactory(product=self.product, value=None) self.path = reverse('api:device:features', args=(self.product.id,))
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)
class ProductTestCase(TestCase): def setUp(self): self.specialty = SpecialtyFactory(name='Structural Heart') self.product = ProductFactory(category=CategoryFactory( specialty=self.specialty)) def test_to_string_returns_product_name(self): self.assertEqual(str(self.product), self.product.name) def test_specialty_property(self): self.assertEqual(self.product.specialty, self.specialty) def test_missing_category_features_property(self): category_features = CategoryFeatureFactory.create_batch( 2, category=self.product.category) self.assertCountEqual(self.product.missing_category_features, category_features) FeatureFactory(product=self.product) FeatureFactory(product=self.product, category_feature=CategoryFeatureFactory()) FeatureFactory(product=self.product, name=category_features[1]) self.assertCountEqual(self.product.missing_category_features, category_features[0:1]) FeatureFactory(product=self.product, name=category_features[0].name) self.assertEqual(self.product.missing_category_features.count(), 0) def test_remove_invalid_category_features(self): category_features = CategoryFeatureFactory.create_batch( 2, category=self.product.category) for category_feature in category_features: FeatureFactory(product=self.product, name=category_feature.name) FeatureFactory(product=self.product) self.assertEqual(Feature.objects.count(), 3) self.assertEqual(CategoryFeature.objects.count(), 3) self.product.category = CategoryFactory() self.product.remove_invalid_category_features() self.assertEqual(Feature.objects.count(), 0)