Esempio n. 1
0
 def test_add_provider_billing_source_non_aws(self):
     """Tests that add a non-AWS billing source to a Source."""
     s3_bucket = {'bucket': 'test-bucket'}
     storage.add_provider_sources_network_info(self.test_source_id,
                                               'OCP Account', 'OCP', 1)
     with self.assertRaises(SourcesStorageError):
         storage.add_provider_billing_source(self.test_source_id, s3_bucket)
Esempio n. 2
0
 def test_add_provider_billing_source_non_existent(self):
     """Tests that add a billing source to a non-existent Source."""
     s3_bucket = {'bucket': 'test-bucket'}
     storage.add_provider_sources_network_info(self.test_source_id + 1,
                                               'AWS Account', 'AWS', 1)
     with self.assertRaises(SourcesStorageError):
         storage.add_provider_billing_source(self.test_source_id, s3_bucket)
Esempio n. 3
0
 def test_add_provider_billing_source(self):
     """Tests that add an AWS billing source to a Source."""
     s3_bucket = {'bucket': 'test-bucket'}
     storage.add_provider_sources_network_info(self.test_source_id, faker.uuid4(),
                                               'AWS Account', 'AWS', 1)
     storage.add_provider_billing_source({'source_id': self.test_source_id}, s3_bucket)
     self.assertEqual(Sources.objects.get(source_id=self.test_source_id).billing_source, s3_bucket)
Esempio n. 4
0
def billing_source(request):
    """Create billing source for AWS and Azure sources."""
    request_data = request.data
    try:
        add_provider_billing_source(request_data,
                                    request_data.get('billing_source'))
        response = request_data
        status_code = status.HTTP_201_CREATED
    except SourcesStorageError as error:
        response = str(error)
        status_code = status.HTTP_400_BAD_REQUEST
    return Response(response, status=status_code)