source: products/quintagroup.plonegooglesitemaps/trunk/quintagroup/plonegooglesitemaps/tests/testNewsSitemaps.py @ 2538

Last change on this file since 2538 was 2538, checked in by mylan, 9 years ago

Merged revisions 3566-3575 via svnmerge from
http://svn.quintagroup.com/products/quintagroup.plonegooglesitemaps/branches/test_refactoring

........

r3566 | mylan | 2010-06-14 12:24:52 +0300 (Mon, 14 Jun 2010) | 1 line


#206: Split single testqPloneGoogleSitemaps module into several specific one

........

r3567 | mylan | 2010-06-14 16:14:34 +0300 (Mon, 14 Jun 2010) | 1 line


#206: Improve code coverage - remove useless BBB code from interfaces.

........

r3568 | mylan | 2010-06-14 20:24:25 +0300 (Mon, 14 Jun 2010) | 1 line


#206: Improve code coverage - added test for MobileSitemap?, MobileSitemapView?.

........

r3569 | mylan | 2010-06-14 22:39:39 +0300 (Mon, 14 Jun 2010) | 1 line


#206: reorganize sitemap tests

........

r3570 | mylan | 2010-06-14 22:40:12 +0300 (Mon, 14 Jun 2010) | 1 line


#206: Added configlet tests

........

r3571 | mylan | 2010-06-14 23:05:19 +0300 (Mon, 14 Jun 2010) | 1 line


#206: remove BBB code for plone<3.0

........

r3572 | mylan | 2010-06-14 23:12:00 +0300 (Mon, 14 Jun 2010) | 1 line


#206: added workflow vocabularies tests for SitemapTypes?

........

r3573 | mylan | 2010-06-15 21:36:40 +0300 (Tue, 15 Jun 2010) | 1 line


#206: some cleanup, simplify tests

........

r3574 | mylan | 2010-06-16 16:35:31 +0300 (Wed, 16 Jun 2010) | 1 line


#206: move mobile sitemap code preparation into base module

........

r3575 | mylan | 2010-06-16 16:37:14 +0300 (Wed, 16 Jun 2010) | 1 line


#206: Added security tests

........

  • Property svn:eol-style set to native
