Exemplo n.º 1
0
    def test_check_size_fail_nosize(self, fake_session):
        """Test _check_size fails if there report has no size."""
        fake_client = Mock()
        fake_client.get_object.return_value = {}

        downloader = AWSReportDownloader(self.fake_customer_name, self.credentials, self.data_source)
        downloader.s3_client = fake_client

        fakekey = self.fake.file_path(depth=random.randint(1, 5), extension=random.choice(["json", "csv.gz"]))
        with self.assertRaises(AWSReportDownloaderError):
            downloader._check_size(fakekey, check_inflate=False)
Exemplo n.º 2
0
    def test_check_size_fail_unknown_error(self, fake_session):
        """Test _check_size fails if there report has no size."""
        fake_response = {"Error": {"Code": "Unknown"}}
        fake_client = Mock()
        fake_client.get_object.side_effect = ClientError(fake_response, "masu-test")

        downloader = AWSReportDownloader(self.fake_customer_name, self.credentials, self.data_source)
        downloader.s3_client = fake_client

        fakekey = self.fake.file_path(depth=random.randint(1, 5), extension=random.choice(["json", "csv.gz"]))
        with self.assertRaises(AWSReportDownloaderError):
            downloader._check_size(fakekey, check_inflate=False)
Exemplo n.º 3
0
    def test_check_size_fail_nosize(self, fake_session):
        """Test _check_size fails if there report has no size."""
        fake_client = Mock()
        fake_client.get_object.return_value = {}

        auth_credential = fake_arn(service="iam", generate_account_id=True)
        downloader = AWSReportDownloader(
            self.mock_task, self.fake_customer_name, auth_credential, self.fake_bucket_name
        )
        downloader.s3_client = fake_client

        fakekey = self.fake.file_path(depth=random.randint(1, 5), extension=random.choice(["json", "csv.gz"]))
        with self.assertRaises(AWSReportDownloaderError):
            downloader._check_size(fakekey, check_inflate=False)
Exemplo n.º 4
0
    def test_check_size_inflate_fail(self, fake_session, fake_shutil):
        """Test _check_size fails when inflation fails."""
        fake_client = Mock()
        fake_client.get_object.return_value = {"ContentLength": 123456, "Body": io.BytesIO(b"\xd2\x02\x96I")}
        fake_shutil.disk_usage.return_value = (10, 10, 1234567)

        downloader = AWSReportDownloader(self.fake_customer_name, self.credentials, self.data_source)
        downloader.s3_client = fake_client

        fakekey = self.fake.file_path(depth=random.randint(1, 5), extension="csv.gz")
        result = downloader._check_size(fakekey, check_inflate=True)
        self.assertFalse(result)
Exemplo n.º 5
0
    def test_check_size_fail_nospace(self, fake_session, fake_shutil):
        """Test _check_size fails if there is no more space."""
        fake_client = Mock()
        fake_client.get_object.return_value = {"ContentLength": 123456, "Body": Mock()}
        fake_shutil.disk_usage.return_value = (10, 10, 10)

        downloader = AWSReportDownloader(self.fake_customer_name, self.credentials, self.data_source)
        downloader.s3_client = fake_client

        fakekey = self.fake.file_path(depth=random.randint(1, 5), extension=random.choice(["json", "csv.gz"]))
        result = downloader._check_size(fakekey, check_inflate=False)
        self.assertFalse(result)
Exemplo n.º 6
0
    def test_check_size_inflate_success(self, fake_session, fake_shutil):
        """Test _check_size inflation succeeds."""
        fake_client = Mock()
        fake_client.get_object.return_value = {"ContentLength": 123456, "Body": io.BytesIO(b"\xd2\x02\x96I")}
        fake_shutil.disk_usage.return_value = (10, 10, 4096 * 1024 * 1024)

        auth_credential = fake_arn(service="iam", generate_account_id=True)
        downloader = AWSReportDownloader(
            self.mock_task, self.fake_customer_name, auth_credential, self.fake_bucket_name
        )
        downloader.s3_client = fake_client

        fakekey = self.fake.file_path(depth=random.randint(1, 5), extension="csv.gz")
        result = downloader._check_size(fakekey, check_inflate=True)
        self.assertTrue(result)
Exemplo n.º 7
0
    def test_check_size_fail_nospace(self, fake_session, fake_shutil):
        fake_client = Mock()
        fake_client.get_object.return_value = {'ContentLength': 123456, 'Body': Mock()}
        fake_shutil.disk_usage.return_value = (10, 10, 10)

        auth_credential = fake_arn(service='iam', generate_account_id=True)
        downloader = AWSReportDownloader(
            self.mock_task, self.fake_customer_name, auth_credential, self.fake_bucket_name
        )
        downloader.s3_client = fake_client

        fakekey = self.fake.file_path(
            depth=random.randint(1, 5), extension=random.choice(['json', 'csv.gz'])
        )
        result = downloader._check_size(fakekey, check_inflate=False)
        self.assertFalse(result)
Exemplo n.º 8
0
    def test_check_size_inflate_fail(self, fake_session, fake_shutil):
        fake_client = Mock()
        fake_client.get_object.return_value = {
            'ContentLength': 123456,
            'Body': io.BytesIO(b'\xd2\x02\x96I'),
        }
        fake_shutil.disk_usage.return_value = (10, 10, 1234567)

        auth_credential = fake_arn(service='iam', generate_account_id=True)
        downloader = AWSReportDownloader(self.fake_customer_name,
                                         auth_credential,
                                         self.fake_bucket_name)
        downloader.s3_client = fake_client

        fakekey = self.fake.file_path(depth=random.randint(1, 5),
                                      extension='csv.gz')
        result = downloader._check_size(fakekey, check_inflate=True)
        self.assertFalse(result)