0

I would like to write a test case like:

    # Create fake request with missing header that we are testing for
    request = HttpRequest() 
    request.META = {}
    response = MyApp.views.start(request)
    self.assertEqual(400, response.status_code, "Unexpected response code")

When I run the above code I see the following error message:

AttributeError: 'module' object has no attribute 'views'

I am a Python newbie and am clearly doing this wrong. Can anyone point how what the error is?

Thanks. -Raj

Raj
  • 2,852
  • 4
  • 29
  • 48
  • 1
    As an aside, if you need to extend your fake request further, you might find [RequestFactory](https://docs.djangoproject.com/en/1.6/topics/testing/advanced/#module-django.test.client) useful. – Alasdair Jan 28 '14 at 22:19

1 Answers1

2

You haven't shown your imports, or included the full traceback, which makes it harder to work out what's going wrong.

Changing

import myapp

to

import myapp.views

might work.

Alasdair
  • 298,606
  • 55
  • 578
  • 516