jeudi 22 février 2018

Django test error arguments 0 given

I'm having trouble running this function:

def test_custom_mail_server_connection(host, port, user, password, use_tls, recipient):
    '''
    Test connection of mailing server with given user params
    returns None if mail is sent successfully, a string containg the error otherwise
    '''
    result = None
    message_list = []

    tenant = get_tenant_by_schema_name(connection.schema_name)

    # create new mail_connection
    mail_connection = mail.get_connection()
    mail_connection.host = host
    mail_connection.port = port
    mail_connection.username = user
    mail_connection.password = password
    mail_connection.use_tls = use_tls

    from_email = '%s <%s>' % (tenant.name, mail_connection.username)
    subject = _(u'%(name)s: SMARTFENSE - Prueba de servidor de correo propio') % {'name': tenant.name}

    mail_content = SimpleTemplateResponse("emails/email_server_test.html", {
        'host': host,
        'port': port,
        'user': user,
        'use_tls': use_tls,
    }, content_type="text/html", charset="utf-8").render().content

    msg = mail.EmailMessage(
        subject,
        mail_content,
        from_email,
        [recipient]
    )

    msg.content_subtype = 'html'
    message_list.append(msg)

    try:
        mail_connection.open()
        mail_connection.send_messages(message_list)
    except Exception as e:
        result = "%s" % e
    finally:
        mail_connection.close()

    set_mail_connection_config(mail_connection, 'default')

    return result

That basically checks if a given mail host is right in order to use it.

I wrote this test:

def test_test_custom_mail_server_connection(self):
        result = test_custom_mail_server_connection('smtp.gmail.com', 587, 'xxxxx@gmail.com',
                                                    'xxxxxxx', True, [])
        self.assertEqual(result, None)

And I'm getting the next error:

ERROR: Test connection of mailing server with given user params
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Volumes/Datos/Diamo/Smartfense/env/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/Volumes/Datos/Diamo/Smartfense/env/lib/python2.7/site-packages/nose/util.py", line 620, in newfunc
    return func(*arg, **kw)
TypeError: test_custom_mail_server_connection() takes exactly 6 arguments (0 given)

I tried changing the amounts of arguments and then I got the same error PLUS another one, like this:

======================================================================
ERROR: test_test_custom_mail_server_connection (lmsplatform.tests.test_services.LmsPlatformServicesTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Volumes/Datos/Diamo/Smartfense/smartfense/lmsplatform/tests/test_services.py", line 120, in test_test_custom_mail_server_connection
    '38809G895723d', True,)
TypeError: test_custom_mail_server_connection() takes exactly 6 arguments (5 given)

======================================================================
ERROR: Test connection of mailing server with given user params
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Volumes/Datos/Diamo/Smartfense/env/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/Volumes/Datos/Diamo/Smartfense/env/lib/python2.7/site-packages/nose/util.py", line 620, in newfunc
    return func(*arg, **kw)
TypeError: test_custom_mail_server_connection() takes exactly 6 arguments (0 given)

I found a couple of guys having through the same problem, but no solutions AT ALL.

Aucun commentaire:

Enregistrer un commentaire