Re: Empty context within template tag render() method after using django.test.client.Client.login() method

2013-09-23 Thread Jonathan Baker
Below are some snippets involved in generating the error. The
'test_get_unauthenticated' works as expected, but 'test_get_ok' fails while
rendering the template response and calling the menu tag of django-menu
(full module:
https://github.com/rossp/django-menu/blob/master/menu/templatetags/menubuilder.py
).

*integration_tests.py*
class IntegrationTestCase(TestCase):
def setUp(self):
self.client = Client()
self.test_domain = "http://testserver;

class AccountDetail(IntegrationTestCase):
def test_get_unauthenticated(self):
"""302"""
destination = reverse("account_detail")
response = self.client.get(destination)
self.assertRedirects(response, reverse("login") + "?next=" +
destination)

def test_get_ok(self):
"""200"""
user = UserFactory.create()
self.client.login(username=user.username, password="testPass")
response = self.client.get(reverse("account_detail"))
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, "accounts/account_detail.html")

*menubuilder.py*
class MenuObject(template.Node):
def __init__(self, menu_name):
self.menu_name = menu_name

def render(self, context):
current_path = context['request'].path
user = context['request'].user
context['menuitems'] = get_items(self.menu_name, current_path, user)
return ''


On Sun, Sep 22, 2013 at 5:36 PM, jondbaker wrote:

> Within my integration tests, it appears that after using the login()
> method of django.test.client.Client the context dict consists only of:
>
> [{'False': False, 'None': None, 'True': True}, {}, {}].
>
> If I remove the use of login(), then the request dict consists of:
>
> [{'False': False, 'None': None, 'True': True}, {'object':  te...@test.com>, 'user': , u'view':
> }, {u'csrf_token':
> }, {'perms':
> ,
> 'user': },
> {}, {u'MEDIA_URL': '/media/'}, {'messages':
>  0x1393c10>}, {u'request':  path:/accounts/,
> GET:,
> POST:,
> COOKIES:{'sessionid': 'q27przqeidsnfykuufu7m6lo7nw606qw'},
> META:{u'CONTENT_TYPE': 'text/html; charset=utf-8',
>  u'CSRF_COOKIE': u'9mWW7nGMJQAgbs3KBB3oEPofbLBCkLW2',
>  u'HTTP_COOKIE': u' sessionid=q27przqeidsnfykuufu7m6lo7nw606qw;
> Domain=None; expires=None; Max-Age=None; Path=/; secure',
>  u'PATH_INFO': u'/accounts/',
>  u'QUERY_STRING': '',
>  u'REMOTE_ADDR': '127.0.0.1',
>  u'REQUEST_METHOD': 'GET',
>  u'SCRIPT_NAME': u'',
>  u'SERVER_NAME': 'testserver',
>  u'SERVER_PORT': '80',
>  u'SERVER_PROTOCOL': 'HTTP/1.1',
>  u'wsgi.errors': <_io.BytesIO object at 0x2358050>,
>  u'wsgi.input': ,
>  u'wsgi.multiprocess': True,
>  u'wsgi.multithread': False,
>  u'wsgi.run_once': False,
>  u'wsgi.url_scheme': 'http',
>  u'wsgi.version': (1, 0)}>}, {u'STATIC_URL': '/static/'}, {}]
>
> I noticed the problem when a template tag was trying to access
> context["request"].path and a KeyError was raised after using login. Both
> outputs above are the result of printing the context var from within the
> render() method of a template tag. Any help would be greatly appreciated,
> as I'm a bit stumped.
>
> Thanks,
> Jonathan
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>



-- 
Jonathan D. Baker
Developer
http://jonathandbaker.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Empty context within template tag render() method after using django.test.client.Client.login() method

2013-09-22 Thread jondbaker
Within my integration tests, it appears that after using the login() method 
of django.test.client.Client the context dict consists only of: 

[{'False': False, 'None': None, 'True': True}, {}, {}].

If I remove the use of login(), then the request dict consists of:

[{'False': False, 'None': None, 'True': True}, {'object': , 'user': , u'view': 
}, {u'csrf_token': 
}, {'perms': 
, 
'user': }, 
{}, {u'MEDIA_URL': '/media/'}, {'messages': 
}, {u'request': ,
POST:,
COOKIES:{'sessionid': 'q27przqeidsnfykuufu7m6lo7nw606qw'},
META:{u'CONTENT_TYPE': 'text/html; charset=utf-8',
 u'CSRF_COOKIE': u'9mWW7nGMJQAgbs3KBB3oEPofbLBCkLW2',
 u'HTTP_COOKIE': u' sessionid=q27przqeidsnfykuufu7m6lo7nw606qw; 
Domain=None; expires=None; Max-Age=None; Path=/; secure',
 u'PATH_INFO': u'/accounts/',
 u'QUERY_STRING': '',
 u'REMOTE_ADDR': '127.0.0.1',
 u'REQUEST_METHOD': 'GET',
 u'SCRIPT_NAME': u'',
 u'SERVER_NAME': 'testserver',
 u'SERVER_PORT': '80',
 u'SERVER_PROTOCOL': 'HTTP/1.1',
 u'wsgi.errors': <_io.BytesIO object at 0x2358050>,
 u'wsgi.input': ,
 u'wsgi.multiprocess': True,
 u'wsgi.multithread': False,
 u'wsgi.run_once': False,
 u'wsgi.url_scheme': 'http',
 u'wsgi.version': (1, 0)}>}, {u'STATIC_URL': '/static/'}, {}]

I noticed the problem when a template tag was trying to access 
context["request"].path and a KeyError was raised after using login. Both 
outputs above are the result of printing the context var from within the 
render() method of a template tag. Any help would be greatly appreciated, 
as I'm a bit stumped.

Thanks,
Jonathan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.