<commit_before># vim:nowrap:textwidth=0
#
# Sheared -- non-blocking network programming library for Python
# Copyright (C) 2003  <NAME> <<EMAIL>>
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

import unittest, os, random

from sheared import reactor
from sheared.web import server, subserver, virtualhost
from sheared.protocol import http
from sheared.python import commands

from tests import transport
from tests.web import SimpleCollection, parseReply

class HTTPServerTestCase(unittest.TestCase):
    def setUp(self):
        self.server = server.HTTPServer()
        vh = virtualhost.VirtualHost(SimpleCollection('foo.com'))
        self.server.addVirtualHost('foo.com', vh)
        vh = virtualhost.VirtualHost(SimpleCollection('bar.com'))
        self.server.addVirtualHost('bar.com', vh)
        self.server.setDefaultHost('bar.com')

        self.transport = transport.StringTransport()

        self.reactor = reactor
        self.reactor.createtasklet(self.server.startup, (self.transport,))

    def testFullRequestWithFoo(self):
        self.transport.appendInput('''GET / HTTP/1.0\r\nHost: foo.com\r\n\r\n''')
        self.reactor.start()

        status, headers, body = parseReply(self.transport.getOutput())
        
        self.assertEquals(status.version, (1, 0))
        self.assertEquals(status.code, 200)<commit_msg>Add test-case for posts.<commit_after># vim:nowrap:textwidth=0
#
# Sheared -- non-blocking network programming library for Python
# Copyright (C) 2003  <NAME> <<EMAIL>>
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

import unittest, os, random

from sheared import reactor
from sheared.web import server, subserver, virtualhost
from sheared.protocol import http
from sheared.python import commands

from tests import transport
from tests.web import SimpleCollection, parseReply

class HTTPServerTestCase(unittest.TestCase):
    def setUp(self):
        self.server = server.HTTPServer()
        vh = virtualhost.VirtualHost(SimpleCollection('foo.com'))
        self.server.addVirtualHost('foo.com', vh)
        vh = virtualhost.VirtualHost(SimpleCollection('bar.com'))
        self.server.addVirtualHost('bar.com', vh)
        self.server.setDefaultHost('bar.com')

        self.transport = transport.StringTransport()

        self.reactor = reactor
        self.reactor.createtasklet(self.server.startup, (self.transport,))

    def testPostRequest(self):
        self.transport.appendInput('POST /post HTTP/1.0\r\n'
                                   'Host: foo.com\r\n'
                                   'Content-Length: 12\r\n'
                                   'Content-Type: application/x-www-form-urlencoded\r\n'
                                   '\r\n'
                                   'q=fortytwo\r\n')
        self.reactor.start()

        status, headers, body = parseReply(self.transport.getOutput())

        self.assertEquals(body, 'Welcome to foo.com!\r\n')
        self.assertEquals(status.version, (1, 0))
        self.assertEquals(status.code, 200)

    def testFullRequestWithFoo(self):
        self.transport.appendInput('''GET / HTTP/1.0\r\nHost: foo.com\r\n\r\n''')
        self.reactor.start()

        status, headers, body = parseReply(self.transport.getOutput())
        
        self.assertEquals(status.version, (1, 0))
        self.assertEquals(status.code, 200)
{'fraction_non_alphanumeric': 0.09768140832975526, 'fraction_numerical': 0.013525118076427652, 'mean_word_length': 3.086842105263158, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5489728', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1271, 'n_words': 417}