def setUp(self): self.gm = GameManager() self.gm.add_player('krol_julian', MockHandler()) self.gm.add_player('martarzy', MockHandler()) self.gm.add_player('the_bad', MockHandler()) self.p0 = self.gm.players[0] self.p1 = self.gm.players[1] self.p2 = self.gm.players[2]
def test_call_application(self): request = AbstractRequest.create(MockHandler(), dict(url='/')) meta = dict(ip='127.0.0.1', port=19234) environ, handler = Environ(request, meta), WSGIHandler(MockHandler()) json_response = handler.call_application(various_status_application, environ.get_dict()) self.assertEqual( dict(status=dict(reason='OK', code='200'), response=dict(), headers=dict()), json_response)
def test_no_json_response(self): request = AbstractRequest.create(MockHandler(), dict(url='/?404 NOT FOUND')) meta = dict(ip='127.0.0.1', port=19234) environ, handler = Environ(request, meta), WSGIHandler(MockHandler()) json_response = handler.call_application(no_json_response_application, environ.get_dict()) self.assertEqual( dict(status=dict(reason='NOT FOUND', code='404'), no_json_response='Page Not Found', response=dict(), headers=dict()), json_response)
def test_command_set_headers(self): request = AbstractRequest.create( MockHandler(), dict(url=':set-headers', headers=dict(foo='bar'))) self.assertEqual( request.command(), dict(status=dict(code='200', reason='OK'), headers=dict(foo='bar')))
def environ(request_parameters, meta=None): if not request_parameters: request_parameters = dict() if not meta: meta = dict() request = AbstractRequest.create(MockHandler(), request_parameters) return Environ(request, meta).get_dict()
def test_command_allow_headers(self): def get_application_response(request_handler): request = AbstractRequest.create(request_handler, dict(url='/')) meta = dict(ip='127.0.0.1', port=19234) environ = Environ(request, meta) wsgi_handler = WSGIHandler(request_handler) return wsgi_handler.call_application(various_status_application, environ.get_dict()) request_handler = MockHandler() headers = get_application_response(request_handler)['headers'] self.assertNotIn('Content-Type', headers) request = AbstractRequest.create( request_handler, dict(url=':allow-headers', names=['content-type'])) self.assertEqual(request.command(), dict(status=dict(code='200', reason='OK'))) self.assertIn('content-type', request_handler.allow_headers) headers = get_application_response(request_handler)['headers'] self.assertIn('Content-Type', headers)
def setUp(self): self.player = Player('julian', MockHandler()) self.player.state = self.player.buy_state
def setUp(self): self.player = Player('julian', MockHandler()) self.player.init_state()
def setUp(self): self.player = Player('julian', MockHandler())
def test_buy_house(self): self.player = Player('julian', MockHandler()) self.player.state = self.player.end_state self.assertTrue(self.player.update_state('buyHouse')) self.assertEqual(self.player.state, self.player.end_state)
def test_invalid_request(self): request = AbstractRequest.create(MockHandler(), dict(url='\x00')) self.assertIsInstance(request, InvalidRequest)
def test_http_header(self): request = {'url': '/', 'headers': dict(USER_AGENT='iPhone')} request = AbstractRequest.create(MockHandler(), request) self.assertEqual(request.headers['USER_AGENT'], 'iPhone')
def test_create(self): request = AbstractRequest.create(MockHandler(), dict(url='/', foo='bar')) self.assertIsInstance(request, WebRequest) self.assertEqual(request.url, '/') self.assertEqual(request.params, dict(foo='bar'))
def test_command_hello(self): request = AbstractRequest.create(MockHandler(), dict(url=':hello')) self.assertEqual(request.command(), dict(status=dict(code='200', reason='OK')))
def test_create(self): request = AbstractRequest.create(MockHandler(), dict(url=':init')) self.assertIsInstance(request, CommandRequest)