Permalink
Browse files

Added to tests for last commit; now tests to make sure

 custom primary keys are editable from the Scrapy Item.
---
 scrapy/tests/test_djangoitem/__init__.py |   15 ++++++++++++++-
 scrapy/tests/test_djangoitem/models.py   |    7 +++++++
 2 files changed, 21 insertions(+), 1 deletions(-)
  • Loading branch information...
djm committed Jun 12, 2011
1 parent 05101c7 commit 6873d5b9524a9f2dd3d444a65bb01d03bdf468a3
Showing with 21 additions and 1 deletion.
  1. +14 −1 scrapy/tests/test_djangoitem/__init__.py
  2. +7 −0 scrapy/tests/test_djangoitem/models.py
@@ -11,9 +11,10 @@
django = None
if django:
- from .models import Person
+ from .models import Person, IdentifiedPerson
else:
Person = None
+ IdentifiedPerson = None
class BasePersonItem(DjangoItem):
@@ -28,6 +29,10 @@ class OverrideFieldPersonItem(BasePersonItem):
age = Field()
+class IdentifiedPersonItem(DjangoItem):
+ django_model = IdentifiedPerson
+
+
class DjangoItemTest(unittest.TestCase):
def setUp(self):
@@ -46,6 +51,14 @@ def test_override_field(self):
i = OverrideFieldPersonItem()
self.assertEqual(i.fields.keys(), ['age', 'name'])
+ def test_custom_primary_key_field(self):
+ """
+ Test that if a custom primary key exists, it is
+ in the field list.
+ """
+ i = IdentifiedPersonItem()
+ self.assertEqual(i.fields.keys(), ['age', 'identifier', 'name'])
+
def test_save(self):
i = BasePersonItem()
self.assertEqual(i.fields.keys(), ['age', 'name'])
@@ -8,3 +8,10 @@ class Person(models.Model):
class Meta:
app_label = 'test_djangoitem'
+class IdentifiedPerson(models.Model):
+ identifier = models.PositiveIntegerField(primary_key=True)
+ name = models.CharField(max_length=255)
+ age = models.IntegerField()
+
+ class Meta:
+ app_label = 'test_djangoitem'

0 comments on commit 6873d5b

Please sign in to comment.