Exemplo n.º 1
0
    def test_create_file_from_file_object(self, dummy_file):
        """Create a file from just a path."""
        from sasctl.services.files import create_file

        with open(dummy_file) as f:
            # Filename must be provided
            with pytest.raises(ValueError):
                file = create_file(f)

            file = create_file(f, filename=self.filename)

        assert isinstance(file, RestObj)
        assert self.filename == file.name
Exemplo n.º 2
0
    def test_create_file_with_name(self, dummy_file):
        """Create a file with an explicitly set filename."""
        from sasctl.services.files import create_file

        file = create_file(dummy_file, filename=self.filename)

        assert isinstance(file, RestObj)
Exemplo n.º 3
0
    def test_create_file_from_file_object(self, dummy_file):
        """Create a file from just a path."""

        with open(dummy_file) as f:
            # Filename must be provided
            with pytest.raises(ValueError):
                file = files.create_file(f)

            # Requests uses os.urandom(16) to generate boundaries for multi-part
            # form uploads.  Mock the output to ensure a consistent value so
            # that body request/responses always match.
            with mock.patch('os.urandom',
                            return_value='abcdefghijklmnop'.encode('utf-8')):
                file = files.create_file(f, filename=self.filename)

        assert isinstance(file, RestObj)
        assert self.filename == file.name
Exemplo n.º 4
0
    def test_create_file_without_name(self, dummy_file):
        """Create a file from just a path."""
        from sasctl.services.files import create_file

        file = create_file(dummy_file)

        assert isinstance(file, RestObj)
        assert FILENAME == file.name
Exemplo n.º 5
0
    def test_create_file_with_name(self, dummy_file):
        # Requests uses os.urandom(16) to generate boundaries for multi-part
        # form uploads.  Mock the output to ensure a consistent value so
        # that body request/responses always match.
        with mock.patch('os.urandom',
                        return_value='abcdefghijklmnop'.encode('utf-8')):
            """Create a file with an explicitly set filename."""
            file = files.create_file(dummy_file, filename=self.filename)

        assert isinstance(file, RestObj)
Exemplo n.º 6
0
    def test_create_file_without_name(self, dummy_file):
        """Create a file from just a path."""
        # Requests uses os.urandom(16) to generate boundaries for multi-part
        # form uploads.  Mock the output to ensure a consistent value so
        # that body request/responses always match.
        with mock.patch('os.urandom',
                        return_value='abcdefghijklmnop'.encode('utf-8')):
            file = files.create_file(dummy_file)

        assert isinstance(file, RestObj)
        assert FILENAME == file.name