Пример #1
0
    def test_execute_given_files_and_directories_enhancement_configuration_should_call_service(
            self):
        """
           Given
                 valid files and subdirectories without recursive tag.
           When
                 CommandParser.parse_args() is called
           Then
                 Enhance service with all files and only files in the first sub diretory should be called.
        """
        # Arrange
        files = [
            '../.pytest_cache/testfile1.png', '../.pytest_cache/testdirectory'
        ]
        mocked_enhance_service = MockedEnhanceService()
        class_under_test = EnhanceCommand(mocked_enhance_service)
        enhance_configuration = EnhancementConfiguration()

        # Act
        pathlib.Path("../.pytest_cache").mkdir(parents=True, exist_ok=True)
        pathlib.Path(files[1]).mkdir(parents=True, exist_ok=True)
        f = open(files[1] + "/sample.jpg", "w+")
        f.write("Hello World")
        f.close()

        class_under_test.execute(files, enhance_configuration)

        # Assert
        self.assertTrue(mocked_enhance_service.called)
        self.assertEqual(2, mocked_enhance_service.called_counter)
Пример #2
0
    def test_execute_given_multiple_files_enhancement_configuration_should_call_service(
            self):
        """
             Given
                   valid files
             When
                   CommandParser.parse_args() is called
             Then
                   Enhance service should be called for each file.
        """
        # Arrange
        files = [
            '../.pytest_cache/testfile1.png', '../.pytest_cache/testfile2.png',
            '../.pytest_cache/testfile3.png'
        ]
        mocked_enhance_service = MockedEnhanceService()
        class_under_test = EnhanceCommand(mocked_enhance_service)
        enhance_configuration = EnhancementConfiguration()

        # Act
        pathlib.Path("../.pytest_cache").mkdir(parents=True, exist_ok=True)
        for i in range(1, 3):
            f = open(files[i], "w+")
            f.write("Hello World")
            f.close()

        class_under_test.execute(files, enhance_configuration)

        # Assert
        self.assertTrue(mocked_enhance_service.called)
        self.assertEqual(3, mocked_enhance_service.called_counter)
Пример #3
0
    def test_execute_given_rotation_value_should_call_service_with(self):
        """
        Given
            a file and rotation as parameter
        When
            EnhanceCommand.execute() is called
        Then
            Enhance service should be called with correct rotation.
        """
        # Arrange
        files = ['../.pytest_cache/testfile5.png']
        mocked_enhance_service = MockedEnhanceService()
        class_under_test = EnhanceCommand(mocked_enhance_service)
        enhance_configuration = EnhancementConfiguration()
        enhance_configuration.rotation = 180
        expected_rotation = 180

        # Act
        pathlib.Path("../.pytest_cache").mkdir(parents=True, exist_ok=True)
        f = open("../.pytest_cache/testfile5_brushed.png", "w+")
        f.write("Hello World")
        f.close()
        f = open("../.pytest_cache/testfile5.png", "w+")
        f.write("Hello World")
        f.close()
        class_under_test.execute(files, enhance_configuration)

        # Assert
        self.assertTrue(mocked_enhance_service.called)
        self.assertEqual(expected_rotation, mocked_enhance_service.rotation)
Пример #4
0
    def test_execute_given_files_and_existing_target_should_call_service(self):
        """
            Given
                 valid file and existing target file
            When
                 CommandParser.parse_args() is called
            Then
                 Enhance service should be called.
        """
        # Arrange
        files = ['../.pytest_cache/testfile5.png']
        mocked_enhance_service = MockedEnhanceService()
        class_under_test = EnhanceCommand(mocked_enhance_service)
        enhance_configuration = EnhancementConfiguration()

        # Act
        pathlib.Path("../.pytest_cache").mkdir(parents=True, exist_ok=True)
        f = open("../.pytest_cache/testfile5_brushed.png", "w+")
        f.write("Hello World")
        f.close()
        f = open("../.pytest_cache/testfile5.png", "w+")
        f.write("Hello World")
        f.close()
        class_under_test.execute(files, enhance_configuration)

        # Assert
        self.assertTrue(mocked_enhance_service.called)
        self.assertEqual(1, mocked_enhance_service.called_counter)
Пример #5
0
def main():
    """
    Entry point of the application which parses the given arguments.
    """
    command_parser = CommandParser(EnhanceCommand(EnhanceService()),
                                   TemplateCommand(), RotationCommand())
    command_parser.parse_args()
Пример #6
0
    def test_execute_given_nonexistent_file_should_raise_exception(self):
        """
        Given
            a nonexisting file as parameter
        When
            EnhanceCommand.execute() is called
        Then
            Enhance service should never be called
        """
        mocked_enhance_service = MockedEnhanceService()
        class_under_test = EnhanceCommand(mocked_enhance_service)
        nonexistent_files = ["i_do_not_exist.png"]
        class_under_test.execute(nonexistent_files)

        self.assertFalse(mocked_enhance_service.called)
        self.assertEqual(0, mocked_enhance_service.called_counter)
Пример #7
0
    def test_execute_given_files_and_subdirectories_configuration_should_call_service(
            self):
        """
            Given
                  valid files and subdirectories with recursive tag.
            When
                  CommandParser.parse_args() is called
            Then
                  Enhance service with all files and not directories should be called.
        """
        # Arrange
        files = [
            '../.pytest_cache/testfile1.png', '../.pytest_cache/testdirectory'
        ]
        mocked_enhance_service = MockedEnhanceService()
        class_under_test = EnhanceCommand(mocked_enhance_service)
        enhance_configuration = EnhancementConfiguration()
        enhance_configuration.recursive = True
        enhance_configuration.foreground_color = "#fore"
        enhance_configuration.background_color = "#back"

        expected_foreground = "#fore"
        expected_background = "#back"

        # Act
        pathlib.Path("../.pytest_cache").mkdir(parents=True, exist_ok=True)
        pathlib.Path(files[1]).mkdir(parents=True, exist_ok=True)
        f = open(files[1] + "/sample.jpg", "w+")
        f.write("Hello World")
        f.close()
        pathlib.Path(files[1] + "/subtestdirectory").mkdir(parents=True,
                                                           exist_ok=True)
        f = open(files[1] + "/subtestdirectory/subsample.jpg", "w+")
        f.write("Hello World")
        f.close()

        class_under_test.execute(files, enhance_configuration)

        # Assert
        self.assertTrue(mocked_enhance_service.called)
        self.assertEqual(3, mocked_enhance_service.called_counter)
        self.assertEqual(
            expected_foreground,
            mocked_enhance_service.called_color_configuration.foreground_color)
        self.assertEqual(
            expected_background,
            mocked_enhance_service.called_color_configuration.background_color)