Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: update tox config and replace deprecated test functions #636

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/test-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ jobs:
- name: Install Dependencies
run: |
pip install virtualenv --upgrade
make install
make test-install
make install test-install

- name: Run the tests
run: make test-with-coverage
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/jwt/test_access_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
SyncGrant,
VoiceGrant,
VideoGrant,
ConversationsGrant,
TaskRouterGrant,
ChatGrant,
PlaybackGrant,
Expand Down Expand Up @@ -95,16 +94,18 @@ def test_identity(self):

def test_conversations_grant(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
scat.add_grant(ConversationsGrant(configuration_profile_sid='CP123'))
scat.add_grant(VoiceGrant(outgoing_application_sid='CP123'))

token = scat.to_jwt()
assert token is not None
decoded_token = AccessToken.from_jwt(token, 'secret')
self._validate_claims(decoded_token.payload)
assert 1 == len(decoded_token.payload['grants'])
assert {
'configuration_profile_sid': 'CP123'
} == decoded_token.payload['grants']['rtc']
'outgoing': {
'application_sid': 'CP123'
}
} == decoded_token.payload['grants']['voice']

def test_video_grant(self):
scat = AccessToken(ACCOUNT_SID, SIGNING_KEY_SID, 'secret')
Expand Down
11 changes: 5 additions & 6 deletions tests/unit/jwt/test_client_validation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unittest
import time
import unittest

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric import rsa
Expand All @@ -11,7 +11,6 @@
)

from twilio.http.validation_client import ValidationPayload
from twilio.jwt import Jwt
from twilio.jwt.validation import ClientValidationJwt


Expand Down Expand Up @@ -231,12 +230,12 @@ def test_jwt_payload(self):

jwt = ClientValidationJwt('AC123', 'SK123', 'CR123', 'secret', vp)

self.assertDictContainsSubset({
self.assertEqual(jwt.payload, {**jwt.payload, **{
'hrh': 'authorization;host',
'rqh': expected_hash,
'iss': 'SK123',
'sub': 'AC123',
}, jwt.payload)
}})
self.assertGreaterEqual(jwt.payload['exp'], time.time(), 'JWT exp is before now')
self.assertLessEqual(jwt.payload['exp'], time.time() + 301, 'JWT exp is after now + 5mins')
self.assertDictEqual({
Expand Down Expand Up @@ -268,12 +267,12 @@ def test_jwt_signing(self):
jwt = ClientValidationJwt('AC123', 'SK123', 'CR123', private_key, vp)
decoded = ClientValidationJwt.from_jwt(jwt.to_jwt(), public_key)

self.assertDictContainsSubset({
self.assertEqual(decoded.payload, {**decoded.payload, **{
'hrh': 'authorization;host',
'rqh': expected_hash,
'iss': 'SK123',
'sub': 'AC123',
}, decoded.payload)
}})
self.assertGreaterEqual(decoded.payload['exp'], time.time(), 'JWT exp is before now')
self.assertLessEqual(decoded.payload['exp'], time.time() + 501, 'JWT exp is after now + 5m')
self.assertDictEqual({
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/jwt/test_jwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ def test_encode_decode(self):
self.assertEqual(decoded_jwt.subject, 'hey')

self.assertEqual(decoded_jwt.headers, {'typ': 'JWT', 'alg': 'HS256'})
self.assertDictContainsSubset({
self.assertEqual(decoded_jwt.payload, {**decoded_jwt.payload, **{
'iss': 'issuer',
'sub': 'hey',
'sick': 'sick',
}, decoded_jwt.payload)
}})

def test_encode_decode_mismatched_algorithms(self):
jwt = DummyJwt('secret_key', 'issuer', algorithm='HS512', subject='hey', payload={'sick': 'sick'})
Expand Down
10 changes: 5 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[tox]
envlist = py3{6,7,8,9,10,11}, pypy
env_list = py3{6,7,8,9,10,11}, pypy
skip_missing_interpreters = true

[testenv]
deps= -r{toxinidir}/tests/requirements.txt
commands=
nosetests \
[]
deps = -r{tox_root}/tests/requirements.txt
commands =
pytest \
[]