tangowithcode / tango_with_django_2

Django 2 and Python 3: Tango With Django 2 Book Repository
Apache License 2.0
68 stars 23 forks source link

Chapter 4: Errors in the test module #1

Closed marshwiggle closed 5 years ago

marshwiggle commented 5 years ago

Trying to use the test module to test the results which I've got after completing Chapter 4.

The content of my about.html is the following:

<!DOCTYPE html>
<html>
     <head>
     </head>
     <body>
          <h1> About </h1>
          <img src="{{MEDIA_URL}}resin.jpg" alt="Галоша" />
          <p>
               This tutorial has been put together by Marshwiggle
          </p>
     </body>
</html>

So, when I start the module, I get a buch of errors:

Creating test database for alias 'default'...
System check identified no issues (0 silenced).
...E.EEE.....The module populate_rango does not exist
EThe module populate_rango does not exist
EThe module populate_rango does not exist
E
======================================================================
ERROR: test_about_contains_create_message (rango.tests.Chapter4ViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<MY_WORKING_PATH>/tango/tango_with_django_project/rango/tests.py", line 130, in test_about_contains_create_message
    self.assertIn('This tutorial has been put together by', response.content)
  File "/usr/lib/python3.5/unittest/case.py", line 1076, in assertIn
    if member not in container:
TypeError: a bytes-like object is required, not 'str'

======================================================================
ERROR: test_does_about_contain_img (rango.tests.Chapter4ViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<MY_WORKING_PATH>/tango/tango_with_django_project/rango/tests.py", line 125, in test_does_about_contain_img
    self.assertIn('img',response.content)
  File "/usr/lib/python3.5/unittest/case.py", line 1076, in assertIn
    if member not in container:
TypeError: a bytes-like object is required, not 'str'

======================================================================
ERROR: test_does_index_contain_img (rango.tests.Chapter4ViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<MY_WORKING_PATH>/tango/tango_with_django_project/rango/tests.py", line 114, in test_does_index_contain_img
    self.assertIn('img',response.content)
  File "/usr/lib/python3.5/unittest/case.py", line 1076, in assertIn
    if member not in container:
TypeError: a bytes-like object is required, not 'str'

======================================================================
ERROR: test_index_contains_hello_message (rango.tests.Chapter4ViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<MY_WORKING_PATH>/tango/tango_with_django_project/rango/tests.py", line 109, in test_index_contains_hello_message
    self.assertContains( response.content,'Rango says')
  File "<MY_WORKING_PATH>/tango/rangoenv/lib/python3.5/site-packages/django/test/testcases.py", line 361, in assertContains
    response, text, status_code, msg_prefix, html)
  File "<MY_WORKING_PATH>/tango/rangoenv/lib/python3.5/site-packages/django/test/testcases.py", line 331, in _assert_contains
    response.status_code, status_code,
AttributeError: 'bytes' object has no attribute 'status_code'

======================================================================
ERROR: test_python_cat_added (rango.tests.ModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<MY_WORKING_PATH>/tango/tango_with_django_project/rango/tests.py", line 91, in test_python_cat_added
    cat = self.get_category('Python')
  File "<MY_WORKING_PATH>/tango/tango_with_django_project/rango/tests.py", line 83, in get_category
    from rango.models import Category
ImportError: cannot import name 'Category'

======================================================================
ERROR: test_python_cat_with_likes (rango.tests.ModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<MY_WORKING_PATH>/tango/tango_with_django_project/rango/tests.py", line 99, in test_python_cat_with_likes
    cat = self.get_category('Python')
  File "<MY_WORKING_PATH>/tango/tango_with_django_project/rango/tests.py", line 83, in get_category
    from rango.models import Category
ImportError: cannot import name 'Category'

======================================================================
ERROR: test_python_cat_with_views (rango.tests.ModelTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "<MY_WORKING_PATH>/tango/tango_with_django_project/rango/tests.py", line 95, in test_python_cat_with_views
    cat = self.get_category('Python')
  File "<MY_WORKING_PATH>/tango/tango_with_django_project/rango/tests.py", line 83, in get_category
    from rango.models import Category
ImportError: cannot import name 'Category'

----------------------------------------------------------------------
Ran 16 tests in 0.089s

FAILED (errors=7)
Destroying test database for alias 'default'...

I've tested my app in the browser and it seems to be working, so perhaps, there are some bugs in the tests.

For example, 'test_about_contains_create_message' method of the 'AboutPageTests' object is almost identical to the method with the same name in the Chapter4ViewTests object, but it raises no error, and that's because it has a type hint (i.e. "b" character) before the string in the last line.

maxwelld90 commented 5 years ago

Hi @marshwiggle, I agree -- as we have moved the content of the book onwards to a new version of Django, some of the tests have broken. This is our next job, and for now, we have taken the tests out. We'll be looking to reintroduce them soon, so hopefully everything will be able to pass.

Thanks for your comment. Closing for now.

Cheers David