Beginner's guide part 5 errors

(Christi W) #1

Hi, I am following the tutorial and everything was working great until I added the login_required decorator and added the code to the login.html page. I also entered the code for the tests and this is my results. (I condensed the errors/failures so it doesn’t have all the file tracebacks)

From testing in the past, I know that if you fix the last error/failure, the rest of the test seem to run and pass. I am just at a loss. I went to projectdjango and looked up the decorator and there wasn’t a change from the version you use in the tutorial and the version I am using v2.2.

code:
in boards/views.py
@login_required
def new_topic(request,id):

and in templates/login.html:

the code in the tests is the same as what is in the tutorial under:

boards/test/test_view_new_topic.py
class LoginRequiredNewTopicTests(TestCase):

Any help will be appreciated!

ERROR: test_redirection (boards.tests.test_view_new_topic.LoginRequiredNewTopicTest)

Traceback (most recent call last):

django.urls.exceptions.NoReverseMatch:
Reverse for ‘new_topic’ with no arguments not found.
1 pattern(s) tried: [‘boards/(?P[0-9]+)/new/$’]

=====================================
ERROR: test_contains_form (boards.tests.test_view_new_topic.NewTopicsTest)

Traceback (most recent call last):

form = response.context.get(“form”)
AttributeError: ‘NoneType’ object has no attribute ‘get’

=====================================
FAIL: test_csfr (boards.tests.test_view_new_topic.NewTopicsTest)

Traceback (most recent call last):

self.assertContains(response, “csrfmiddlewaretoken”)
AssertionError: 302 != 200 : Couldn’t retrieve content: Response code was 302 (expe
cted 200)

=====================================
FAIL: test_new_topic_invalid_post_data (boards.tests.test_view_new_topic.NewTopicsTest)

Traceback (most recent call last):

self.assertEqual(response.status_code, 200)
AssertionError: 302 != 200

=====================================
FAIL: test_new_topic_invalid_post_data_empty_fields (boards.tests.test_view_new_topic.NewTopicsTest)

Traceback (most recent call last):

self.assertEqual(response.status_code, 200)
AssertionError: 302 != 200

=====================================
FAIL: test_new_topic_valid_post_data (boards.tests.test_view_new_topic.NewTopicsTest)

Traceback (most recent call last):

self.assertTrue(Topic.objects.exists())
AssertionError: False is not true

=====================================
FAIL: test_new_topic_view_contains_link_back_to_board_topics_view (boards.tests.test_view_new_topic.NewTopicsTest)

Traceback (most recent call last):

self.assertContains(response, ‘href="{0}"’.format(board_topics_url))
AssertionError: 302 != 200 : Couldn’t retrieve content: Response code was 302 (expe
cted 200)

=====================================
FAIL: test_new_topic_view_not_found_status_code (boards.tests.test_view_new_topic.NewTopicsTest)

Traceback (most recent call last):

self.assertEqual(response.status_code, 404)
AssertionError: 302 != 404

=====================================
FAIL: test_new_topic_view_success_status_code (boards.tests.test_view_new_topic.NewTopicsTest)

Traceback (most recent call last):

self.assertEqual(response.status_code, 200)
AssertionError: 302 != 200


Ran 62 tests in 11.503s

FAILED (failures=7, errors=2)
Destroying test database for alias ‘default’…

0 Likes