def setUp(self):
     self.scrubenv()
     self.config = Config()
     for app in ('app1', 'app2'):
         if os.path.isdir(app):
             os.rmdir(app)
         os.mkdir(app)
Exemple #2
0
 def __init__(self):
     self.http_version_string = "HTTP/1.0"
     self.response_header = "stub server"
     self.config = Config(['-rroot'])
     self.debug_mode = False
     self.deploy_mode = True
     self.devel_mode = False
Exemple #3
0
def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]
    try:
        config = Config(argv).ossify()
    except ConfigError, err:
        print >> sys.stderr, err.msg
        print >> sys.stderr, "`man 1 httpy' for usage."
        return 2
Exemple #4
0
    def setUp(self):

        self.scrubenv()

        # [re]build a temporary website tree in ./root
        self.removeTestSite()
        self.buildTestSite()

        if self.server:
            self.startServer()

        if self.want_config:
            self.config = Config()
Exemple #5
0
def main(argv=None):

    # Read in configuration options.
    # ==============================

    if argv is None:
        argv = sys.argv[1:]
    try:
        config = Config(argv)
    except ConfigError, err:
        print >> sys.stderr, err.msg
        print >> sys.stderr, "`man 1 httpy' for usage."
        return 2
Exemple #6
0
    def testOverlapProperly(self):

        # set up environment
        os.environ['HTTPY_MODE'] = 'development'  # should be retained
        os.environ['HTTPY_PORT'] = '9000'  # should be overriden
        os.environ['HTTPY_VERBOSITY'] = '99'  # should be retained

        # set up configuration file
        conf = file('httpy.conf', 'w')
        conf.write(
            os.linesep.join([
                "[main]",
                "port: 537"  # should be retained
                ,
                "root = /etc"  # should be overridden
            ]))
        conf.close()

        argv = [
            '-r',
            'root'  # should be retained
            ,
            '-f',
            'httpy.conf'  # should be retained
        ]

        # expected
        d = {}
        d['ip'] = ''  # default
        d['port'] = 537  # file
        d['root'] = os.path.realpath('./root')  # opts
        d['apps'] = [None]  # default

        e = {}
        e['HTTPY_MODE'] = 'development'  # env
        e['HTTPY_VERBOSITY'] = '99'  # env

        config = Config(argv)

        for k, expected in d.items():
            if k == 'apps':
                continue
            actual = getattr(config, k)
            self.assertEqual(expected, actual)
        self.assertEqual([a.__ for a in config.apps], d['apps'])

        for k, expected in e.items():
            actual = os.environ[k]
            self.assertEqual(expected, actual)
Exemple #7
0
def main(argv=None):

    # Read in configuration options.
    # ==============================
    # We override the default port number

    Config.address = ('', 5370)

    if argv is None:
        argv = sys.argv[1:]
    try:
        config = Config(argv)
    except ConfigError, err:
        print >> sys.stderr, err.msg
        print >> sys.stderr, "`man 1 mimed' for usage."
        return 2
Exemple #8
0
 def startServer(self):
     if len(asyncore.socket_map) != 1:
         # Let sockets die off.
         # TODO tests should be more careful to clear the socket map.
         asyncore.poll(0.1)
     self.orig_map_size = len(asyncore.socket_map)
     #self.hook_asyncore_error()
     config = Config(opts)
     self._server = Server(config, threads=4)
     self._server.accept_connections()
     self.port = self._server.socket.getsockname()[1]
     self.run_loop = 1
     self.counter = 0
     self.thread_started = threading.Event()
     self.thread = threading.Thread(target=self.loop)
     self.thread.setDaemon(True)
     self.thread.start()
     self.thread_started.wait(10.0)
     self.assert_(self.thread_started.isSet())
Exemple #9
0
    def testDefaults(self):

        d = {}
        d['sockfam'] = 2 # socket.AF_INET
        d['address'] = ('', 8080)
        d['root'] = os.path.realpath('.')
        d['apps'] = [None]

        e = {}
        e['HTTPY_MODE'] = 'deployment'
        e['HTTPY_VERBOSITY'] = '1'

        config = Config()

        for k, expected in d.items():
            if k == 'apps':
                continue
            actual = getattr(config, k)
            self.assertEqual(expected, actual)
        self.assertEqual([a.__ for a in config.apps], d['apps'])

        for k, expected in e.items():
            actual = os.environ[k]
            self.assertEqual(expected, actual)
Exemple #10
0
 def setUp(self):
     config = Config()
     self.server = Server(config)
 def testCanExplicitlyTurnOffAllApps(self):
     file('httpy.conf', 'w').write('[m]\napps=\n')
     self.config = Config(['-fhttpy.conf'])
     expected = [None]  # Can't turn off root app though!
     actual = [a.__ for a in self.config.apps]
     self.assertEqual(expected, actual)
 def testRootOnlyAddedIfNotAlreadyThere(self):
     self.config = Config(['-a/:/app1', '-rroot'])
     expected = [None, os.path.realpath('root/app1/__')]
     actual = [a.__ for a in self.config.apps]
     self.assertEqual(expected, actual)
 def testExplicitlySettingAppsOverridesMagic(self):
     self.config = Config(['-a/app1', '-rroot'])
     expected = [os.path.realpath('root/app1/__'), None]
     actual = [a.__ for a in self.config.apps]
     self.assertEqual(expected, actual)