source: products/quintagroup.referencedatagridfield/trunk/quintagroup/referencedatagridfield/tests/testField.py @ 2360

Last change on this file since 2360 was 2360, checked in by mylan, 14 years ago

Toggle trunk for plone4 release.
Plone-3 release moved to brances/plone3.

Merged revisions 3345-3351,3355-3359,3361-3370,3372-3390,3397 via svnmerge from
http://svn.quintagroup.com/products/quintagroup.referencedatagridfield/branches/plone4

Fixed minor conflicts in:

  • ./setup.py
  • ./quintagroup/referencedatagridfield/configure.zcml

........

r3345 | mylan | 2010-05-13 15:51:53 +0300 (Thu, 13 May 2010) | 1 line


Update requirements: in setup.py, included its in configure.zcml

........

r3346 | mylan | 2010-05-13 17:42:07 +0300 (Thu, 13 May 2010) | 1 line


Added refdatagridbrowser_popup view with popup customization for the referencedatagridfield

........

r3347 | mylan | 2010-05-13 17:50:14 +0300 (Thu, 13 May 2010) | 1 line


Added and registered datagridref_popup named template for the ReferenceDataGridWidget?

........

r3348 | mylan | 2010-05-13 18:59:34 +0300 (Thu, 13 May 2010) | 1 line


Fix typo in named_template_adapter

........

r3349 | mylan | 2010-05-13 19:00:21 +0300 (Thu, 13 May 2010) | 1 line


Prevent breakage of datagridwidget_manipulators.pt

........

r3350 | mylan | 2010-05-13 20:01:59 +0300 (Thu, 13 May 2010) | 1 line


Initial reference popup integration

........

r3351 | mylan | 2010-05-13 22:05:47 +0300 (Thu, 13 May 2010) | 1 line


Update default referencebrowser javascript / datagrid field to popup work correctly for new added row

........

r3355 | mylan | 2010-05-14 17:21:23 +0300 (Fri, 14 May 2010) | 1 line


Fix reference browser url calculation on the view - pass additional paramters

........

r3356 | mylan | 2010-05-14 17:26:49 +0300 (Fri, 14 May 2010) | 1 line


Update datagridwidget_manipulators template for additional params pass to datagridref_popup view

........

r3357 | mylan | 2010-05-14 17:27:59 +0300 (Fri, 14 May 2010) | 1 line


Remove order_idx from the additional parmeters - it will be calulated with jQuery

........

r3358 | mylan | 2010-05-14 17:29:20 +0300 (Fri, 14 May 2010) | 1 line


Updated jQuery processor on UID adding

........

r3359 | mylan | 2010-05-14 17:31:54 +0300 (Fri, 14 May 2010) | 1 line


Added focus and blur event-handlers to referencedatagridwidget javascripts

........

r3361 | mylan | 2010-05-17 18:08:44 +0300 (Mon, 17 May 2010) | 1 line


Fixed all overlays bindings to same target issue

........

r3362 | mylan | 2010-05-17 18:29:07 +0300 (Mon, 17 May 2010) | 1 line


Fix error with everlay windows autoclosing

........

r3363 | mylan | 2010-05-17 18:29:51 +0300 (Mon, 17 May 2010) | 1 line


Fix error with everlay windows autoclosing

........

r3364 | mylan | 2010-05-17 18:35:25 +0300 (Mon, 17 May 2010) | 1 line


Fixed link, title and uid data set in refbrowser_setReference

........

r3365 | mylan | 2010-05-17 18:38:15 +0300 (Mon, 17 May 2010) | 1 line


Fix error with everlay windows autoclosing

........

r3366 | mylan | 2010-05-17 18:43:18 +0300 (Mon, 17 May 2010) | 1 line


Fix addReferenceDataGridRowAfter newly added method of dataGridFieldFunctions

........

r3367 | mylan | 2010-05-17 18:46:10 +0300 (Mon, 17 May 2010) | 1 line


Implemented addReferenceDataGridRowAfter method of dataGridFieldFunctions object

........

r3368 | mylan | 2010-05-17 18:47:22 +0300 (Mon, 17 May 2010) | 1 line


Override updateOrderIndex method of dataGridFieldFunctions

........

r3369 | mylan | 2010-05-17 19:14:01 +0300 (Mon, 17 May 2010) | 1 line


Fixed styles toggling on title column edition

........

r3370 | mylan | 2010-05-17 20:35:10 +0300 (Mon, 17 May 2010) | 1 line


Little clean-up

........

r3372 | mylan | 2010-05-18 19:02:12 +0300 (Tue, 18 May 2010) | 1 line


