Esempio n. 1
0
    def test_tenant_with_package_has_plan(self):
        self.fixture = package_fixtures.PackageFixture()
        self.tenant = self.fixture.openstack_package.tenant
        self.template = self.fixture.openstack_package.template

        resource = self.import_resource()
        self.assertEqual(resource.plan.scope, self.template)
Esempio n. 2
0
 def setUp(self):
     self.fixture = packages_fixtures.PackageFixture()
     self.package = self.fixture.openstack_package
     self.item = models.InvoiceItem.objects.get(object_id=self.package.id)
     self.item.start = parse_datetime('2018-10-11')
     self.item.end = parse_datetime('2018-10-15')
     self.item.save()
Esempio n. 3
0
    def test_when_order_item_is_approved_openstack_tenant_is_created(self):
        # Arrange
        fixture = package_fixtures.PackageFixture()
        offering = marketplace_factories.OfferingFactory(
            scope=fixture.openstack_service_settings, type=PLUGIN_NAME)
        order = marketplace_factories.OrderFactory(
            state=marketplace_models.Order.States.REQUESTED_FOR_APPROVAL,
            project=fixture.project,
        )
        plan = marketplace_factories.PlanFactory(
            scope=fixture.openstack_template)
        attributes = dict(
            name='My first VPC',
            description='Database cluster',
            user_username='******',
        )
        order_item = marketplace_factories.OrderItemFactory(
            order=order, offering=offering, attributes=attributes, plan=plan)

        serialized_order = core_utils.serialize_instance(order)
        serialized_user = core_utils.serialize_instance(fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)

        # Assert
        order_item.refresh_from_db()
        self.assertTrue(isinstance(order_item.scope, openstack_models.Tenant))
Esempio n. 4
0
 def test_when_openstack_package_is_created_total_is_updated(self, scope):
     fixture = packages_fixtures.PackageFixture()
     package = fixture.openstack_package
     estimate = models.PriceEstimate.objects.get(
         scope=getattr(fixture, scope))
     self.assertAlmostEqual(decimal.Decimal(estimate.total),
                            decimal.Decimal(package.template.price * 31))
Esempio n. 5
0
 def setUp(self):
     self.fixture = packages_fixtures.PackageFixture()
     self.package = self.fixture.openstack_package
     self.downtime = models.ServiceDowntime.objects.create(
         package=self.package,
         start=parse_datetime('2018-10-05'),
         end=parse_datetime('2018-10-15'),
     )
Esempio n. 6
0
    def _init(self, price, unit):
        self.fixture = package_fixtures.PackageFixture()
        self.project_url = structure_factories.ProjectFactory.get_url(
            self.fixture.project)

        self.offering = marketplace_factories.OfferingFactory(
            scope=self.fixture.openstack_service_settings,
            type=PACKAGE_TYPE,
            state=marketplace_models.Offering.States.ACTIVE,
        )

        self.offering_url = marketplace_factories.OfferingFactory.get_url(
            self.offering)

        plan = self._create_plan(price=price, unit=unit)
        plan_url = marketplace_factories.PlanFactory.get_url(plan)

        # Create SPL
        self.fixture.openstack_spl

        attributes = dict(
            name='My first VPC',
            description='Database cluster',
            user_username='******',
        )

        payload = {
            'project':
            self.project_url,
            'items': [
                {
                    'offering': self.offering_url,
                    'plan': plan_url,
                    'attributes': attributes,
                },
            ]
        }

        user = self.fixture.staff
        self.client.force_login(user)
        url = marketplace_factories.OrderFactory.get_list_url()
        response = self.client.post(url, payload)

        order_item = marketplace_models.OrderItem.objects.get(
            uuid=response.data['items'][0]['uuid'])
        marketplace_utils.process_order_item(order_item, user)
        self.resource = order_item.resource
        callbacks.resource_creation_succeeded(self.resource)

        self.tenant = plan.scope.openstack_packages.first().tenant
        self.tenant.state = openstack_models.Tenant.States.OK
        self.tenant.backend_id = 'tenant id'
        self.tenant.save()

        self.package = package_models.OpenStackPackage.objects.get(
            tenant=self.tenant)
        self.invoice = invoices_models.Invoice.objects.get(
            customer=self.fixture.customer)
Esempio n. 7
0
 def setUp(self):
     self.fixture = package_fixtures.PackageFixture()
     self.offering = marketplace_factories.OfferingFactory(type=PACKAGE_TYPE)
     self.order = marketplace_factories.OrderFactory(project=self.fixture.project)
     self.order_item = marketplace_factories.OrderItemFactory(
         order=self.order,
         offering=self.offering,
         attributes=dict(user_username='******', user_userpassword='******'),
     )
Esempio n. 8
0
 def setUp(self):
     super(TenantCreateTest, self).setUp()
     self.fixture = package_fixtures.PackageFixture()
     self.offering = marketplace_factories.OfferingFactory(
         scope=self.fixture.openstack_service_settings,
         type=PACKAGE_TYPE,
         state=marketplace_models.Offering.States.ACTIVE,
     )
     self.plan = marketplace_factories.PlanFactory(
         scope=self.fixture.openstack_template, offering=self.offering)
Esempio n. 9
0
    def test_plan_is_created_for_template(self):
        fixture = package_fixtures.PackageFixture()
        template = fixture.openstack_package.template

        utils.import_openstack_service_settings(fixture.customer)
        utils.import_openstack_tenant_service_settings()

        offerings = marketplace_models.Offering.objects.filter(scope=fixture.openstack_package.service_settings)
        volume_offering = offerings.get(type=VOLUME_TYPE)

        plan = marketplace_models.Plan.objects.get(scope=template, offering=volume_offering)
        self.assertEqual(plan.components.all().count(), template.components.count())
