Re: How can I add the Openid session data to the Django test client Client.post() ?
I looked at how the Django test client class method, Client.login() stored sessions and attempt to copy the important sections into the test so the session data could be stored. When I broke into the test immediately before Client.post() was called and the session looked OK. ipdb> request.session.__dict__ {'_session_cache': {'openid': 'https://www.google.com/accounts/o8/id? id=ItsAFakeOpenID'}, '_session_key': 'decee0b0bdbba7ad7c1a6601bbc60ef1', 'modified': True, 'accessed': True} However, after Client.post() the session doesn't seem to contain the request.session['openid'] any longer. I broke into the register view and checked: ipdb> request.session.__dict__ {'_session_cache': {'pagesize': 10}, '_session_key': None, 'modified': True, 'accessed': True} Why is the session data not persisting? class UserTestCAse(TestCase): def test_register_should_create_UserProfile(self): from django.test.client import Client c = Client() # Create a fake request to store session details. from django.http import HttpRequest request = HttpRequest() from django.contrib.sessions.backends.db import SessionStore request.session = SessionStore() request.session['openid'] = 'https://www.google.com/accounts/ o8/id?id=ItsAFakeOpenID' request.session.save() response = c.post('/account/register/', {u'username': [u'john'], u'email': [u'j...@beatles.com'], u'bnewaccount': [u'Signup']}) self.assertEqual(response.status_code, 200) user = User.objects.get( username ='john') self.assertTrue(user.get_profile()) On Feb 24, 5:12 pm, "br...@instantdirectmarketing.com" <bryan.wheel...@gmail.com> wrote: > I'm trying to test that a UserProfile model is created as a new User > is registered in django_authopenid. > I don't understand how to add the Openidsessiondata to the POST. > > class UserTestCase(TestCase): > def test_register_should_create_UserProfile(self): > from django.test.client import Client > c = Client() > response = c.post('/account/register/', {u'username': > [u'john'], u'email': [u'j...@beatles.com'], u'bnewaccount': > [u'Signup']},) > > self.assertEqual(response.status_code, 302) > > user = User.objects.get( username ='john') > self.assertTrue(user.get_profile()) > > I'm using django_authopenid and I want to make sure a UserProfile is > created after the User is created. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How can I add the Openid session data to the Django test client Client.post() ?
I'm trying to test that a UserProfile model is created as a new User is registered in django_authopenid. I don't understand how to add the Openid session data to the POST. class UserTestCase(TestCase): def test_register_should_create_UserProfile(self): from django.test.client import Client c = Client() response = c.post('/account/register/', {u'username': [u'john'], u'email': [u'j...@beatles.com'], u'bnewaccount': [u'Signup']},) self.assertEqual(response.status_code, 302) user = User.objects.get( username ='john') self.assertTrue(user.get_profile()) I'm using django_authopenid and I want to make sure a UserProfile is created after the User is created. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
How can _meta.local_fields not match the table schema in the database?
I'm completely confused about why _meta.local_fields returns more fields than the database table contains. The User model inherits from contrib.auth.models.User. $ mysql -u user -p database Enter password: Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1240032 Server version: 5.0.77 Source distribution mysql> describe auth_user; ++--+--+-+- ++ | Field | Type | Null | Key | Default | Extra | ++--+--+-+- ++ | id | int(11) | NO | PRI | NULL| auto_increment | | username | varchar(30) | NO | UNI | NULL || | first_name | varchar(30) | NO | | NULL || | last_name | varchar(30) | NO | | NULL || | email | varchar(75) | NO | | NULL || | password | varchar(128) | NO | | NULL || | is_staff | tinyint(1) | NO | | NULL || | is_active | tinyint(1) | NO | | NULL || | is_superuser | tinyint(1) | NO | | NULL || | last_login | datetime | NO | | NULL || | date_joined| datetime | NO | | NULL || | email_isvalid | tinyint(1) | NO | | NULL || | email_key | varchar(16) | YES | | NULL || | reputation | int(10) unsigned | NO | | NULL || | gravatar | varchar(32) | NO | | NULL || | gold | smallint(6) | NO | | NULL || | silver | smallint(6) | NO | | NULL || | bronze | smallint(6) | NO | | NULL || | questions_per_page | smallint(6) | NO | | NULL || | last_seen | datetime | NO | | NULL || | real_name | varchar(100) | NO | | NULL || | website| varchar(200) | NO | | NULL || | location | varchar(100) | NO | | NULL || | date_of_birth | date | YES | | NULL || | about | longtext | NO | | NULL || ++--+--+-+- ++ 25 rows in set (0.00 sec) >From the Django error page, this is the SQL statement that generates the error: Exception Value: (1110, "Column 'about' specified twice") 'INSERT INTO `auth_user` (`username`, `first_name`, `last_name`, `email`, `password`, `is_staff`, `is_active`, `is_superuser`, `last_login`, `date_joined`, `email_isvalid`, `email_key`, `reputation`, `gravatar`, `gold`, `silver`, `bronze`, `questions_per_page`, `last_seen`, `real_name`, `website`, `location`, `date_of_birth`, `about`, `email_isvalid`, `email_key`, `reputation`, `gravatar`, `gold`, `silver`, `bronze`, `questions_per_page`, `last_seen`, `real_name`, `website`, `location`, `date_of_birth`, `about`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)' This SQL statement seems to be generated by iterating over User._meta.local_fields. I don't understand why _meta.local_fields doesn't match the actual User table schema. $ python2.5 manage.py shell Python 2.5.4 (r254:67916, Aug 5 2009, 12:42:40) [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from forum.models import User >>> len(User._meta.local_fields) 39 >>> import pprint >>> pprint.pprint(User._meta.local_fields) [, , , , , , , , , , , # here is where customizations to User begin. , , , , , , , , , , , , , , # this seems to be a duplicate of the fields added to User , , , , , , , , , , , , , ] >>> This is how this project customized User: from django.contrib.auth.models import User The additional fields to the model are added thusly: User.add_to_class('email_isvalid', models.BooleanField(default=False))
Re: Amazon Product Advertising API
Luke, I was curious how this was going. I did find this: http://jjinux.blogspot.com/2009/06/python-amazon-product-advertising-api.html import time import urllib from boto.connection import AWSQueryConnection AWS_ACCESS_KEY_ID = '...' AWS_ASSOCIATE_TAG = '...' AWS_SECRET_ACCESS_KEY = '...' search_index = 'All' keywords = 'pink' aws_conn = AWSQueryConnection( aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY, is_secure=False, host='ecs.amazonaws.com') aws_conn.SignatureVersion = '2' params = dict( Service='AWSECommerceService', Version='2008-08-19', SignatureVersion=aws_conn.SignatureVersion, AWSAccessKeyId=AWS_ACCESS_KEY_ID, AssociateTag=AWS_ASSOCIATE_TAG, Operation='ItemSearch', SearchIndex=search_index, Keywords=keywords, ResponseGroup='ItemAttributes,Images', Order='salesrank', Timestamp=time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime())) verb = 'GET' path = '/onca/xml' qs, signature = aws_conn.get_signature(params, verb, path) qs = path + '?' + qs + '=' + urllib.quote(signature) print "verb:", verb, "qs:", qs response = aws_conn._mexe(verb, qs, None, headers={}) print response.read() On Jul 17, 8:34 am, Luke Seelenbinderwrote: > I'm working on a django project right now that uses the Amazon Product > Advertising API. I was using pyaws, but it is quite outdated and won't > be useful for the changes coming in the next month. > > My first question is whether you know of any other python library for > it. > Second question, is there anybody willing to help me develop a new > python abstraction for the api. > > I'm going to get started today with a new python api, if there is > anybody willing to help, drop me an email (lukeqsee at gmail), or just > reply to this message. > > Thanks, > Luke --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---