Test fail: test_archive, test_delete and test_undelete

Issue #47 closed
kerryz created an issue

When running the tests I get the 3 failures mentioned in the title. Archive, delete and undelete actions work when interacting through the browser though.

Error log:

$ python manage.py test 
Creating test database for alias 'default'...
.......................................................................F..F...............F.................
======================================================================
FAIL: test_archive (postman.tests.ViewTest)
Test archive action on messages.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 837, in test_archive
    self.check_update('postman_archive', 'Messages or conversations successfully archived.', 'archived', pk, True)
  File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 796, in check_update
    self.check_contrib_messages(response, 'Select at least one object.')
  File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 340, in check_contrib_messages
    self.assertEqual(len(messages), 1)
AssertionError: 5 != 1

======================================================================
FAIL: test_delete (postman.tests.ViewTest)
Test delete action on messages.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 853, in test_delete
    self.check_update('postman_delete', 'Messages or conversations successfully deleted.', 'deleted_at', pk, True)
  File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 796, in check_update
    self.check_contrib_messages(response, 'Select at least one object.')
  File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 340, in check_contrib_messages
    self.assertEqual(len(messages), 1)
AssertionError: 5 != 1

======================================================================
FAIL: test_undelete (postman.tests.ViewTest)
Test undelete action on messages.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 869, in test_undelete
    self.check_update('postman_undelete', 'Messages or conversations successfully recovered.', 'deleted_at', pk)
  File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 796, in check_update
    self.check_contrib_messages(response, 'Select at least one object.')
  File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 340, in check_contrib_messages
    self.assertEqual(len(messages), 1)
AssertionError: 5 != 1

----------------------------------------------------------------------
Ran 108 tests in 20.221s

FAILED (failures=3)
Destroying test database for alias 'default'...

Comments (5)

  1. Patrick Samson repo owner
    • changed status to open

    Can't reproduce (sqlite db for tests)

    #!
    
    >manage.py test postman
    Creating test database for alias 'default'...
    Ran 89 tests in 26.347s
    OK
    Destroying test database for alias 'default'...
    
    • Python 2.7.7
    • Django 1.6.5

    Investigate these points:

    • your line numbers are +1 compared to the tests.py in repo. Not important but..

    • restrict the test to 'postman' only

    • in tests.py add "for message in messages: print message" before line 340, to known what are these extra messages

  2. kerryz reporter
    $ python manage.py test postman
    Creating test database for alias 'default'...
    ....................................................Messages or conversations successfully archived.
    Messages or conversations successfully archived.
    Messages or conversations successfully archived.
    Messages or conversations successfully archived.
    Messages or conversations successfully archived.
    Select at least one object.
    F..Messages or conversations successfully deleted.
    Messages or conversations successfully deleted.
    Messages or conversations successfully deleted.
    Messages or conversations successfully deleted.
    Messages or conversations successfully deleted.
    Select at least one object.
    F...............Messages or conversations successfully recovered.
    Messages or conversations successfully recovered.
    Messages or conversations successfully recovered.
    Messages or conversations successfully recovered.
    Messages or conversations successfully recovered.
    Select at least one object.
    F..........Message successfully sent.
    .Message successfully sent.
    ..Message rejected for at least one recipient.
    ....
    ======================================================================
    FAIL: test_archive (postman.tests.ViewTest)
    Test archive action on messages.
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 837, in test_archive
        self.check_update('postman_archive', 'Messages or conversations successfully archived.', 'archived', pk, True)
      File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 796, in check_update
        self.check_contrib_messages(response, 'Select at least one object.')
      File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 340, in check_contrib_messages
        self.assertEqual(len(messages), 1)
    AssertionError: 5 != 1
    
    ======================================================================
    FAIL: test_delete (postman.tests.ViewTest)
    Test delete action on messages.
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 853, in test_delete
        self.check_update('postman_delete', 'Messages or conversations successfully deleted.', 'deleted_at', pk, True)
      File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 796, in check_update
        self.check_contrib_messages(response, 'Select at least one object.')
      File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 340, in check_contrib_messages
        self.assertEqual(len(messages), 1)
    AssertionError: 5 != 1
    
    ======================================================================
    FAIL: test_undelete (postman.tests.ViewTest)
    Test undelete action on messages.
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 869, in test_undelete
        self.check_update('postman_undelete', 'Messages or conversations successfully recovered.', 'deleted_at', pk)
      File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 796, in check_update
        self.check_contrib_messages(response, 'Select at least one object.')
      File "/home/kerryz/Programming/CMovie/cmovie-django/postman/tests.py", line 340, in check_contrib_messages
        self.assertEqual(len(messages), 1)
    AssertionError: 5 != 1
    
    ----------------------------------------------------------------------
    Ran 89 tests in 21.811s
    
    FAILED (failures=3)
    Destroying test database for alias 'default'...
    

    More info about my project: I'm only building an API with Django REST Framework and therefore only included a base.html and registration/login.html for test purposes, they're very minimal:

    base.html

    <!DOCTYPE html>
    <html>
    <head lang="en">
        <meta charset="UTF-8">
        <title>{% block title %}{% endblock %}</title>
        {% block extrahead %} {% endblock %}
    </head>
    <body>
        {% block postman_menu %}{% endblock %}
        {% block content %}{% endblock %}
    </body>
    </html>
    

    registration/login.html

    {% block title %}Login{% endblock %}
    {% block content %}
    
    <form method="post" action="/api-auth/">{% csrf_token %}
    
    <input type="text" name="username" value="" placeholder="Username or Email"><br />
    <input type="password" name="password" value="" placeholder="Password"><br />
    <input type="submit" value="login" />
    </form>
    
    {% endblock %}
    
  3. Patrick Samson repo owner

    Messages are normally consumed through their displaying.

    So add this section in your base.html:

    {% if messages %}
    <ul class="messages">{% for message in messages %}
     <li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>{% endfor %}
    </ul>
    {% endif %}
    
  4. Patrick Samson repo owner

    Just a personal choice, I reserve the 'resolved' status to issues that generate a change in the app.

  5. Log in to comment