Skip to content

Commit

Permalink
Merge pull request go-macaroon-bakery#96 from cjwatson/py312
Browse files Browse the repository at this point in the history
Fix tests on Python 3.12
  • Loading branch information
fabricematrat authored Dec 13, 2023
2 parents f37ca72 + 674d2a8 commit 972e401
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 55 deletions.
40 changes: 20 additions & 20 deletions macaroonbakery/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def handler(*args):
srv_macaroon = b.oven.macaroon(
version=bakery.LATEST_VERSION, expiry=AGES,
caveats=None, ops=[TEST_OP])
self.assertEquals(srv_macaroon.macaroon.location, 'loc')
self.assertEqual(srv_macaroon.macaroon.location, 'loc')
client = httpbakery.Client()
client.cookies.set_cookie(requests.cookies.create_cookie(
'macaroon-test', base64.b64encode(json.dumps([
Expand All @@ -63,7 +63,7 @@ def handler(*args):
str(httpd.server_address[1]),
cookies=client.cookies, auth=client.auth())
resp.raise_for_status()
self.assertEquals(resp.text, 'done')
self.assertEqual(resp.text, 'done')
finally:
httpd.shutdown()

Expand Down Expand Up @@ -110,7 +110,7 @@ def handler(*args):
cookies=client.cookies,
auth=client.auth())
resp.raise_for_status()
self.assertEquals(resp.text, 'done')
self.assertEqual(resp.text, 'done')
finally:
httpd.shutdown()

Expand Down Expand Up @@ -157,7 +157,7 @@ def handler(*args):
cookies=client.cookies,
auth=client.auth())
resp.raise_for_status()
self.assertEquals(resp.text, 'done')
self.assertEqual(resp.text, 'done')
finally:
httpd.shutdown()

Expand Down Expand Up @@ -203,7 +203,7 @@ def handler(*args):
cookies=client.cookies,
auth=client.auth())
resp.raise_for_status()
self.assertEquals(resp.text, 'done')
self.assertEqual(resp.text, 'done')
finally:
httpd.shutdown()

Expand All @@ -222,7 +222,7 @@ def handler(*args):
srv_macaroon = b.oven.macaroon(
version=bakery.LATEST_VERSION, expiry=AGES,
caveats=None, ops=[TEST_OP])
self.assertEquals(srv_macaroon.macaroon.location, 'loc')
self.assertEqual(srv_macaroon.macaroon.location, 'loc')
client = httpbakery.Client()
# Note: by using "localhost" instead of the presumably numeric address held
# in httpd.server_address, we're triggering the no-FQDN logic in the cookie
Expand All @@ -231,7 +231,7 @@ def handler(*args):
url='http://localhost:' + str(httpd.server_address[1]),
cookies=client.cookies, auth=client.auth())
resp.raise_for_status()
self.assertEquals(resp.text, 'done')
self.assertEqual(resp.text, 'done')
except httpbakery.BakeryException:
pass # interacion required exception is expected
finally:
Expand All @@ -254,7 +254,7 @@ def handler(*args):
srv_macaroon = b.oven.macaroon(
version=bakery.LATEST_VERSION,
expiry=AGES, caveats=None, ops=[TEST_OP])
self.assertEquals(srv_macaroon.macaroon.location, 'loc')
self.assertEqual(srv_macaroon.macaroon.location, 'loc')
headers = {
'Macaroons': base64.b64encode(json.dumps([
srv_macaroon.to_dict().get('m')
Expand All @@ -265,7 +265,7 @@ def handler(*args):
str(httpd.server_address[1]),
headers=headers)
resp.raise_for_status()
self.assertEquals(resp.text, 'done')
self.assertEqual(resp.text, 'done')
finally:
httpd.shutdown()

Expand Down Expand Up @@ -317,8 +317,8 @@ def handler(*args):
base64.b64decode(client.cookies.get('macaroon-test')).decode('utf-8'))[0])
t = checkers.macaroons_expiry_time(
checkers.Namespace(), [m.macaroon])
self.assertEquals(ages, t)
self.assertEquals(resp.text, 'done')
self.assertEqual(ages, t)
self.assertEqual(resp.text, 'done')
finally:
httpd.shutdown()

Expand Down Expand Up @@ -557,13 +557,13 @@ def handler(*args):
cookies=client.cookies,
auth=client.auth())
if platform.python_version_tuple()[0] == '2':
self.assertEquals(str(discharge_error.exception),
'third party refused dischargex: unexpected response: '
"[503] 'bad system'")
self.assertEqual(str(discharge_error.exception),
'third party refused dischargex: unexpected response: '
"[503] 'bad system'")
else:
self.assertEquals(str(discharge_error.exception),
'third party refused dischargex: unexpected response: '
"[503] b'bad system'")
self.assertEqual(str(discharge_error.exception),
'third party refused dischargex: unexpected response: '
"[503] b'bad system'")

