mirror of https://github.com/scrapy/scrapy.git
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(-)
This commit is contained in:
parent
05101c7bba
commit
6873d5b952
|
|
@ -11,9 +11,10 @@ except ImportError:
|
|||
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 @@ class DjangoItemTest(unittest.TestCase):
|
|||
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'
|
||||
|
|
|
|||
Loading…
Reference in New Issue