Esempio n. 10
0
    def test_when_openstack_package_is_extended_project_total_is_updated(self):
        fixture = packages_fixtures.PackageFixture()
        package = fixture.openstack_package
        new_template = packages_factories.PackageTemplateFactory(
            service_settings=fixture.openstack_service_settings)

        view = packages_views.OpenStackPackageViewSet.as_view(
            {'post': 'change'})
        response = common_utils.create_request(view, fixture.owner, {
            'template': new_template.uuid.hex,
            'package': package.uuid.hex,
        })
        self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
Esempio n. 11
0
    def test_plan_is_imported(self):
        fixture = package_fixtures.PackageFixture()
        package = fixture.openstack_package
        template = fixture.openstack_template
        service_settings = package.service_settings

        service = openstack_tenant_factories.OpenStackTenantServiceFactory(settings=service_settings)
        spl = openstack_tenant_factories.OpenStackTenantServiceProjectLinkFactory(service=service)
        self.volume = openstack_tenant_factories.VolumeFactory(service_project_link=spl)

        utils.import_openstack_service_settings(fixture.customer)
        resource = self.import_resource()
        self.assertEqual(resource.plan.scope, template)
Esempio n. 12
0
 def setUp(self):
     super(TenantMutateTest, self).setUp()
     self.fixture = package_fixtures.PackageFixture()
     self.tenant = self.fixture.openstack_package.tenant
     self.offering = marketplace_factories.OfferingFactory(
         type=PACKAGE_TYPE)
     self.plan = marketplace_factories.PlanFactory(
         offering=self.offering, scope=self.fixture.openstack_template)
     self.resource = marketplace_factories.ResourceFactory(
         scope=self.tenant,
         offering=self.offering,
         plan=self.plan,
     )
     self.order = marketplace_factories.OrderFactory(
         project=self.fixture.project,
         state=marketplace_models.Order.States.EXECUTING,
     )
    def test_when_openstack_package_is_extended_project_total_is_updated(self):
        fixture = packages_fixtures.PackageFixture()
        package = fixture.openstack_package
        new_template = packages_factories.PackageTemplateFactory(
            service_settings=fixture.openstack_service_settings)

        self.client.force_authenticate(user=fixture.owner)
        response = self.client.post(
            packages_factories.OpenStackPackageFactory.get_list_url(
                action='change'),
            data={
                'template':
                packages_factories.PackageTemplateFactory.get_url(
                    new_template),
                'package':
                packages_factories.OpenStackPackageFactory.get_url(package),
            })
        self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
Esempio n. 14
0
    def test_invoice_is_created_monthly(self):
        with freeze_time('2016-11-01 00:00:00'):
            fixture = package_fixtures.PackageFixture()
            package = fixture.openstack_package

        with freeze_time('2016-12-01 00:00:00'):
            invoice = models.Invoice.objects.get(customer=fixture.customer)

            # Create monthly invoices
            tasks.create_monthly_invoices()

            # Check that old invoices has changed the state
            invoice.refresh_from_db()
            self.assertEqual(invoice.state, models.Invoice.States.CREATED)

            # Check that new invoice where created with the same openstack items
            new_invoice = models.Invoice.objects.get(
                customer=fixture.customer, state=models.Invoice.States.PENDING)
            self.assertEqual(package, new_invoice.generic_items.first().scope)
Esempio n. 15
0
    def create_order(self, add_attributes=None):
        fixture = package_fixtures.PackageFixture()
        project_url = structure_factories.ProjectFactory.get_url(
            fixture.project)

        offering = marketplace_factories.OfferingFactory(
            scope=fixture.openstack_service_settings,
            type=PLUGIN_NAME,
            state=marketplace_models.Offering.States.ACTIVE,
        )
        offering_url = marketplace_factories.OfferingFactory.get_url(offering)

        plan = marketplace_factories.PlanFactory(
            scope=fixture.openstack_template, offering=offering)
        plan_url = marketplace_factories.PlanFactory.get_url(plan)

        # Create SPL
        fixture.openstack_spl

        attributes = dict(
            name='My first VPC',
            description='Database cluster',
            user_username='******',
        )
        if add_attributes:
            attributes.update(add_attributes)

        payload = {
            'project':
            project_url,
            'items': [
                {
                    'offering': offering_url,
                    'plan': plan_url,
                    'attributes': attributes,
                },
            ]
        }

        self.client.force_login(fixture.staff)
        url = marketplace_factories.OrderFactory.get_list_url()
        return self.client.post(url, payload)
Esempio n. 16
0
 def setUp(self):
     self.fixture = packages_fixtures.PackageFixture()
     self.package = self.fixture.openstack_package
     self.item = models.InvoiceItem.objects.get(scope=self.package)
 def setUp(self):
     self.fixture = packages_fixtures.PackageFixture()
     self.package = self.fixture.openstack_package
 def setUp(self):
     self.fixture = packages_fixtures.PackageFixture()
     self.package = self.fixture.openstack_package
     self.item = models.OpenStackItem.objects.get(package=self.package)
Esempio n. 19
0
 def setUp(self):
     super(TemplateImportTest, self).setUp()
     self.fixture = package_fixtures.PackageFixture()
     self.template = self.fixture.openstack_template
Esempio n. 20
0
 def setUp(self):
     self.fixture = package_fixtures.PackageFixture()