From 24dd22145e80a6e1b504185beda31246daa25822 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 5 Jan 2020 11:24:13 -0800 Subject: [PATCH] Fix tests for Python3 --- tests/test_models.py | 5 +++-- tests/util.py | 14 ++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index ea83c3f..550c194 100755 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -2,10 +2,11 @@ import unittest import util +import uuid -MODEL_1_NAME = 'testModel' -MODEL_2_NAME = 'testModel-second' +MODEL_1_NAME = str(uuid.uuid4()) +MODEL_2_NAME = str(uuid.uuid4()) CSS = 'some random css' NEW_CSS = 'new random css' diff --git a/tests/util.py b/tests/util.py index 2a5c077..2074981 100644 --- a/tests/util.py +++ b/tests/util.py @@ -1,17 +1,14 @@ import json -import urllib2 - -API_VERSION = 6 -API_URL = 'http://localhost:8765' +import urllib.request def request(action, **params): - return {'action': action, 'params': params, 'version': API_VERSION} - + return {'action': action, 'params': params, 'version': 6} def invoke(action, **params): - requestJson = json.dumps(request(action, **params)) - response = json.load(urllib2.urlopen(urllib2.Request(API_URL, requestJson))) + requestJson = json.dumps(request(action, **params)).encode('utf-8') + response = json.load(urllib.request.urlopen(urllib.request.Request('http://localhost:8765', requestJson))) + if len(response) != 2: raise Exception('response has an unexpected number of fields') if 'error' not in response: @@ -20,4 +17,5 @@ def invoke(action, **params): raise Exception('response is missing required result field') if response['error'] is not None: raise Exception(response['error']) + return response['result']