def setUp(self):
        self.fixture = ServiceFixture()
        self.project = self.fixture.project
        self.resource = marketplace_factories.ResourceFactory(
            project=self.project)
        self.resource.scope = self.fixture.volume
        self.resource.save()
        resource_offering = self.resource.offering
        resource_offering.scope = self.fixture.service_settings
        resource_offering.save()
        self.order = marketplace_factories.OrderFactory(project=self.project)
        marketplace_factories.OrderItemFactory(resource=self.resource,
                                               order=self.order)
        self.new_project = structure_factories.ProjectFactory()

        self.start_invoice = invoices_factories.InvoiceFactory(
            customer=self.project.customer,
            year=2020,
            month=1,
            state=invoices_models.Invoice.States.PENDING,
        )

        invoices_factories.InvoiceItemFactory(
            invoice=self.start_invoice,
            project=self.project,
            resource=self.resource,
        )

        self.target_invoice = invoices_factories.InvoiceFactory(
            customer=self.new_project.customer,
            year=2020,
            month=1,
            state=invoices_models.Invoice.States.PENDING,
        )
示例#2
0
 def test_send_notify_if_related_invoice_item_has_not_price(self):
     item = invoices_factories.InvoiceItemFactory(resource=self.resource)
     item.unit_price = 0
     item.save()
     self.assertFalse(item.price)
     tasks.notify_about_stale_resource()
     self.assertEqual(len(mail.outbox), 1)
示例#3
0
    def test_staff_can_delete_customer_with_non_empty_invoice(self):
        factories.InvoiceItemFactory(invoice=self.invoice, unit_price=100)

        self.client.force_authenticate(self.fixture.staff)
        response = self.client.delete(self.url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
示例#4
0
    def test_move_resource_exception_handling(self):
        start_invoice = invoices_factories.InvoiceFactory(
            customer=self.project.customer,
            year=2020,
            month=1,
            state=invoices_models.Invoice.States.PENDING,
        )
        invoices_factories.InvoiceItemFactory(
            invoice=start_invoice, project=self.project, resource=self.resource,
        )

        invoices_factories.InvoiceFactory(
            customer=self.new_project.customer,
            year=2020,
            month=1,
            state=invoices_models.Invoice.States.CREATED,
        )

        response = self.get_response(self.fixture.staff)

        self.resource.refresh_from_db()
        self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
        self.assertEqual(
            response.json(),
            {
                'error_message': 'Resource moving is not possible, because invoice items moving is not possible.'
            },
        )
        self.assertEqual(self.resource.project, self.project)
示例#5
0
    def setUp(self):
        self.tenant = openstack_factories.TenantFactory()
        self.project = self.tenant.service_project_link.project
        self.resource = marketplace_factories.ResourceFactory(
            project=self.project)
        self.resource.scope = self.tenant
        self.resource.save()
        self.order = marketplace_factories.OrderFactory(project=self.project)
        marketplace_factories.OrderItemFactory(resource=self.resource,
                                               order=self.order)
        self.new_project = structure_factories.ProjectFactory()

        self.start_invoice = invoices_factories.InvoiceFactory(
            customer=self.project.customer,
            year=2020,
            month=1,
            state=invoices_models.Invoice.States.PENDING,
        )

        invoices_factories.InvoiceItemFactory(
            invoice=self.start_invoice,
            project=self.project,
            scope=self.resource,
        )

        self.target_invoice = invoices_factories.InvoiceFactory(
            customer=self.new_project.customer,
            year=2020,
            month=1,
            state=invoices_models.Invoice.States.PENDING,
        )
示例#6
0
    def setUp(self):
        self.fixture = invoice_fixtures.InvoiceFixture()

        invoice_factories.InvoiceItemFactory(
            invoice=self.fixture.invoice,
            project=self.fixture.project,
            unit=invoice_models.InvoiceItem.Units.PER_MONTH,
            unit_price=100,
            quantity=1,
        )
        invoice_factories.InvoiceItemFactory(
            invoice=self.fixture.invoice,
            project=self.fixture.project,
            unit=invoice_models.InvoiceItem.Units.PER_DAY,
            unit_price=3,
            quantity=1,
        )
示例#7
0
 def get_invoice_item(self, unit, measured_unit=''):
     return factories.InvoiceItemFactory(
         start=datetime.date(year=2020, month=12, day=1),
         end=datetime.date(year=2020, month=12, day=10),
         quantity=2,
         unit=unit,
         measured_unit=measured_unit,
     )
示例#8
0
 def create_invoice_item(self):
     return factories.InvoiceItemFactory(
         invoice=self.invoice,
         project=self.project,
         unit_price=100,
         quantity=1,
         unit=models.InvoiceItem.Units.QUANTITY,
     )
示例#9
0
    def test_owner_can_not_delete_customer_with_non_empty_invoice(self):
        factories.InvoiceItemFactory(invoice=self.invoice,
                                     unit_price=100,
                                     quantity=10)

        self.client.force_authenticate(self.fixture.owner)
        response = self.client.delete(self.url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
示例#10
0
    def setUp(self):
        self.fixture1 = invoice_fixtures.InvoiceFixture()
        self.fixture2 = invoice_fixtures.InvoiceFixture()

        invoice_factories.InvoiceItemFactory(
            invoice=self.fixture1.invoice,
            project=self.fixture1.project,
            unit=invoice_models.InvoiceItem.Units.QUANTITY,
            unit_price=10,
            quantity=10,
        )
        invoice_factories.InvoiceItemFactory(
            invoice=self.fixture2.invoice,
            project=self.fixture2.project,
            unit=invoice_models.InvoiceItem.Units.QUANTITY,
            unit_price=20,
            quantity=5,
        )
示例#11
0
    def test_filter_order_items_by_marketplace_resource_uuid(self):
        resource_1 = marketplace_factories.ResourceFactory()
        resource_2 = marketplace_factories.ResourceFactory()
        factories.InvoiceItemFactory(
            name='OFFERING-002',
            project=self.fixture.project,
            invoice=self.fixture.invoice,
            unit_price=10,
            resource=resource_1,
            quantity=1,
        )
        factories.InvoiceItemFactory(
            name='OFFERING-003',
            project=self.fixture.project,
            invoice=self.fixture.invoice,
            unit_price=10,
            resource=resource_2,
            quantity=1,
        )
        user = self.fixture.staff
        self.client.force_authenticate(user)

        response = self.client.get(
            factories.InvoiceFactory.get_url(self.fixture.invoice))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['items']), 3)

        response = self.client.get(factories.InvoiceFactory.get_list_url())
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data[0]['items']), 3)

        response = self.client.get(
            factories.InvoiceFactory.get_url(self.fixture.invoice),
            {'resource_uuid': resource_1.uuid.hex},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['items']), 1)

        response = self.client.get(
            factories.InvoiceFactory.get_list_url(),
            {'resource_uuid': resource_1.uuid.hex},
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data[0]['items']), 1)
示例#12
0
    def test_do_not_send_notify_if_stale_resource_does_not_exists(self):
        item = invoices_factories.InvoiceItemFactory(resource=self.resource)
        item.unit_price = 10
        item.quantity = 10
        item.unit = invoices_models.InvoiceItem.Units.QUANTITY
        item.save()

        self.assertTrue(item.price)
        tasks.notify_about_stale_resource()
        self.assertEqual(len(mail.outbox), 0)