finally:
httpd.shutdown()
Expand Down Expand Up @@ -591,10 +591,10 @@ def encode_macaroon(m):
jar.add_cookie_header(req)

macaroons = httpbakery.extract_macaroons(req)
self.assertEquals(len(macaroons), 2)
self.assertEqual(len(macaroons), 2)
macaroons.sort(key=lambda ms: ms[0].identifier)
self.assertEquals(macaroons[0][0].identifier, m1.identifier)
self.assertEquals(macaroons[1][0].identifier, m2.identifier)
self.assertEqual(macaroons[0][0].identifier, m1.identifier)
self.assertEqual(macaroons[1][0].identifier, m2.identifier)

def test_handle_error_cookie_path(self):
macaroon = bakery.Macaroon(
Expand Down
16 changes: 8 additions & 8 deletions macaroonbakery/tests/test_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_v1_round_trip(self):
self.fp_key,
None)
res = bakery.decode_caveat(self.tp_key, cid)
self.assertEquals(res, bakery.ThirdPartyCaveatInfo(
self.assertEqual(res, bakery.ThirdPartyCaveatInfo(
first_party_public_key=self.fp_key.public_key,
root_key=b'a random string',
condition='is-authenticated-user',
Expand All @@ -48,7 +48,7 @@ def test_v2_round_trip(self):
self.fp_key,
None)
res = bakery.decode_caveat(self.tp_key, cid)
self.assertEquals(res, bakery.ThirdPartyCaveatInfo(
self.assertEqual(res, bakery.ThirdPartyCaveatInfo(
first_party_public_key=self.fp_key.public_key,
root_key=b'a random string',
condition='is-authenticated-user',
Expand All @@ -72,7 +72,7 @@ def test_v3_round_trip(self):
self.fp_key,
ns)
res = bakery.decode_caveat(self.tp_key, cid)
self.assertEquals(res, bakery.ThirdPartyCaveatInfo(
self.assertEqual(res, bakery.ThirdPartyCaveatInfo(
first_party_public_key=self.fp_key.public_key,
root_key=b'a random string',
condition='is-authenticated-user',
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_decode_caveat_v1_from_go(self):
'0V2lEOHhRUWdjU3ljOHY4eUt4dEhxejVEczJOYmh1ZDJhUFdt'
'UTVMcVlNWitmZ2FNaTAxdE9DIn0=')
cav = bakery.decode_caveat(tp_key, encrypted_cav)
self.assertEquals(cav, bakery.ThirdPartyCaveatInfo(
self.assertEqual(cav, bakery.ThirdPartyCaveatInfo(
condition='caveat condition',
first_party_public_key=fp_key.public_key,
third_party_key_pair=tp_key,
Expand Down Expand Up @@ -164,7 +164,7 @@ def test_decode_caveat_v3_from_go(self):
'1LX4VKxymqG62UGPo78wOv0_fKjr3OI6PPJOYOQgBMclemlRF2',
)
cav = bakery.decode_caveat(tp_key, encrypted_cav)
self.assertEquals(cav, bakery.ThirdPartyCaveatInfo(
self.assertEqual(cav, bakery.ThirdPartyCaveatInfo(
condition='third party condition',
first_party_public_key=fp_key.public_key,
third_party_key_pair=tp_key,
Expand All @@ -190,7 +190,7 @@ def test_encode_decode_varint(self):
bakery.encode_uvarint(test[0], data)
for v in test[1]:
expected.append(v)
self.assertEquals(data, expected)
self.assertEqual(data, expected)
val = codec.decode_uvarint(bytes(data))
self.assertEquals(test[0], val[0])
self.assertEquals(len(test[1]), val[1])
self.assertEqual(test[0], val[0])
self.assertEqual(len(test[1]), val[1])
10 changes: 5 additions & 5 deletions macaroonbakery/tests/test_macaroon.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ def test_new_macaroon(self):
'here',
bakery.LATEST_VERSION)
self.assertIsNotNone(m)
self.assertEquals(m._macaroon.identifier, b'some id')
self.assertEquals(m._macaroon.location, 'here')
self.assertEquals(m.version, bakery.LATEST_VERSION)
self.assertEqual(m._macaroon.identifier, b'some id')
self.assertEqual(m._macaroon.location, 'here')
self.assertEqual(m.version, bakery.LATEST_VERSION)

def test_add_first_party_caveat(self):
m = bakery.Macaroon('rootkey', 'some id', 'here',
bakery.LATEST_VERSION)
m.add_caveat(checkers.Caveat('test_condition'))
caveats = m.first_party_caveats()
self.assertEquals(len(caveats), 1)
self.assertEquals(caveats[0].caveat_id, b'test_condition')
self.assertEqual(len(caveats), 1)
self.assertEqual(caveats[0].caveat_id, b'test_condition')

def test_add_third_party_caveat(self):
locator = bakery.ThirdPartyStore()
Expand Down
12 changes: 6 additions & 6 deletions macaroonbakery/tests/test_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ def test_serialize(self):
for test in tests:
ns = checkers.Namespace(test[1])
data = ns.serialize_text()
self.assertEquals(data, test[2])
self.assertEquals(str(ns), test[2].decode('utf-8'))
self.assertEqual(data, test[2])
self.assertEqual(str(ns), test[2].decode('utf-8'))

# Check that it can be deserialize to the same thing:
ns1 = checkers.deserialize_namespace(data)
self.assertEquals(ns1, ns)
self.assertEqual(ns1, ns)

# TODO(rogpeppe) add resolve tests

def test_register(self):
ns = checkers.Namespace(None)
ns.register('testns', 't')
prefix = ns.resolve('testns')
self.assertEquals(prefix, 't')
self.assertEqual(prefix, 't')

ns.register('other', 'o')
prefix = ns.resolve('other')
self.assertEquals(prefix, 'o')
self.assertEqual(prefix, 'o')

# If we re-register the same URL, it does nothing.
ns.register('other', 'p')
prefix = ns.resolve('other')
self.assertEquals(prefix, 'o')
self.assertEqual(prefix, 'o')

def test_register_bad_uri(self):
ns = checkers.Namespace(None)
Expand Down
28 changes: 14 additions & 14 deletions macaroonbakery/tests/test_oven.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def test_canonical_ops(self):
for about, ops, expected in canonical_ops_tests:
new_ops = copy.copy(ops)
canonical_ops = bakery.canonical_ops(new_ops)
self.assertEquals(canonical_ops, expected)
self.assertEqual(canonical_ops, expected)
# Verify that the original array isn't changed.
self.assertEquals(new_ops, ops)
self.assertEqual(new_ops, ops)

def test_multiple_ops(self):
test_oven = bakery.Oven(
Expand All @@ -58,8 +58,8 @@ def test_multiple_ops(self):
m = test_oven.macaroon(bakery.LATEST_VERSION, AGES,
None, ops)
got_ops, conds = test_oven.macaroon_ops([m.macaroon])
self.assertEquals(len(conds), 1) # time-before caveat.
self.assertEquals(bakery.canonical_ops(got_ops), ops)
self.assertEqual(len(conds), 1) # time-before caveat.
self.assertEqual(bakery.canonical_ops(got_ops), ops)

def test_multiple_ops_in_id(self):
test_oven = bakery.Oven()
Expand All @@ -69,8 +69,8 @@ def test_multiple_ops_in_id(self):
m = test_oven.macaroon(bakery.LATEST_VERSION, AGES,
None, ops)
got_ops, conds = test_oven.macaroon_ops([m.macaroon])
self.assertEquals(len(conds), 1) # time-before caveat.
self.assertEquals(bakery.canonical_ops(got_ops), ops)
self.assertEqual(len(conds), 1) # time-before caveat.
self.assertEqual(bakery.canonical_ops(got_ops), ops)

def test_multiple_ops_in_id_with_version1(self):
test_oven = bakery.Oven()
Expand All @@ -79,8 +79,8 @@ def test_multiple_ops_in_id_with_version1(self):
bakery.Op('two', 'read')]
m = test_oven.macaroon(bakery.VERSION_1, AGES, None, ops)
got_ops, conds = test_oven.macaroon_ops([m.macaroon])
self.assertEquals(len(conds), 1) # time-before caveat.
self.assertEquals(bakery.canonical_ops(got_ops), ops)
self.assertEqual(len(conds), 1) # time-before caveat.
self.assertEqual(bakery.canonical_ops(got_ops), ops)

def test_huge_number_of_ops_gives_small_macaroon(self):
test_oven = bakery.Oven(
Expand All @@ -93,9 +93,9 @@ def test_huge_number_of_ops_gives_small_macaroon(self):
m = test_oven.macaroon(bakery.LATEST_VERSION, AGES,
None, ops)
got_ops, conds = test_oven.macaroon_ops([m.macaroon])
self.assertEquals(len(conds), 1) # time-before caveat.
self.assertEquals(bakery.canonical_ops(got_ops),
bakery.canonical_ops(ops))
self.assertEqual(len(conds), 1) # time-before caveat.
self.assertEqual(bakery.canonical_ops(got_ops),
bakery.canonical_ops(ops))

data = m.serialize_json()
self.assertLess(len(data), 300)
Expand All @@ -111,8 +111,8 @@ def test_ops_stored_only_once(self):
m = test_oven.macaroon(bakery.LATEST_VERSION, AGES,
None, ops)
got_ops, conds = test_oven.macaroon_ops([m.macaroon])
self.assertEquals(bakery.canonical_ops(got_ops),
bakery.canonical_ops(ops))
self.assertEqual(bakery.canonical_ops(got_ops),
bakery.canonical_ops(ops))

# Make another macaroon containing the same ops in a different order.
ops = [bakery.Op('one', 'write'),
Expand All @@ -121,4 +121,4 @@ def test_ops_stored_only_once(self):
bakery.Op('two', 'read')]
test_oven.macaroon(bakery.LATEST_VERSION, AGES, None,
ops)
self.assertEquals(len(st._store), 1)
self.assertEqual(len(st._store), 1)
5 changes: 3 additions & 2 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mock==1.0.1
nose2==0.13.0
pbr==3.1.1
python-mimeparse==1.6.0
testtools==2.3.0
testtools==2.3.0; python_version<"3"
testtools==2.5.0; python_version>="3"
traceback2==1.4.0
unittest2==1.1.0
unittest2==1.1.0; python_version<"3"

0 comments on commit 972e401

Please sign in to comment.