Fix Deprication warning for plone4 consider importing

........

r3373 | mylan | 2010-05-18 19:04:12 +0300 (Tue, 18 May 2010) | 1 line


Added base tests structure, move tests into the tests package

........

r3374 | mylan | 2010-05-18 19:04:51 +0300 (Tue, 18 May 2010) | 1 line


Added installation tests

........

r3375 | mylan | 2010-05-18 20:08:00 +0300 (Tue, 18 May 2010) | 1 line


Fixed package installation, updated demo content creation to MixIn? class

........

r3376 | mylan | 2010-05-18 22:20:41 +0300 (Tue, 18 May 2010) | 1 line


Added basic field test

........

r3377 | mylan | 2010-05-18 23:29:24 +0300 (Tue, 18 May 2010) | 1 line


Added test for link, uid, title for the field

........

r3378 | mylan | 2010-05-19 10:54:46 +0300 (Wed, 19 May 2010) | 1 line


Prevent changing security manager on tested content adding

........

r3379 | mylan | 2010-05-19 13:58:29 +0300 (Wed, 19 May 2010) | 1 line


Added tests for possible bugs in field processing

........

r3380 | mylan | 2010-05-19 13:58:54 +0300 (Wed, 19 May 2010) | 1 line


Updated testing content creation

........

r3381 | mylan | 2010-05-19 13:59:49 +0300 (Wed, 19 May 2010) | 1 line


Simplify field name for example content type

........

r3382 | mylan | 2010-05-19 14:01:16 +0300 (Wed, 19 May 2010) | 1 line


Fixed bug on getting data for uninitialized field

........

r3383 | mylan | 2010-05-19 15:22:37 +0300 (Wed, 19 May 2010) | 1 line


Added tests for widget in view mode

........

r3384 | mylan | 2010-05-19 16:47:06 +0300 (Wed, 19 May 2010) | 1 line


Update comments for TestWidgetView?, some code cleanup

........

r3385 | mylan | 2010-05-19 17:02:29 +0300 (Wed, 19 May 2010) | 1 line


Added TestWidgetEditPresence? tests for presence of columns and buttons in edit mode of the widget

........

r3386 | mylan | 2010-05-19 18:00:01 +0300 (Wed, 19 May 2010) | 1 line


Remove records with links to unexistent objects on getting data from the field

........

r3387 | mylan | 2010-05-19 18:13:57 +0300 (Wed, 19 May 2010) | 1 line


Minor changes

........

r3388 | mylan | 2010-05-19 18:14:42 +0300 (Wed, 19 May 2010) | 1 line


Added tests popup related adapters registration

........

r3389 | mylan | 2010-05-19 19:10:49 +0300 (Wed, 19 May 2010) | 1 line


Added tests for pupup related staff in edit mode of ReferenceDataGridWidget?

........

r3390 | mylan | 2010-05-19 19:12:06 +0300 (Wed, 19 May 2010) | 1 line


Added tests of widget resources

........

r3397 | mylan | 2010-05-19 21:02:51 +0300 (Wed, 19 May 2010) | 1 line


Added MANIFEST.in, updated author in package information

........

  • Property svn:eol-style set to native