File size: 8.4 KB
Line 
1from base import *
2from DateTime import DateTime
3
4from zope.component import getSiteManager, getGlobalSiteManager
5from archetypes.schemaextender.interfaces import ISchemaExtender
6
7from Products.CMFPlone.utils import _createObjectByType
8
9class TestNewsSitemapsXML(FunctionalTestCase):
10
11    def afterSetUp(self):
12        super(TestNewsSitemapsXML, self).afterSetUp()
13        # Create news sitemaps
14        _createObjectByType("Sitemap", self.portal, id="news-sitemaps",
15                            sitemapType="news", portalTypes=("News Item",))
16        self.portal["news-sitemaps"].at_post_create_script()
17        # Add testing news item to portal
18        self.pubdate = (DateTime()+1).strftime("%Y-%m-%d")
19        self.my_news = _createObjectByType('News Item', self.portal, id='my_news')
20        self.my_news.edit(text="Test news item", title="First news (test)", language="ua",
21                          effectiveDate=self.pubdate, gsm_access="Registration",
22                          gsm_genres=("PressRelease",), gsm_stock="NASDAQ:AMAT, BOM:500325")
23        self.workflow.doActionFor(self.my_news, "publish")
24        self.reParse()
25
26    def reParse(self):
27        # Parse news sitemap
28        self.sitemap = self.publish("/"+self.portal.absolute_url(1) + "/news-sitemaps",
29                                    "%s:%s" % (portal_owner, default_password)).getBody()
30        parsed_sitemap = parse(self.sitemap)
31        self.start = parsed_sitemap["start"]
32        self.data = parsed_sitemap["data"]
33
34    def test_urlset(self):
35        self.assert_("urlset" in self.start.keys())
36        urlset = self.start["urlset"]
37        self.assertEqual(urlset.get("xmlns", ""), "http://www.sitemaps.org/schemas/sitemap/0.9")
38        self.assertEqual(urlset.get("xmlns:n", ""), "http://www.google.com/schemas/sitemap-news/0.9")
39
40    def test_url(self):
41        self.assert_("url" in self.start.keys())
42
43    def test_loc(self):
44        self.assert_("loc" in self.start.keys())
45        self.assert_(self.portal.absolute_url() + "/my_news" in self.data)
46
47    def test_nnews(self):
48        self.assert_("n:news" in self.start.keys())
49       
50    def test_npublication(self):
51        self.assert_("n:publication" in self.start.keys())
52        self.assert_("n:name" in self.start.keys())
53        self.assert_("First news" in self.data, "No 'First news' in data")
54        self.assert_("n:language" in self.start.keys())
55        self.assert_("ua" in self.data, "No 'ua' in data")
56
57    def test_npublication_date(self):
58        self.assert_("n:publication_date" in self.start.keys())
59        self.assert_(self.pubdate in self.data, "No %s in data" % self.pubdate)
60       
61    def test_ntitle(self):
62        self.assert_("n:title" in self.start.keys())
63        self.assert_("First news (test)" in self.data, "No 'First news (test)' in data")
64
65    def test_naccess(self):
66        # Test when access present
67        self.assert_("n:access" in self.start.keys())
68        self.assert_("Registration" in self.data, "No 'Registration' in data")
69
70    def test_ngenres(self):
71        # Test when genres present
72        self.assert_("n:genres" in self.start.keys())
73        self.assert_("PressRelease" in self.data, "No 'PressRelease' in data")
74
75    def test_ngenresMultiple(self):
76        # Test multiple genres
77        self.my_news.edit(gsm_genres=("PressRelease", "Blog"))
78        self.my_news.reindexObject()
79        self.reParse()
80        self.assert_("n:genres" in self.start.keys())
81        self.assert_("PressRelease, Blog" in self.data, "No 'PressRelease, Blog' in data")
82
83    def test_ngenresEmpty(self):
84        # No genres should present if it's not updated
85        self.my_news.edit(gsm_genres=[])
86        self.my_news.reindexObject()
87        self.reParse()
88        self.assertNotEqual("n:genres" in self.start.keys(), True)
89
90    def test_ngenresForNotExtended(self):
91        # No genres should present for not extended content type
92        my_doc = _createObjectByType('Document', self.portal, id='my_doc')
93        #self.portal.invokeFactory("Document", id="my_doc")
94        #my_doc = getattr(self.portal, "my_doc")
95        my_doc.edit(text="Test document")
96        self.workflow.doActionFor(my_doc, "publish")
97        self.portal["news-sitemaps"].edit(portalTypes=("Document",))
98        self.reParse()
99        open("/tmp/news.sm.docs.xml", "w").write(self.sitemap)
100        self.assertNotEqual("n:genres" in self.start.keys(), True)
101
102    def test_nstock_tickers(self):
103        # Test n:stock_tickers
104        self.assert_("n:stock_tickers" in self.start.keys())
105        self.assert_("NASDAQ:AMAT, BOM:500325" in self.data, "No 'NASDAQ:AMAT, BOM:500325' in data")
106
107
108class TestNewsSitemapsXMLDefaultObject(FunctionalTestCase):
109
110    def afterSetUp(self):
111        super(TestNewsSitemapsXMLDefaultObject, self).afterSetUp()
112        # Create news sitemaps
113        _createObjectByType("Sitemap", self.portal, id="news-sitemaps",
114                            sitemapType="news", portalTypes=("News Item",))
115        self.portal["news-sitemaps"].at_post_create_script()
116        # Add minimal testing news item to portal
117        self.pubdate = (DateTime()+1).strftime("%Y-%m-%d")
118        self.my_news = _createObjectByType('News Item', self.portal, id='my_news')
119        self.my_news.edit(effectiveDate=self.pubdate)
120        self.workflow.doActionFor(self.my_news, "publish")
121        self.reParse()
122
123    def reParse(self):
124        # Parse news sitemap
125        self.sitemap = self.publish("/"+self.portal.absolute_url(1) + "/news-sitemaps",
126                                    "%s:%s" % (portal_owner, default_password)).getBody()
127        parsed_sitemap = parse(self.sitemap)
128        self.start = parsed_sitemap["start"]
129        self.data = parsed_sitemap["data"]
130
131    def test_nnews(self):
132        self.assert_("n:news" in self.start.keys())
133       
134    def test_npublication(self):
135        self.assert_("n:publication" in self.start.keys())
136        self.assert_("n:name" in self.start.keys())
137        self.assert_("my_news" in self.data, "No 'First news' in data")
138        self.assert_("n:language" in self.start.keys())
139        self.assert_("en" in self.data, "No 'en' in data")
140
141    def test_npublication_date(self):
142        self.assert_("n:publication_date" in self.start.keys())
143        self.assert_(self.pubdate in self.data, "No %s in data" % self.pubdate)
144       
145    def test_ntitle(self):
146        self.assert_("n:title" in self.start.keys())
147        self.assert_("my_news" in self.data, "No 'First news (test)' in data")
148
149    def test_no_naccess(self):
150        self.assert_("n:access" not in self.start.keys())
151
152    def test_no_ngenres(self):
153        self.assert_("n:genres" not in self.start.keys())
154
155    def test_no_keywords(self):
156        self.assert_("n:keywords" not in self.start.keys())
157
158    def test_no_keywords(self):
159        self.assert_("n:stock_tickers" not in self.start.keys())
160
161
162from Products.ATContentTypes.interface import IATNewsItem
163from quintagroup.plonegooglesitemaps.content.newsextender import NewsExtender
164
165class TestSchemaExtending(TestCase):
166
167    def afterSetUp(self):
168        super(TestSchemaExtending, self).afterSetUp()
169        self.my_doc = _createObjectByType('Document', self.portal, id='my_doc')
170        self.my_news = _createObjectByType('News Item', self.portal, id='my_news')
171
172    def testExtendNewsItemByDefault(self):
173        # Neither of object has extended fields
174        self.assertNotEqual(self.my_news.getField("gsm_access"), None)
175        self.assertNotEqual(self.my_news.getField("gsm_genres"), None)
176        self.assertNotEqual(self.my_news.getField("gsm_stock"), None)
177        self.assertEqual(self.my_doc.getField("gsm_access"), None)
178        self.assertEqual(self.my_doc.getField("gsm_genres"), None)
179        self.assertEqual(self.my_doc.getField("gsm_stock"), None)
180   
181    def testRegistrationOnLocalSM(self):
182        """SchemaExtender adapters must be registered
183           in Local SiteManager only.
184        """
185        localsm = getSiteManager(self.portal)
186        globalsm = getGlobalSiteManager()
187        # Now register SchemaExtender adapter and
188        # check if it present in Local SiteManger only
189        self.assertNotEqual(localsm, globalsm)
190        self.assertNotEqual(localsm.queryAdapter(self.my_news, ISchemaExtender), None)
191        self.assertEqual(globalsm.queryAdapter(self.my_news, ISchemaExtender), None)
192
193
194def test_suite():
195    from unittest import TestSuite, makeSuite
196    suite = TestSuite()
197    suite.addTest(makeSuite(TestNewsSitemapsXML))
198    suite.addTest(makeSuite(TestNewsSitemapsXMLDefaultObject))
199    suite.addTest(makeSuite(TestSchemaExtending))
200    return suite
Note: See TracBrowser for help on using the repository browser.