Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two Matrix connector tests fail on 'main' branch #1994

Open
lucastronova opened this issue May 23, 2023 · 3 comments
Open

Two Matrix connector tests fail on 'main' branch #1994

lucastronova opened this issue May 23, 2023 · 3 comments

Comments

@lucastronova
Copy link

Description

The tests

  • 'tests/test_connector_matrix.py::TestConnectorMatrixAsync::test_respond_image'
  • 'tests/test_connector_matrix.py::TestConnectorMatrixAsync::test_respond_file'

currently fail when running 'tox' on the main branch of opsdroid.

Experienced Functionality

The error rises in this function (defined in opsdroid/connector/matrix/connector.py) for both tests:

async def _file_to_mxc_url(self, file_event):
    """Given a file event return the mxc url."""
    uploaded = False
    mxc_url = None
    file_dict = None
    if file_event.url:
        url = urlparse(file_event.url)
        if url.scheme == "mxc":
            mxc_url = file_event.url

    if not mxc_url:
        encrypt_file = (
            self._allow_encryption
            and file_event.target in self.connection.store.load_encrypted_rooms()
        )
        upload_file = await file_event.get_file_bytes()
        mimetype = await file_event.get_mimetype()

        response = await self.connection.upload(
            lambda x, y: upload_file, content_type=mimetype, encrypt=encrypt_file
        )
        response, file_dict = response

with this line throwing the error:

      response, file_dict = response

E ValueError: not enough values to unpack (expected 2, got 0)

Versions

These errors rise for all versions of python tested by tox.

@penugondaakash2
Copy link

Updated.txt

@penugondaakash2
Copy link

The above code will work without errors

@penugondaakash2
Copy link

async def _file_to_mxc_url(self, file_event):

"""Given a file event, return the mxc URL."""
uploaded = False
mxc_url = None
file_dict = None

if file_event.url:
    url = urlparse(file_event.url)
    if url.scheme == "mxc":
        mxc_url = file_event.url

if not mxc_url:
    encrypt_file = (
        self._allow_encryption
        and file_event.target in self.connection.store.load_encrypted_rooms()
    )
    upload_file = await file_event.get_file_bytes()
    mimetype = await file_event.get_mimetype()

    response = await self.connection.upload(
        lambda x, y: upload_file, content_type=mimetype, encrypt=encrypt_file
    )

    if isinstance(response, tuple) and len(response) >= 2:
        response, file_dict = response
    else:
        response = None
        file_dict = None

# Rest of your code...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants