def setUp(self):
        self.users = {
            'staff':
            structure_factories.UserFactory(username='******', is_staff=True),
            'owner':
            structure_factories.UserFactory(username='******'),
            'administrator':
            structure_factories.UserFactory(username='******'),
            'manager':
            structure_factories.UserFactory(username='******'),
            'regular_user':
            structure_factories.UserFactory(username='******'),
        }

        self.customer = structure_factories.CustomerFactory()
        self.customer.add_user(self.users['owner'],
                               structure_models.CustomerRole.OWNER)
        self.project = structure_factories.ProjectFactory(
            customer=self.customer)
        self.project.add_user(self.users['administrator'],
                              structure_models.ProjectRole.ADMINISTRATOR)
        self.project_group = structure_factories.ProjectGroupFactory(
            customer=self.customer)
        self.project_group.add_user(self.users['manager'],
                                    structure_models.ProjectGroupRole.MANAGER)
        self.project_group.projects.add(self.project)

        self.default_price_list_item = factories.DefaultPriceListItemFactory()
    def test_price_list_item_will_be_deleted_if_default_item_deleted(self):
        default_item = factories.DefaultPriceListItemFactory(resource_content_type=self.openstack_resource_content_type)
        item = models.PriceListItem.objects.get(
            service=self.service, key=default_item.key, item_type=default_item.item_type)

        default_item.delete()

        self.assertFalse(models.PriceListItem.objects.filter(id=item.id).exists())
    def test_new_price_list_item_will_be_created_on_default_item_creation(self):
        default_item = factories.DefaultPriceListItemFactory(resource_content_type=self.openstack_resource_content_type)

        self.assertTrue(models.PriceListItem.objects.filter(
            service=self.service,
            key=default_item.key,
            value=default_item.value,
            units=default_item.units,
            item_type=default_item.item_type).exists()
        )
Esempio n. 4
0
    def test_get_consumable_items_pretty_names(self):
        item_type, key = 'flavor', 'small'
        price_list_item = factories.DefaultPriceListItemFactory(
            item_type=item_type, key=key, name='Pretty name')
        consumable_item = ConsumableItem(item_type, key)

        expected = {consumable_item: price_list_item.name}
        actual = models.DefaultPriceListItem.get_consumable_items_pretty_names(
            price_list_item.resource_content_type, [consumable_item])
        self.assertDictEqual(actual, expected)
    def test_manually_created_price_list_item_key_will_not_be_changed_on_default_item_key_change(self):
        default_item = factories.DefaultPriceListItemFactory(resource_content_type=self.openstack_resource_content_type)
        item = models.PriceListItem.objects.get(
            service=self.service, key=default_item.key, item_type=default_item.item_type)
        item.is_manually_input = True
        item.save()

        default_item.key = 'new_key'
        default_item.save()

        reread_item = models.PriceListItem.objects.get(id=item.id)
        self.assertEqual(default_item.key, reread_item.key)