我无法追踪此测试失败的原因:
def test_CreateViewPost(self):
user = self.client.login(username="g",password="g")
# this method creates a poi type and returns it for me
poiType = self.stubPOIType()
# this creates a point (django.contrib.gis.geos.Point)
point = Point(10,10)
response = self.client.post(reverse("createPOI"),{"name":"testPOI",
"description":"description",
"type":poiType,
"geometry":point})
# the post is failing. I have errors in my form
self.assertTemplateUsed(response,"gazetteer/detailPOI.html")
self.assertEqual(response.status_code,302)
self.assertEqual(POI.objects.count(),1)
这是模型:
class POI(models.Model):
name = models.CharField(max_length=128,verbose_name=u"Nome")
description = models.CharField(max_length=1024,verbose_name=u"Descrição",null=True,blank=True)
type = models.ForeignKey(POIType,verbose_name=u"Tipo de Ponto")
geometry = models.PointField(verbose_name=u"Geometria",srid=4291)
geohash = models.CharField(max_length=64,verbose_name=u"GeoHash",editable=False)
objects = models.GeoManager()
我从表单中返回两个错误:字段几何和类型的“无效几何值”和“无效选择”。我正在将这些传递给帖子,但它失败了。
有小费吗?
编辑:我已经跟踪到“无效几何值”的失败是我的表单需要文本(WKT 表单)而不是实际的 GEOS 点。我已经将实际的 .wkt 添加到它并且它有效。但是外键呢?我应该通过pk吗?
为什么?