Exemplo n.º 1
0
 def test_redirectToSettingsWhenLoggedIn(self):
     """
     When a user is already logged in, navigating to /resetPassword should
     redirect to the settings page, since the user can change their password
     from there.
     """
     self.assertNotIdentical(self.userStore.parent, None) # sanity check
     prefPage = ixmantissa.IPreferenceAggregator(self.userStore)
     urlPath = ixmantissa.IWebTranslator(self.userStore).linkTo(prefPage.storeID)
     request = FakeRequest(headers={"host": "example.com"})
     app = IResource(self.userStore)
     rsc = IResource(app.locateChild(request, ("resetPassword",))[0])
     d = renderPage(rsc, reqFactory=lambda : request)
     def rendered(result):
         self.assertEquals(
             'http://example.com' + urlPath,
             request.redirected_to)
     d.addCallback(rendered)
     return d
Exemplo n.º 2
0
class AnonymousSiteTests(SiteTestsMixin, TestCase):
    """
    Tests for L{AnonymousSite}.
    """

    def setUp(self):
        """
        Set up a store with a valid offering to test against.
        """
        SiteTestsMixin.setUp(self)
        self.store = self.siteStore
        self.site = ISiteURLGenerator(self.store)
        self.resource = IResource(self.store)

    def test_powersUpWebViewer(self):
        """
        L{AnonymousSite} provides an indirected L{IWebViewer}
        powerup, and its indirected powerup should be the default provider of
        that interface.
        """
        webViewer = IWebViewer(self.store)
        self.assertIsInstance(webViewer, _AnonymousWebViewer)
        self.assertIdentical(webViewer._siteStore, self.store)

    def test_login(self):
        """
        L{AnonymousSite} has a I{login} child which returns a L{LoginPage}
        instance.
        """
        host = "example.org"
        port = 1234
        netloc = "%s:%d" % (host, port)

        request = FakeRequest(headers={"host": netloc}, uri="/login/foo", currentSegments=[], isSecure=False)

        self.site.hostname = host.decode("ascii")
        SSLPort(store=self.store, portNumber=port, factory=self.site)

        resource, segments = self.resource.locateChild(request, ("login",))
        self.assertTrue(isinstance(resource, LoginPage))
        self.assertIdentical(resource.store, self.store)
        self.assertEqual(resource.segments, ())
        self.assertEqual(resource.arguments, {})
        self.assertEqual(segments, ())

    def test_resetPassword(self):
        """
        L{AnonymousSite} has a I{resetPassword} child which returns a
        L{PasswordResetResource} instance.
        """
        resource, segments = self.resource.locateChild(FakeRequest(headers={"host": "example.com"}), ("resetPassword",))
        self.assertTrue(isinstance(resource, PasswordResetResource))
        self.assertIdentical(resource.store, self.store)
        self.assertEqual(segments, ())

    def test_users(self):
        """
        L{AnonymousSite} has a I{users} child which returns a L{UserIndexPage}
        instance.
        """
        resource, segments = self.resource.locateChild(FakeRequest(headers={"host": "example.com"}), ("users",))
        self.assertTrue(isinstance(resource, UserIndexPage))
        self.assertIdentical(resource.loginSystem, self.store.findUnique(LoginSystem))
        self.assertEqual(segments, ())

    def test_notFound(self):
        """
        L{AnonymousSite.locateChild} returns L{NotFound} for requests it cannot
        find another response for.
        """
        result = self.resource.locateChild(FakeRequest(headers={"host": "example.com"}), ("foo", "bar"))
        self.assertIdentical(result, NotFound)
Exemplo n.º 3
0
class AnonymousSiteTests(SiteTestsMixin, TestCase):
    """
    Tests for L{AnonymousSite}.
    """
    def setUp(self):
        """
        Set up a store with a valid offering to test against.
        """
        SiteTestsMixin.setUp(self)
        self.store = self.siteStore
        self.site = ISiteURLGenerator(self.store)
        self.resource = IResource(self.store)

    def test_powersUpWebViewer(self):
        """
        L{AnonymousSite} provides an indirected L{IWebViewer}
        powerup, and its indirected powerup should be the default provider of
        that interface.
        """
        webViewer = IWebViewer(self.store)
        self.assertIsInstance(webViewer, _AnonymousWebViewer)
        self.assertIdentical(webViewer._siteStore, self.store)

    def test_login(self):
        """
        L{AnonymousSite} has a I{login} child which returns a L{LoginPage}
        instance.
        """
        host = 'example.org'
        port = 1234
        netloc = '%s:%d' % (host, port)

        request = FakeRequest(headers={'host': netloc},
                              uri='/login/foo',
                              currentSegments=[],
                              isSecure=False)

        self.site.hostname = host.decode('ascii')
        SSLPort(store=self.store, portNumber=port, factory=self.site)

        resource, segments = self.resource.locateChild(request, ("login", ))
        self.assertTrue(isinstance(resource, LoginPage))
        self.assertIdentical(resource.store, self.store)
        self.assertEqual(resource.segments, ())
        self.assertEqual(resource.arguments, {})
        self.assertEqual(segments, ())

    def test_resetPassword(self):
        """
        L{AnonymousSite} has a I{resetPassword} child which returns a
        L{PasswordResetResource} instance.
        """
        resource, segments = self.resource.locateChild(
            FakeRequest(headers={"host": "example.com"}), ("resetPassword", ))
        self.assertTrue(isinstance(resource, PasswordResetResource))
        self.assertIdentical(resource.store, self.store)
        self.assertEqual(segments, ())

    def test_users(self):
        """
        L{AnonymousSite} has a I{users} child which returns a L{UserIndexPage}
        instance.
        """
        resource, segments = self.resource.locateChild(
            FakeRequest(headers={"host": "example.com"}), ("users", ))
        self.assertTrue(isinstance(resource, UserIndexPage))
        self.assertIdentical(resource.loginSystem,
                             self.store.findUnique(LoginSystem))
        self.assertEqual(segments, ())

    def test_notFound(self):
        """
        L{AnonymousSite.locateChild} returns L{NotFound} for requests it cannot
        find another response for.
        """
        result = self.resource.locateChild(
            FakeRequest(headers={"host": "example.com"}), ("foo", "bar"))
        self.assertIdentical(result, NotFound)