<commit_before>from mock import patch, Mock
from django.test import TestCase
from django.conf import settings

from .utils import humanize_filesize, S3Mixin


class HumanizeFilesizeTests(TestCase):
    def test_returns_0_for_input_0(self):
        self.assertEqual(
            humanize_filesize(0),
            '0 bytes'
        )

    def test_returns_singular_byte_for_input_1(self):
        self.assertEqual(
            humanize_filesize(1),
            '1 byte'
        )

    def test_returns_number_of_bytes_if_in_byte_range(self):
        self.assertEqual(
            humanize_filesize(500),
            '500 bytes'
        )

    def test_returns_number_of_kilobytes_if_in_kilobyte_range(self):
        self.assertEqual(
            humanize_filesize(512000),
            '500.0KB'
        )

    def test_returns_number_of_megabytes_if_in_megabyte_range(self):
        self.assertEqual(
            humanize_filesize(524288000),
            '500.0MB'
        )

    def test_returns_number_of_gigabytes_if_in_gigabyte_range(self):
        self.assertEqual(
            humanize_filesize(536870912000),
            '500.0GB'
        )

    def test_returns_number_of_terabytes_if_in_terabyte_range(self):
        self.assertEqual(
            humanize_filesize(549755813888000),
            '500.0TB'
        )


class S3MixinTests(TestCase):
    def setUp(self):
        self.s3_mixin = S3Mixin()

    def test_get_bucket_uses_cached_bucket_if_exists(self):
        self.s3_mixin.bucket = 'test test test'
        result = self.s3_mixin.get_bucket()
        self.assertEqual(result, 'test test test')

    @patch('remote_fixtures.utils.S3Connection')
    def test_get_bucket_initialises_s3connection_with_key_and_secret(self, mock_s3connection):
        self.s3_mixin.get_bucket()

        mock_s3connection.assert_called_once_with(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)

    @patch('remote_fixtures.utils.S3Connection')
    def test_bucket_returned_from_get_bucket_and_cached(self, mock_s3connection):
        mock_s3connection.return_value = Mock(**{
            'get_bucket.return_value': 'this is my mock bucket'
        })
        bucket = self.s3_mixin.get_bucket()
        self.assertEqual(self.s3_mixin.bucket, 'this is my mock bucket')
        self.assertEqual(bucket, 'this is my mock bucket')
<commit_msg>import management commands to have coverage correctly reported<commit_after>from mock import patch, Mock
from django.test import TestCase
from django.conf import settings

from .utils import humanize_filesize, S3Mixin
from .management.commands.pull_fixtures import Command as PullFixturesCommand
from .management.commands.push_fixtures import Command as PushFixturesCommand
from .management.commands.list_fixtures import Command as ListFixturesCommand


class HumanizeFilesizeTests(TestCase):
    def test_returns_0_for_input_0(self):
        self.assertEqual(
            humanize_filesize(0),
            '0 bytes'
        )

    def test_returns_singular_byte_for_input_1(self):
        self.assertEqual(
            humanize_filesize(1),
            '1 byte'
        )

    def test_returns_number_of_bytes_if_in_byte_range(self):
        self.assertEqual(
            humanize_filesize(500),
            '500 bytes'
        )

    def test_returns_number_of_kilobytes_if_in_kilobyte_range(self):
        self.assertEqual(
            humanize_filesize(512000),
            '500.0KB'
        )

    def test_returns_number_of_megabytes_if_in_megabyte_range(self):
        self.assertEqual(
            humanize_filesize(524288000),
            '500.0MB'
        )

    def test_returns_number_of_gigabytes_if_in_gigabyte_range(self):
        self.assertEqual(
            humanize_filesize(536870912000),
            '500.0GB'
        )

    def test_returns_number_of_terabytes_if_in_terabyte_range(self):
        self.assertEqual(
            humanize_filesize(549755813888000),
            '500.0TB'
        )


class S3MixinTests(TestCase):
    def setUp(self):
        self.s3_mixin = S3Mixin()

    def test_get_bucket_uses_cached_bucket_if_exists(self):
        self.s3_mixin.bucket = 'test test test'
        result = self.s3_mixin.get_bucket()
        self.assertEqual(result, 'test test test')

    @patch('remote_fixtures.utils.S3Connection')
    def test_get_bucket_initialises_s3connection_with_key_and_secret(self, mock_s3connection):
        self.s3_mixin.get_bucket()

        mock_s3connection.assert_called_once_with(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)

    @patch('remote_fixtures.utils.S3Connection')
    def test_bucket_returned_from_get_bucket_and_cached(self, mock_s3connection):
        mock_s3connection.return_value = Mock(**{
            'get_bucket.return_value': 'this is my mock bucket'
        })
        bucket = self.s3_mixin.get_bucket()
        self.assertEqual(self.s3_mixin.bucket, 'this is my mock bucket')
        self.assertEqual(bucket, 'this is my mock bucket')

{'fraction_non_alphanumeric': 0.07649066452519575, 'fraction_numerical': 0.03493274442882955, 'mean_word_length': 2.9951884522854852, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1040566', 'n_tokens_mistral': 1691, 'n_tokens_neox': 1577, 'n_words': 243}