示例#13
0
 def setUp(self):
     for price in [200, 100, 300]:
         project = structure_factories.ProjectFactory()
         invoice = invoice_factories.InvoiceFactory(
             customer=project.customer)
         invoice_factories.InvoiceItemFactory(
             invoice=invoice,
             project=project,
             unit_price=price,
             quantity=1,
             unit=invoice_models.InvoiceItem.Units.QUANTITY,
         )
     structure_factories.CustomerFactory()
示例#14
0
 def test_when_invoice_item_is_created_total_is_updated(self, scope):
     invoice = invoice_factories.InvoiceFactory(
         customer=self.fixture.customer)
     invoice_factories.InvoiceItemFactory(invoice=invoice,
                                          project=self.fixture.project,
                                          unit_price=10,
                                          quantity=31)
     estimate = models.PriceEstimate.objects.get(
         scope=getattr(self.fixture, scope))
     self.assertAlmostEqual(
         decimal.Decimal(estimate.total),
         decimal.Decimal(10 * 31),
     )
示例#15
0
 def setUp(self):
     self.prices = [200, 100, 300, 0]
     customers = structure_factories.CustomerFactory.create_batch(len(self.prices))
     for (customer, price) in zip(customers, self.prices):
         if price == 0:
             continue
         project = structure_factories.ProjectFactory(customer=customer)
         invoice = invoice_factories.InvoiceFactory(customer=customer)
         invoice_factories.InvoiceItemFactory(
             invoice=invoice,
             project=project,
             unit_price=price,
             quantity=1,
             unit=invoice_models.InvoiceItem.Units.QUANTITY,
         )