Changeset 2338 in products
- Timestamp:
- May 18, 2010 8:29:24 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.referencedatagridfield/branches/plone4/quintagroup/referencedatagridfield/tests/testField.py
r2337 r2338 6 6 7 7 8 class Test Field(TestCase):9 """ Field unit tests """8 class TestReferenceDataGridField(TestCase): 9 """ ReferenceDataGridField unit tests """ 10 10 11 11 def afterSetUp(self): … … 14 14 self.refcat = self.portal.reference_catalog 15 15 self.field = self.demo.getField('demo_rdgf') 16 self.data = [{"uid": self.doc.UID(),17 "link": "http://test.link",18 "title": "test"},]19 16 20 17 def testColumnProperties(self): … … 33 30 34 31 def testGet(self): 32 data = [{"uid": self.doc.UID(), "link": "http://test.link", "title": "test"},] 35 33 # if data set: 36 34 # result is list with dictionary items, as in DataGridField 37 self.field.set(self.demo, self.data)35 self.field.set(self.demo, data) 38 36 39 37 field_data = self.field.get(self.demo) … … 49 47 self.assertEqual(item_data.has_key("title"), True) 50 48 49 def getData(self, key, index=0): 50 data = self.field.get(self.demo) 51 return data and data[index].get(key, None) or None 52 53 def getRefsCount(self): 54 return len(self.refcat.getReferences(self.demo, self.field.relationship)) 55 56 def testSetUID(self): 57 # link always must present in the data 58 row = {"uid": "", "link": "/"} 59 data = [row,] 60 # If set unexistent UID - UID - not set 61 row['uid'] = "123" 62 self.field.set(self.demo, data) 63 self.assertEqual(self.getData("uid"), None) 64 # No references to the object 65 self.assertEqual(self.getRefsCount(), 0) 66 67 # If link is not remote url and passed uid of existent object - uid is saved 68 row["uid"] = self.doc.UID() 69 self.field.set(self.demo, data) 70 self.assertEqual(self.getData("uid"), self.doc.UID()) 71 # Also reference added to the object catalog 72 self.assertEqual(self.getRefsCount(), 1) 73 74 def testSetTitleForLink(self): 75 row = {"link": "http://google.com"} 76 data = [row,] 77 # If there is title data with external link - it is stored in the field 78 row["title"] = "google" 79 self.field.set(self.demo, data) 80 self.assertEqual(self.getData("title"), "google") 81 82 # If No title specified for the external link title will be equals to link 83 row["title"] = "" 84 self.field.set(self.demo, data) 85 self.assertEqual(self.getData("title"), "http://google.com") 86 87 self.assertEqual(self.getRefsCount(), 0) 88 89 def testSetTitleForUID(self): 90 row = {"uid": self.doc.UID(), "link": "/"} 91 data = [row,] 92 # If there is title data with correct uid - it is stored in the field 93 row["title"] = "Custom Title" 94 self.field.set(self.demo, data) 95 self.assertEqual(self.getData("title"), "Custom Title") 96 97 # If No title specified with correct portal UID object - 98 # title will be get from the object 99 row["title"] = "" 100 self.field.set(self.demo, data) 101 self.assertEqual(self.getData("title"), "Test Document") 102 103 def testNoLink(self): 104 # Link is key data for the field. 105 # If no link present in the data - no data will be saved 106 # even with correct uid. 107 data = [{"uid": self.doc.UID(), "title": "Title"},] 108 self.field.set(self.demo, data) 109 self.assertEqual(self.field.get(self.demo), []) 110 # If a external link present in the data - it will be saved 111 data = [{"link": "http://google.com"},] 112 self.field.set(self.demo, data) 113 self.assertEqual(self.getData("link"), "http://google.com") 114 115 51 116 52 117 def test_suite(): 53 118 return unittest.TestSuite([ 54 unittest.makeSuite(Test DataGridRelatedField),119 unittest.makeSuite(TestReferenceDataGridField), 55 120 ])
Note: See TracChangeset
for help on using the changeset viewer.