[1674] | 1 | Introduction |
---|
| 2 | ============ |
---|
| 3 | |
---|
| 4 | This is a full-blown functional test. The emphasis here is on testing what |
---|
| 5 | the user may input and see, and the system is largely tested as a black box. |
---|
| 6 | We use PloneTestCase to set up this test as well, so we have a full Plone site |
---|
| 7 | to play with. We *can* inspect the state of the portal, e.g. using |
---|
| 8 | self.portal and self.folder, but it is often frowned upon since you are not |
---|
| 9 | treating the system as a black box. Also, if you, for example, log in or set |
---|
| 10 | roles using calls like self.setRoles(), these are not reflected in the test |
---|
| 11 | browser, which runs as a separate session. |
---|
| 12 | |
---|
| 13 | Being a doctest, we can tell a story here. |
---|
| 14 | |
---|
| 15 | First, we must perform some setup. We use the testbrowser that is shipped |
---|
| 16 | with Five, as this provides proper Zope 2 integration. Most of the |
---|
| 17 | documentation, though, is in the underlying zope.testbrower package. |
---|
| 18 | |
---|
| 19 | >>> from Products.Five.testbrowser import Browser |
---|
| 20 | >>> browser = Browser() |
---|
| 21 | >>> portal_url = self.portal.absolute_url() |
---|
| 22 | |
---|
| 23 | The following is useful when writing and debugging testbrowser tests. It lets |
---|
| 24 | us see all error messages in the error_log. |
---|
| 25 | |
---|
| 26 | >>> self.portal.error_log._ignored_exceptions = () |
---|
| 27 | |
---|
| 28 | With that in place, we can go to the portal front page and log in. We will |
---|
| 29 | do this using the default user from PloneTestCase: |
---|
| 30 | |
---|
| 31 | >>> from Products.PloneTestCase.setup import portal_owner, default_password |
---|
| 32 | >>> browser.open(portal_url) |
---|
| 33 | |
---|
| 34 | We have the login portlet, so let's use that. |
---|
| 35 | |
---|
| 36 | >>> browser.open('http://nohost/plone/login_form') |
---|
| 37 | >>> browser.getLink('Log in').click() |
---|
| 38 | >>> browser.url |
---|
| 39 | 'http://nohost/plone/login_form' |
---|
| 40 | >>> browser.getControl('Login Name').value = portal_owner |
---|
| 41 | >>> browser.getControl('Password').value = default_password |
---|
| 42 | >>> browser.getControl('Log in').click() |
---|
| 43 | >>> "You are now logged in" in browser.contents |
---|
| 44 | True |
---|
| 45 | >>> "Login failed" in browser.contents |
---|
| 46 | False |
---|
| 47 | >>> browser.url |
---|
| 48 | 'http://nohost/plone/login_form' |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | -*- extra stuff goes here -*- |
---|
[1820] | 52 | Test 'SEO Properties' action |
---|
[1674] | 53 | =============================== |
---|
| 54 | |
---|
[1849] | 55 | >>> self.qi = self.portal.portal_quickinstaller |
---|
| 56 | >>> self.sp = self.portal.portal_properties.seo_properties |
---|
| 57 | >>> self.object_tabs = self.portal.portal_actions.object |
---|
| 58 | >>> self.ps = self.portal.portal_setup |
---|
| 59 | |
---|
[1833] | 60 | First uninstall product, if it is already installed: |
---|
| 61 | |
---|
| 62 | >>> from quintagroup.seoptimizer.config import PROJECT_NAME |
---|
| 63 | >>> if self.qi.isProductInstalled(PROJECT_NAME): |
---|
| 64 | ... self.qi.uninstallProducts([PROJECT_NAME,]) |
---|
| 65 | |
---|
| 66 | |
---|
[1820] | 67 | Test installation 'SEO Properties' action |
---|
| 68 | |
---|
| 69 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 70 | >>> "SEO Properties" in browser.contents |
---|
| 71 | False |
---|
| 72 | >>> self.qi.installProduct(PROJECT_NAME) |
---|
| 73 | 'Ran all install steps.' |
---|
| 74 | >>> self.portal.portal_actions.object.get('SEOProperties', None) is not None |
---|
| 75 | True |
---|
| 76 | |
---|
| 77 | Test visibility 'SEO Properties' action after installation |
---|
| 78 | |
---|
| 79 | >>> self.sp.content_types_with_seoproperties = ('Document',) |
---|
| 80 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 81 | >>> "SEO Properties" in browser.contents |
---|
| 82 | True |
---|
| 83 | >>> browser.getLink('SEO Properties').url |
---|
| 84 | 'http://nohost/plone/front-page/@@seo-context-properties' |
---|
| 85 | |
---|
| 86 | Test invisibility 'SEO Properties' action after installation |
---|
| 87 | |
---|
| 88 | >>> self.sp.content_types_with_seoproperties = ('File',) |
---|
| 89 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 90 | >>> "SEO Properties" in browser.contents |
---|
| 91 | False |
---|
| 92 | |
---|
| 93 | Test reinstallation 'SEO Properties' action |
---|
[1849] | 94 | For perform all upgrade steps on re-installation, earlier version of profile must be set. |
---|
[1820] | 95 | |
---|
| 96 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 97 | >>> "SEO Properties" in browser.contents |
---|
| 98 | False |
---|
[1849] | 99 | >>> self.ps.setLastVersionForProfile('quintagroup.seoptimizer:default', '2.0.0') |
---|
[1820] | 100 | >>> self.qi.reinstallProducts((PROJECT_NAME,)) |
---|
| 101 | >>> self.portal.portal_actions.object.get('SEOProperties', None) is not None |
---|
| 102 | True |
---|
| 103 | |
---|
| 104 | Test visibility 'SEO Properties' action after reinstallation |
---|
| 105 | |
---|
| 106 | >>> self.sp.content_types_with_seoproperties = ('Document',) |
---|
| 107 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 108 | >>> "SEO Properties" in browser.contents |
---|
| 109 | True |
---|
| 110 | >>> browser.getLink('SEO Properties').url |
---|
| 111 | 'http://nohost/plone/front-page/@@seo-context-properties' |
---|
| 112 | |
---|
| 113 | Test invisibility 'SEO Properties' action after reinstallation |
---|
| 114 | |
---|
| 115 | >>> self.sp.content_types_with_seoproperties = ('File',) |
---|
| 116 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 117 | >>> "SEO Properties" in browser.contents |
---|
| 118 | False |
---|
| 119 | |
---|
| 120 | Test uninstallation 'SEO Properties' action |
---|
| 121 | |
---|
| 122 | >>> self.sp.content_types_with_seoproperties = ('Document',) |
---|
| 123 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 124 | >>> "SEO Properties" in browser.contents |
---|
| 125 | True |
---|
| 126 | >>> self.qi.uninstallProducts((PROJECT_NAME,)) |
---|
| 127 | >>> self.portal.portal_actions.object.get('SEOProperties', None) is not None |
---|
| 128 | False |
---|
| 129 | |
---|
| 130 | Test visibility 'SEO Properties' action after uninstallation |
---|
| 131 | |
---|
| 132 | >>> self.sp.content_types_with_seoproperties = ('Document',) |
---|
| 133 | >>> browser.open('http://nohost/plone/front-page') |
---|
| 134 | >>> "SEO Properties" in browser.contents |
---|
| 135 | False |
---|