def test_failed_call(self): script = self.create_script(TEST_CGI_SCRIPT_FAIL) client = CGIClient(script) try: client.open('http://example.org/service?hello=bar') except HTTPClientError: pass else: assert False, 'expected HTTPClientError'
def test_script_not_executable(self): script = self.create_script(executable=False) client = CGIClient(script) try: client.open('http://example.org/service?hello=bar') except SourceError: pass else: assert False, 'expected SourceError'
def test_working_directory(self): tmp_work_dir = os.path.join(self.script_dir, 'tmp') os.mkdir(tmp_work_dir) tmp_file = os.path.join(tmp_work_dir, 'testfile') open(tmp_file, 'w') # start script in default directory script = self.create_script(TEST_CGI_SCRIPT_CWD) client = CGIClient(script) try: client.open('http://example.org/service?hello=bar') except HTTPClientError: pass else: assert False, 'expected HTTPClientError' # start in tmp_work_dir client = CGIClient(script, working_directory=tmp_work_dir) client.open('http://example.org/service?hello=bar')
def test_call(self): script = self.create_script() client = CGIClient(script) resp = client.open('http://example.org/service?hello=bar') eq_(resp.headers['Content-type'], 'text/plain') eq_(resp.read(), 'hello=bar')