Esempio n. 1
0
 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)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
    def test_set_children(self):
        hospital1, hospital2, hospital22, hospital222, hospital3, hospital33 = ClientFactory.create_batch(6)
        self.assertIsNone(hospital1.parent)
        self.assertIsNone(hospital2.parent)
        self.assertIsNone(hospital22.parent)
        self.assertIsNone(hospital222.parent)
        self.assertIsNone(hospital3.parent)
        self.assertIsNone(hospital33.parent)

        def _refresh_all_clients():
            hospital_list = [hospital1, hospital2, hospital22, hospital222, hospital3, hospital33]
            return [Client.objects.get(pk=h.id) for h in hospital_list]

        hospital2.set_children(children_ids=[hospital22.id])
        hospital22.set_children(children_ids=[hospital222.id])
        self.client.set_children(children_ids=[hospital1.id, hospital2.id])
        hospital3.set_children(children_ids=[hospital33.id])
        hospital1, hospital2, hospital22, hospital222, hospital3, hospital33 = _refresh_all_clients()

        self.assertEqual(hospital1.parent, self.client)
        self.assertEqual(hospital2.parent, self.client)
        self.assertEqual(hospital22.parent, hospital2)
        self.assertEqual(hospital222.parent, hospital22)
        self.assertIsNone(hospital3.parent)
        self.assertEqual(hospital33.parent, hospital3)

        self.assertEqual(hospital1.root_parent_id, self.client.id)
        self.assertEqual(hospital2.root_parent_id, self.client.id)
        self.assertEqual(hospital22.root_parent_id, self.client.id)
        self.assertEqual(hospital222.root_parent_id, self.client.id)
        self.assertEqual(hospital3.root_parent_id, hospital3.id)
        self.assertEqual(hospital33.root_parent_id, hospital3.id)

        self.client.set_children(children_ids=[hospital1.id, hospital3.id])
        hospital1, hospital2, hospital22, hospital222, hospital3, hospital33 = _refresh_all_clients()

        self.assertEqual(hospital1.parent, self.client)
        self.assertEqual(hospital3.parent, self.client)
        self.assertIsNone(hospital2.parent)
        self.assertEqual(hospital22.parent, hospital2)
        self.assertEqual(hospital222.parent, hospital22)
        self.assertEqual(hospital33.parent, hospital3)

        self.assertEqual(hospital1.root_parent_id, self.client.id)
        self.assertEqual(hospital2.root_parent_id, hospital2.id)
        self.assertEqual(hospital22.root_parent_id, hospital2.id)
        self.assertEqual(hospital222.root_parent_id, hospital2.id)
        self.assertEqual(hospital3.root_parent_id, self.client.id)
        self.assertEqual(hospital33.root_parent_id, self.client.id)
    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')
Esempio n. 6
0
    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)
    def setUp(self):
        super().setUp()
        self.log_in_master_admin()
        self.product = ProductFactory(name='pacemaker')
        self.client_1, self.client_2 = ClientFactory.create_batch(2)
        client_price = ClientPriceFactory(product=self.product,
                                          client=self.client_1,
                                          unit_cost=1000,
                                          system_cost=1200)
        DiscountFactory(client_price=client_price,
                        cost_type=UNIT_COST,
                        name='CCO',
                        order=1,
                        percent=10)
        DiscountFactory(client_price=client_price,
                        cost_type=UNIT_COST,
                        name='Repless',
                        order=2,
                        percent=15)

        self.visit_reverse('admin:device_product_change', self.product.id)
        self.wait_for_element_contains_text(
            '.app-device.model-product #content h1', 'Change product')
Esempio n. 8
0
 def setUp(self):
     super(ChildrenClientAdminTestCase, self).setUp()
     self.log_in_master_admin()
     self.client, self.client2, self.client3 = ClientFactory.create_batch(3)