Fix tests for Python3

This commit is contained in:
Alex Yatskov 2020-01-05 11:24:13 -08:00
parent 06c40ed85d
commit 24dd22145e
2 changed files with 9 additions and 10 deletions

View File

@ -2,10 +2,11 @@
import unittest import unittest
import util import util
import uuid
MODEL_1_NAME = 'testModel' MODEL_1_NAME = str(uuid.uuid4())
MODEL_2_NAME = 'testModel-second' MODEL_2_NAME = str(uuid.uuid4())
CSS = 'some random css' CSS = 'some random css'
NEW_CSS = 'new random css' NEW_CSS = 'new random css'

View File

@ -1,17 +1,14 @@
import json import json
import urllib2 import urllib.request
API_VERSION = 6
API_URL = 'http://localhost:8765'
def request(action, **params): def request(action, **params):
return {'action': action, 'params': params, 'version': API_VERSION} return {'action': action, 'params': params, 'version': 6}
def invoke(action, **params): def invoke(action, **params):
requestJson = json.dumps(request(action, **params)) requestJson = json.dumps(request(action, **params)).encode('utf-8')
response = json.load(urllib2.urlopen(urllib2.Request(API_URL, requestJson))) response = json.load(urllib.request.urlopen(urllib.request.Request('http://localhost:8765', requestJson)))
if len(response) != 2: if len(response) != 2:
raise Exception('response has an unexpected number of fields') raise Exception('response has an unexpected number of fields')
if 'error' not in response: if 'error' not in response:
@ -20,4 +17,5 @@ def invoke(action, **params):
raise Exception('response is missing required result field') raise Exception('response is missing required result field')
if response['error'] is not None: if response['error'] is not None:
raise Exception(response['error']) raise Exception(response['error'])
return response['result'] return response['result']