File size: 5.7 KB
Line 
1import unittest
2from types import ListType, TupleType, DictionaryType
3from Products.Archetypes.tests.utils import makeContent
4
5from quintagroup.referencedatagridfield.tests.base import TestCase
6
7from quintagroup.referencedatagridfield import ReferenceDataGridWidget
8
9
10class TestField(TestCase):
11    """ ReferenceDataGridField unit tests """
12
13    def afterSetUp(self):
14        self.loginAsPortalOwner()
15        self.createDemo()
16        self.refcat = self.portal.reference_catalog
17        self.field = self.demo.getField('demo_rdgf')
18
19    def testColumnProperties(self):
20        self.assertEqual(hasattr(self.field, "columns"), True)
21        for column in ['title', 'link', 'uid']:
22            self.assertEqual(column in self.field.columns, True)
23
24    def testWidget(self):
25        self.assertEqual(type(self.field.widget), ReferenceDataGridWidget)
26
27    def testGetInitial(self):
28        # If no data set - emty list must be returned
29        field_data = self.field.get(self.demo)
30        self.assertEqual(type(field_data), ListType)
31        self.assertEqual(len(field_data), 0)
32
33    def testGet(self):
34        data = [{"uid": self.doc.UID(), "link": "http://test.link", "title": "test"},]
35        # if data set:
36        # result is list with dictionary items, as in DataGridField
37        self.field.set(self.demo, data)
38
39        field_data = self.field.get(self.demo)
40        self.assertEqual(type(field_data), ListType)
41        self.assertEqual(len(field_data), 1)
42
43        # items in list is Dictionary
44        item_data = field_data[0]
45        self.assertEqual(type(item_data), DictionaryType)
46        # Dictionary contains uid, link, title keys
47        self.assertEqual(item_data.has_key("uid"), True)
48        self.assertEqual(item_data.has_key("link"), True)
49        self.assertEqual(item_data.has_key("title"), True)
50
51    def getData(self, key, index=0):
52        data = self.field.get(self.demo)
53        return data and data[index].get(key, None) or None
54
55    def getRefsCount(self):
56        return len(self.refcat.getReferences(self.demo, self.field.relationship))
57
58    def testSetUID(self):
59        # link always must present in the data
60        row = {"uid": "", "link": "/"}
61        data = [row,]
62        # If set unexistent UID - UID - not set
63        row['uid'] = "123"
64        self.field.set(self.demo, data)
65        self.assertEqual(self.getData("uid"), None)
66        # No references to the object
67        self.assertEqual(self.getRefsCount(), 0)
68
69        # If link is not remote url and passed uid of existent object  - uid is saved
70        row["uid"] = self.doc.UID()
71        self.field.set(self.demo, data)
72        self.assertEqual(self.getData("uid"), self.doc.UID())
73        # Also reference added to the object catalog
74        self.assertEqual(self.getRefsCount(), 1)
75
76    def testSetTitleForLink(self):
77        row = {"link": "http://google.com"}
78        data = [row,]
79        # If there is title data with external link - it is stored in the field
80        row["title"] = "google"
81        self.field.set(self.demo, data)
82        self.assertEqual(self.getData("title"), "google")
83
84        # If No title specified for the external link title will be  equals to link
85        row["title"] = ""
86        self.field.set(self.demo, data)
87        self.assertEqual(self.getData("title"), "http://google.com")
88       
89        self.assertEqual(self.getRefsCount(), 0)
90       
91    def testSetTitleForUID(self):
92        row = {"uid": self.doc.UID(), "link": "/"}
93        data = [row,]
94        # If there is title data with correct uid - it is stored in the field
95        row["title"] = "Custom Title"
96        self.field.set(self.demo, data)
97        self.assertEqual(self.getData("title"), "Custom Title")
98
99        # If No title specified with correct portal UID object -
100        # title will be get from the object
101        row["title"] = ""
102        self.field.set(self.demo, data)
103        self.assertEqual(self.getData("title"), "Test Document")
104
105    def testNoLink(self):
106        # Link is key data for the field.
107        # If no link present in the data - no data will be saved
108        # even with correct uid.
109        data = [{"uid": self.doc.UID(), "title": "Title"},]
110        self.field.set(self.demo, data)
111        self.assertEqual(self.field.get(self.demo), [])
112        # If a external link present in the data - it will be saved   
113        data = [{"link": "http://google.com"},]
114        self.field.set(self.demo, data)
115        self.assertEqual(self.getData("link"), "http://google.com")
116       
117
118class TestFieldBugs(TestCase):
119    """ ReferenceDataGridField unit tests for bugs """
120
121    def afterSetUp(self):
122        self.loginAsPortalOwner()
123        # minimal demo content creation
124        self.demo = makeContent(self.portal, portal_type="ReferenceDataGridDemoType", id="demo")
125        self.field = self.demo.getField('demo_rdgf')
126
127    def testGetNotInitializedField(self):
128        self.field.getStorage().unset('demo_rdgf', self.demo)
129        try:
130            data = self.field.get(self.demo)
131        except KeyError, e:
132            self.fail(str(e) + " on getting data from not initialized field")
133
134    def testDelLinkedObject(self):
135        doc = makeContent(self.portal, portal_type="Document", id="doc")
136        data = {"uid": doc.UID(), "link": doc.absolute_url(1)}
137        self.field.set(self.demo, data)
138
139        res = self.field.get(self.demo)
140        self.assertEqual(res[0]["uid"], doc.UID())
141
142        self.portal.manage_delObjects(ids=["doc",])
143        try:
144            res = self.field.get(self.demo)
145        except AttributeError, e:
146            self.fail(str(e) + " on getting data when linked object was delited")
147        self.assertEqual(len(res), 0, "Not removed data with link to deleted object")
148
149def test_suite():
150    return unittest.TestSuite([
151        unittest.makeSuite(TestField),
152        unittest.makeSuite(TestFieldBugs),
153        ])
Note: See TracBrowser for help on using the repository browser.