Commit 9586f815 authored by Aurélien Bompard's avatar Aurélien Bompard Committed by Abhilash Raj

Fix tests

parent 6193e1dd
......@@ -7,12 +7,10 @@ python2.7:
python3.4:
script:
- tox -e py34
allow_failure: true
python3.5:
script:
- tox -e py35
allow_failure: true
lint:
script:
......
......@@ -60,24 +60,32 @@ class NosePlugin(Plugin):
self.addFlag(set_record, 'R', 'rerecord',
"""Force re-recording of test responses. Requires
Mailman to be running.""")
self._data_path = os.path.join(TOPDIR, 'tests', 'data', 'tape.yaml')
self._data_path = os.path.join(TOPDIR, 'tests', 'data')
self._resources = ExitStack()
self._recorder = get_vcr()
def startTestRun(self, event):
def startTest(self, event):
# Check to see if we're running the test suite in record mode. If so,
# delete any existing recording.
if isinstance(event.test, doctest.DocFileCase):
cassette_filename = event.test.id() + ".yaml"
else:
cassette_filename = ".".join([
event.test.__class__.__name__,
event.test._testMethodName,
'yaml'])
cassette_path = os.path.join(self._data_path, cassette_filename)
if self.record:
try:
os.remove(self._data_path)
os.remove(cassette_path)
except OSError as error:
if error.errno != errno.ENOENT:
raise
# This will automatically create the recording file.
self._resources.enter_context(
self._recorder.use_cassette(self._data_path))
self._recorder.use_cassette(cassette_path))
def stopTestRun(self, event):
def stopTest(self, event):
# Stop all recording.
self._resources.close()
......
......@@ -20,7 +20,7 @@
import vcr
from functools import update_wrapper
from six import binary_type, text_type
from six import binary_type, text_type, PY3
from six.moves.urllib.parse import urlparse, urlunparse, parse_qsl, urlencode
......@@ -39,7 +39,12 @@ def filter_response_headers(response):
def reorder_request_params(request):
def reorder_params(params):
parsed = parse_qsl(params)
if PY3:
if isinstance(params, binary_type):
params = params.decode("ascii")
parsed = parse_qsl(params, encoding="utf-8")
else:
parsed = parse_qsl(params)
if parsed:
return urlencode(sorted(parsed, key=lambda kv: kv[0]))
else:
......
interactions:
- request:
body: null
headers:
accept-encoding: ['gzip, deflate']
method: !!python/unicode 'GET'
uri: http://localhost:9001/3.0/domains/example.org
response:
body: {string: !!python/unicode '404 Not Found'}
headers:
content-length: ['13']
content-type: [application/json; charset=UTF-8]
status: {code: 404, message: Not Found}
version: 1
interactions:
- request:
body: !!python/unicode 'display_name=J%C3%A9r%C3%B4me&email=jeremy%40example.com&password=1234'
headers:
accept-encoding: ['gzip, deflate']
!!python/unicode 'content-type': [!!python/unicode 'application/x-www-form-urlencoded']
method: !!python/unicode 'POST'
uri: http://localhost:9001/3.1/users
response:
body: {string: !!python/unicode ''}
headers:
content-length: ['0']
content-type: [application/json; charset=UTF-8]
location: ['http://localhost:9001/3.1/users/0000000000000000000000000000000d']
status: {code: 201, message: Created}
- request:
body: null
headers:
accept-encoding: ['gzip, deflate']
method: !!python/unicode 'GET'
uri: http://localhost:9001/3.1/users/0000000000000000000000000000000d
response:
body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "display_name":
"J\u00e9r\u00f4me", "http_etag": "\"d78f048ae1392154b9563088e8f784ef26e5be62\"",
"is_server_owner": false, "password": "$6$rounds=656000$OnXXy2o/Ekoi2lAu$F4C.1ma.fdl9ovvmkjWloLrdn4z2.Z47vV1wvcBQK008zDXw0Dyl2Gp2GH3qQmCAuuY7MC5qmnkPR9vKE2j.u/",
"self_link": "http://localhost:9001/3.1/users/0000000000000000000000000000000d",
"user_id": "0000000000000000000000000000000d"}'}
headers:
content-length: ['424']
content-type: [application/json; charset=UTF-8]
status: {code: 200, message: OK}
- request:
body: null
headers:
accept-encoding: ['gzip, deflate']
method: !!python/unicode 'GET'
uri: http://localhost:9001/3.1/users/jeremy@example.com
response:
body: {string: !!python/unicode '{"created_on": "2005-08-01T07:49:23", "display_name":
"J\u00e9r\u00f4me", "http_etag": "\"d78f048ae1392154b9563088e8f784ef26e5be62\"",
"is_server_owner": false, "password": "$6$rounds=656000$OnXXy2o/Ekoi2lAu$F4C.1ma.fdl9ovvmkjWloLrdn4z2.Z47vV1wvcBQK008zDXw0Dyl2Gp2GH3qQmCAuuY7MC5qmnkPR9vKE2j.u/",
"self_link": "http://localhost:9001/3.1/users/0000000000000000000000000000000d",
"user_id": "0000000000000000000000000000000d"}'}
headers:
content-length: ['424']
content-type: [application/json; charset=UTF-8]
status: {code: 200, message: OK}
- request:
body: null
headers:
accept-encoding: ['gzip, deflate']
method: !!python/unicode 'DELETE'
uri: http://localhost:9001/3.1/users/0000000000000000000000000000000d
response:
body: {string: !!python/unicode ''}
headers:
content-length: ['0']
status: {code: 204, message: No Content}
version: 1
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -21,19 +21,18 @@
from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
'TestUnicode',
]
import sys
import unittest
from mailmanclient import Client
from six.moves.urllib_error import HTTPError
@unittest.skipIf(sys.version_info.major == 3, "Expected failure on Py3.")
__metaclass__ = type
__all__ = [
'TestUnicode',
]
class TestUnicode(unittest.TestCase):
def setUp(self):
self._client = Client(
......
......@@ -17,6 +17,7 @@ commands = python -m nose2 -v -R
[testenv:lint]
deps =
six
flake8 > 3.0
commands =
python -m flake8 {posargs}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment