コード例 #1
0
ファイル: tests_filters.py プロジェクト: yxl201908/ralph
    def setUpClass(cls):
        super().setUpClass()

        cls.conf_module1 = ConfigurationModuleFactory(name='abc')
        cls.conf_module2 = ConfigurationModuleFactory(parent=cls.conf_module1)
        cls.conf_class = ConfigurationClassFactory(module=cls.conf_module2)
        cls.dca_1 = DataCenterAssetFactory(
            invoice_date=datetime.date(2015, 1, 1),
            barcode='barcode_one',
            status=DataCenterAssetStatus.new,
        )
        cls.dca_1.tags.add('tag_1')
        cls.dca_2 = DataCenterAssetFactory(
            invoice_date=datetime.date(2015, 2, 1),
            barcode='barcode_two',
            status=DataCenterAssetStatus.liquidated,
        )
        cls.dca_2.management_ip = '10.20.30.40'
        cls.dca_2.tags.add('tag_1')
        cls.dca_3 = DataCenterAssetFactory(
            invoice_date=datetime.date(2015, 3, 1),
            force_depreciation=True,
            status=DataCenterAssetStatus.used,
        )
        cls.dca_3.tags.add('tag1')
        cls.dca_3.tags.add('tag2')
        cls.dca_4 = DataCenterAssetFactory(
            invoice_date=datetime.date(2014, 3, 1),
            rack=RackFactory(),
            configuration_path=cls.conf_class,
        )
        cls.dca_4.tags.add('tag1')
        cls.support_1 = SupportFactory(price=10)
        cls.support_2 = SupportFactory(price=100)
コード例 #2
0
 def setUp(self):
     super().setUp()
     self.support = SupportFactory(
         name='test1',
         support_type=SupportTypeFactory(name='type1'),
         supplier='supplier1')
     self.login_as_user(username='******')
コード例 #3
0
 def test_get_content_type_for_model(self, support_price, objects_count,
                                     expected_price):
     support = SupportFactory(price=support_price)
     BaseObjectsSupportFactory.create_batch(objects_count, support=support)
     export_data = self._export(BaseObjectsSupport)
     self.assertEqual(export_data.dict[0]['support__price_per_object'],
                      str(expected_price))
コード例 #4
0
 def test_support_export_works_with_support_without_price(self):
     support = SupportFactory(price=None)
     BaseObjectsSupportFactory(support=support)
     export_data = self._export(BaseObjectsSupport)
     self.assertEqual(export_data.dict[0]['support__price'], '')
     self.assertEqual(export_data.dict[0]['support__price_per_object'],
                      '0.00')
コード例 #5
0
ファイル: tests.py プロジェクト: wayneburlingame/ralph
 def setUp(self):
     self.dc_1 = DataCenterAssetFactory()
     self.dc_2 = DataCenterAssetFactory()
     self.bo_1 = BackOfficeAssetFactory()
     self.bo_2 = BackOfficeAssetFactory()
     self.support = SupportFactory()
     for obj in [self.dc_1, self.dc_2, self.bo_1, self.bo_2]:
         BaseObjectsSupport.objects.create(support=self.support,
                                           baseobject=obj)
     user = UserFactory()
     self.attachment = Attachment.objects.create_from_file_path(
         __file__, user)
     self.attachment_item = AttachmentItem.objects.attach(
         self.support.pk, get_content_type_for_model(self.support),
         [self.attachment])
コード例 #6
0
ファイル: test_api.py プロジェクト: yxl201908/ralph
 def setUp(self):
     super().setUp()
     self.service_env = ServiceEnvironmentFactory()
     self.support = SupportFactory(name='support1',
                                   service_env=self.service_env)
コード例 #7
0
ファイル: test_api.py プロジェクト: yxl201908/ralph
class SupportAPITests(RalphAPITestCase):
    def setUp(self):
        super().setUp()
        self.service_env = ServiceEnvironmentFactory()
        self.support = SupportFactory(name='support1',
                                      service_env=self.service_env)

    def test_get_supports_list(self):
        url = reverse('support-list')
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], Support.objects.count())

    def test_get_support_details(self):
        url = reverse('support-detail', args=(self.support.id, ))
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['name'], self.support.name)
        self.assertEqual(response.data['contract_id'],
                         self.support.contract_id)
        self.assertEqual(response.data['status'], 'new')
        self.assertEqual(response.data['support_type']['id'],
                         self.support.support_type.id)
        self.assertEqual(response.data['service_env']['service'],
                         self.service_env.service.name)
        self.assertEqual(response.data['service_env']['environment'],
                         self.service_env.environment.name)
        # TODO: baseobjects

    def test_create_support(self):
        region = Region.objects.create(name='EU')
        url = reverse('support-list')
        data = {
            'name': 'support2',
            'region': region.id,
            'contract_id': '12345',
            'status': 'new',
            'date_to': '2020-01-01',
        }
        response = self.client.post(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        support = Support.objects.get(pk=response.data['id'])
        self.assertEqual(support.name, 'support2')
        self.assertEqual(support.region, region)
        self.assertEqual(support.contract_id, '12345')
        self.assertEqual(support.status, SupportStatus.new.id)
        self.assertEqual(support.date_to, date(2020, 1, 1))

    def test_patch_support(self):
        url = reverse('support-detail', args=(self.support.id, ))
        data = {
            'name': 'support2',
            'contract_id': '12345',
            'date_to': '2015-12-31',
        }
        response = self.client.patch(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.support.refresh_from_db()
        self.assertEqual(self.support.name, 'support2')
        self.assertEqual(self.support.contract_id, '12345')
        self.assertEqual(self.support.date_to, date(2015, 12, 31))
コード例 #8
0
 def _init(self, num=10):
     self.supports = SupportFactory.create_batch(num)
     for support in self.supports:
         BackOfficeAssetSupportFactory.create_batch(3, support=support)
         DataCenterAssetSupportFactory.create_batch(2, support=support)