Django tests failing on invalid keyword argument
Posted
by
Darwin Tech
on Stack Overflow
See other posts from Stack Overflow
or by Darwin Tech
Published on 2012-10-31T22:55:40Z
Indexed on
2012/10/31
23:00 UTC
Read the original article
Hit count: 396
I have a models.py like so:
from django.db import models
from django.contrib.auth.models import User
from datetime import datetime
class UserProfile(models.Model):
user = models.OneToOneField(User)
def __unicode__(self):
return self.user.username
class Project(models.Model):
user = models.ForeignKey(UserProfile)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
product = models.ForeignKey('tool.product')
module = models.ForeignKey('tool.module')
model = models.ForeignKey('tool.model')
zipcode = models.IntegerField(max_length=5)
def __unicode__(self):
return unicode(self.id)
And my tests.py:
from django.test import TestCase, Client
# --- import app models
from django.contrib.auth.models import User
from tool.models import Module, Model, Product
from user_profile.models import Project, UserProfile
# --- unit tests --- #
class UserProjectTests(TestCase):
fixtures = ['admin_user.json']
def setUp(self):
self.product1 = Product.objects.create(
name='bar',
)
self.module1 = Module.objects.create(
name='foo',
enable=True
)
self.model1 = Model.objects.create(
module=self.module1,
name='baz',
enable=True
)
self.user1 = User.objects.get(pk=1)
...
def test_can_create_project(self):
self.project1 = Model.objects.create(
user=self.user1,
product=self.product1,
module=self.module1,
model=self.model1,
zipcode=90210
)
self.assertEquals(self.project1.zipcode, 90210)
But I get a TypeError: 'product' is an invalid keyword argument for this function
error.
I'm not sure what is failing but I'm guessing something to do with the FK relationships...
Any help would be much appreciated.
© Stack Overflow or respective owner