Merge pull request #2776 from bblommers/python-2-readyness

Python 2 dependencies + Test fix
This commit is contained in:
Steve Pulec 2020-03-05 12:58:27 -06:00 committed by GitHub
commit 9024031ca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 11 deletions

View File

@ -1,5 +1,5 @@
-r requirements.txt -r requirements.txt
mock mock==3.0.5 # Last version compatible with Python 2.7
nose nose
black; python_version >= '3.6' black; python_version >= '3.6'
regex==2019.11.1; python_version >= '3.6' # Needed for black regex==2019.11.1; python_version >= '3.6' # Needed for black

View File

@ -1,20 +1,20 @@
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import unicode_literals from __future__ import unicode_literals
import codecs import codecs
from io import open
import os import os
import re import re
import setuptools import setuptools
from setuptools import setup, find_packages from setuptools import setup, find_packages
import sys import sys
# Borrowed from pip at https://github.com/pypa/pip/blob/62c27dee45625e1b63d1e023b0656310f276e050/setup.py#L11-L15 # Borrowed from pip at https://github.com/pypa/pip/blob/62c27dee45625e1b63d1e023b0656310f276e050/setup.py#L11-L15
here = os.path.abspath(os.path.dirname(__file__)) here = os.path.abspath(os.path.dirname(__file__))
def read(*parts): def read(*parts):
# intentionally *not* adding an encoding option to open, See: # intentionally *not* adding an encoding option to open, See:
# https://github.com/pypa/virtualenv/issues/201#issuecomment-3145690 # https://github.com/pypa/virtualenv/issues/201#issuecomment-3145690
with codecs.open(os.path.join(here, *parts), 'r') as fp: with open(os.path.join(here, *parts), 'r') as fp:
return fp.read() return fp.read()
@ -28,7 +28,8 @@ def get_version():
install_requires = [ install_requires = [
"Jinja2>=2.10.1", "setuptools==44.0.0",
"Jinja2==2.11.0",
"boto>=2.36.0", "boto>=2.36.0",
"boto3>=1.9.201", "boto3>=1.9.201",
"botocore>=1.12.201", "botocore>=1.12.201",
@ -41,14 +42,16 @@ install_requires = [
"pytz", "pytz",
"python-dateutil<3.0.0,>=2.1", "python-dateutil<3.0.0,>=2.1",
"python-jose<4.0.0", "python-jose<4.0.0",
"mock", "mock==3.0.5",
"docker>=2.5.1", "docker>=2.5.1",
"jsondiff>=1.1.2", "jsondiff>=1.1.2",
"aws-xray-sdk!=0.96,>=0.93", "aws-xray-sdk!=0.96,>=0.93",
"responses>=0.9.0", "responses>=0.9.0",
"idna<2.9,>=2.5", "idna<2.9,>=2.5",
"cfn-lint>=0.4.0", "cfn-lint>=0.4.0",
"sshpubkeys>=3.1.0,<4.0" "sshpubkeys>=3.1.0,<4.0",
"zipp==0.6.0",
"more-itertools==5.0.0"
] ]
extras_require = { extras_require = {

View File

@ -274,9 +274,7 @@ def test_access_denied_with_not_allowing_policy():
user_name = "test-user" user_name = "test-user"
inline_policy_document = { inline_policy_document = {
"Version": "2012-10-17", "Version": "2012-10-17",
"Statement": [ "Statement": [{"Effect": "Allow", "Action": ["ec2:Run*"], "Resource": "*"}],
{"Effect": "Allow", "Action": ["ec2:Describe*"], "Resource": "*"}
],
} }
access_key = create_user_with_access_key_and_inline_policy( access_key = create_user_with_access_key_and_inline_policy(
user_name, inline_policy_document user_name, inline_policy_document
@ -288,12 +286,14 @@ def test_access_denied_with_not_allowing_policy():
aws_secret_access_key=access_key["SecretAccessKey"], aws_secret_access_key=access_key["SecretAccessKey"],
) )
with assert_raises(ClientError) as ex: with assert_raises(ClientError) as ex:
client.run_instances(MaxCount=1, MinCount=1) client.describe_instances()
ex.exception.response["Error"]["Code"].should.equal("AccessDenied") ex.exception.response["Error"]["Code"].should.equal("AccessDenied")
ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403) ex.exception.response["ResponseMetadata"]["HTTPStatusCode"].should.equal(403)
ex.exception.response["Error"]["Message"].should.equal( ex.exception.response["Error"]["Message"].should.equal(
"User: arn:aws:iam::{account_id}:user/{user_name} is not authorized to perform: {operation}".format( "User: arn:aws:iam::{account_id}:user/{user_name} is not authorized to perform: {operation}".format(
account_id=ACCOUNT_ID, user_name=user_name, operation="ec2:RunInstances" account_id=ACCOUNT_ID,
user_name=user_name,
operation="ec2:DescribeInstances",
) )
) )