def setUp(self): meep_example_app.initialize() app = meep_example_app.MeepExampleApp() self.app = app u = meeplib.User('foo', 'bar', -1) v = meeplib.User('foo2', 'bar2', -1) m = meeplib.Message('my title', 'lol', u, -1)
def setUp(self): #the backup data causes some of the tests to fail - not sure why #remove the backup data before every test cur.execute("DELETE FROM MESSAGE") cur.execute("DELETE FROM SESSION") cur.execute("DELETE FROM USER") con.commit() meep_example_app.meeplib._users = {} meep_example_app.meeplib._messages = {} meep_example_app.meeplib._user_ids = {} meep_example_app.initialize() app = meep_example_app.MeepExampleApp() self.app = app cur.execute("INSERT INTO SESSION(ID, USER_ID) VALUES('studentx',%d)" % (meep_example_app.meeplib.get_user('studentx').id)) con.commit()
def test_06_delete_test_user(self): #this isn't actually a test. it's simply to clean up after ourselves. e = {} e['REQUEST_METHOD'] = 'GET' e['SCRIPT_NAME'] = '' e['QUERY_STRING'] = '' e['CONTENT_TYPE'] = 'text/plain' e['CONTENT_LENGTH'] = '0' e['SERVER_NAME'] = 'localhost' e['SERVER_PORT'] = '8000' e['SERVER_PROTOCOL'] = 'HTTP/1.1' e['HTTP_COOKIE'] = "username=twillTester" app = meep_example_app.MeepExampleApp() def fake_start_response(status, headers): pass app.delete_loggedin_user_action(e, fake_start_response)
def process_Request(): global e, outputStatus, outputHeaders app = meep_example_app.MeepExampleApp() print 'processing' data = app(e, fake_start_response) output = [] output.append('%s %s\r\n' % (e['SERVER_PROTOCOL'], outputStatus)) output.append('Date: %s EST\r\n' % datetime.datetime.now().strftime("%a, %d %b %Y %I:%M:%S")) output.append('Server: HaydensAwesomeServer/0.1 Python/2.5\r\n') for h in outputHeaders: output.append(h[0] + ': ' + h[1] + '\r\n') if len(data) > 0: output.append('Content-Length: %d\r\n\r\n' % (len(data[0]), )) output.append(data[0]) else: output.append('Content-Length: 0\r\n\r\n') return ''.join(output)
def _process_request(self): app = meep_example_app.MeepExampleApp() print 'processing' response_fn_callable = ResponseFunctionHolder() data = app(self.e, response_fn_callable) output = [] output.append('%s %s\r\n' % (self.e['SERVER_PROTOCOL'], response_fn_callable.status)) output.append( 'Date: %s EST\r\n' % datetime.datetime.now().strftime("%a, %d %b %Y %I:%M:%S")) output.append('Server: HaydensAwesomeServer/0.1 Python/2.7\r\n') for h in response_fn_callable.headers: output.append(h[0] + ': ' + h[1] + '\r\n') if len(data) > 0: output.append('Content-Length: %d\r\n\r\n' % (len(data[0]), )) output.append(data[0]) else: output.append('Content-Length: 0\r\n\r\n') return ''.join(output)
import cgi, meep_example_app, time, meepcookie, sys, socket, StringIO, urllib
def setUp(self): app = meep_example_app.MeepExampleApp() self.app = app self.setDefaults()
def setUp(self): meep_example_app.initialize() app = meep_example_app.MeepExampleApp() self.app = app
def format_return(data): weekdays = {0: 'Sun', 1: 'Mon', 2: 'Tue', 3: 'Wed', 4: 'Thu', 5: 'Fri', 6: 'Sat' } months = {1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr', 5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec' } #filename = '1-request.txt' #fp = open(filename, 'rb') #text = fp.read() #text = data; list = data.split('\r\n') value = ''; thing =[] app = meep_example_app.MeepExampleApp() environ = {} hold = str(list[0]).split(' ') if hold != '': value += ('HTTP/1.0' + ' ') environ['REQUEST_METHOD'] = hold[0] environ['PATH_INFO'] = hold[1] environ['SERVER_PROTOCOL'] = hold[2] for x in list: pair = str(x).split(": ") if pair[0] == 'Host': #print pair[1] environ['SCRIPT_NAME'] = pair[1] environ["wsgi.version"] = (1,1) if(hold[0] == "POST"): print list vars = list[-1].split('&') s = [] print vars for x in vars: values = x.split('=') print values s.append({values[0]: values[1]}) for x in s: print x #filename = 'wsgiinput.txt' #fp = open(filename, 'wb') #fp.write(s); #fp.close() #fp = open(filename, 'rb') output = StringIO.StringIO(list[-1]); #output.write(s) environ["wsgi.input"] = output def fake_start_response(status, headers): thing.append(status) thing.append(headers[0]) html = app(environ, fake_start_response) value += thing[0] + '\r\n' date = time.localtime() value += ("Date: ") value += (weekdays[date[6]]) value += (', ') value += (str(date[2])) value += (' ') value += (months[date[1]]) value += (' ') value += (str(date[0])) value += (' ') value += (str(date[3])) value += (':') value += (str(date[4])) value += (':') value += (str(date[5])) value += (" GMT\r\n") value += 'Server: WSGIServer/0.1 Python/2.5\r\n' value += str(thing[1][0]) + ': ' + str(thing[1][1]) + '\r\n' value += 'Content Length: ' realhtml = '' for x in html: realhtml += x value += str(realhtml.__len__()) + '\r\n' value += '\r\n' + realhtml + '\r\n' filename = 'WebpageRequest.txt' fp = open(filename, 'wb') fp.write(data) fp.close() return value
self._parse_other(h,'CONTENT_LENGTH') else: self._parse_http_header(h) if len(sections) > 1 and self.e['REQUEST_METHOD'] == 'POST': post = sections[1] print 'POST DATA: %s' % post content_type, body = self._encode_multipart_formdata(post) self.e['CONTENT_TYPE'] = content_type self.e['wsgi.input'] = StringIO(body) return self._process_request() def _process_request(self): app = meep_example_app.MeepExampleApp() print 'processing' response_fn_callable = ResponseFunctionHolder() data = app(self.e, response_fn_callable) output = [] output.append('%s %s\r\n' % (self.e['SERVER_PROTOCOL'], response_fn_callable.status)) output.append('Date: %s EST\r\n' % datetime.datetime.now().strftime("%a, %d %b %Y %I:%M:%S")) output.append('Server: HaydensAwesomeServer/0.1 Python/2.7\r\n') for h in response_fn_callable.headers: output.append(h[0] + ': ' + h[1] + '\r\n') if len(data) > 0: output.append('Content-Length: %d\r\n\r\n' % (len(data[0]),)) output.append(data[0]) else: output.append('Content-Length: 0\r\n\r\n')
def setUp(self): meep_example_app.initialize() app = meep_example_app.MeepExampleApp() self.app = app meep_example_app.meeplib.delete_curr_user()