~cbehrens/nova/lp844160-build-works-with-zones

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/web/test/test_script.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2009 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
 
3
 
 
4
"""
 
5
Tests for L{twisted.web.script}.
 
6
"""
 
7
 
 
8
import os
 
9
 
 
10
from twisted.trial.unittest import TestCase
 
11
from twisted.web.http import NOT_FOUND
 
12
from twisted.web.script import ResourceScriptDirectory, PythonScript
 
13
from twisted.web.test._util import _render
 
14
from twisted.web.test.test_web import DummyRequest
 
15
 
 
16
 
 
17
class ResourceScriptDirectoryTests(TestCase):
 
18
    """
 
19
    Tests for L{ResourceScriptDirectory}.
 
20
    """
 
21
    def test_render(self):
 
22
        """
 
23
        L{ResourceScriptDirectory.render} sets the HTTP response code to I{NOT
 
24
        FOUND}.
 
25
        """
 
26
        resource = ResourceScriptDirectory(self.mktemp())
 
27
        request = DummyRequest([''])
 
28
        d = _render(resource, request)
 
29
        def cbRendered(ignored):
 
30
            self.assertEqual(request.responseCode, NOT_FOUND)
 
31
        d.addCallback(cbRendered)
 
32
        return d
 
33
 
 
34
 
 
35
    def test_notFoundChild(self):
 
36
        """
 
37
        L{ResourceScriptDirectory.getChild} returns a resource which renders an
 
38
        response with the HTTP I{NOT FOUND} status code if the indicated child
 
39
        does not exist as an entry in the directory used to initialized the
 
40
        L{ResourceScriptDirectory}.
 
41
        """
 
42
        path = self.mktemp()
 
43
        os.makedirs(path)
 
44
        resource = ResourceScriptDirectory(path)
 
45
        request = DummyRequest(['foo'])
 
46
        child = resource.getChild("foo", request)
 
47
        d = _render(child, request)
 
48
        def cbRendered(ignored):
 
49
            self.assertEqual(request.responseCode, NOT_FOUND)
 
50
        d.addCallback(cbRendered)
 
51
        return d
 
52
 
 
53
 
 
54
 
 
55
class PythonScriptTests(TestCase):
 
56
    """
 
57
    Tests for L{PythonScript}.
 
58
    """
 
59
    def test_notFoundRender(self):
 
60
        """
 
61
        If the source file a L{PythonScript} is initialized with doesn't exist,
 
62
        L{PythonScript.render} sets the HTTP response code to I{NOT FOUND}.
 
63
        """
 
64
        resource = PythonScript(self.mktemp(), None)
 
65
        request = DummyRequest([''])
 
66
        d = _render(resource, request)
 
67
        def cbRendered(ignored):
 
68
            self.assertEqual(request.responseCode, NOT_FOUND)
 
69
        d.addCallback(cbRendered)
 
70
        return d