From 804f489b51d0e793ad12791a2883b752b77c2f83 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Fri, 3 Aug 2018 11:35:10 +0100 Subject: [PATCH 1/4] bump requirements --- .gitignore | 1 + requirements-app.txt | 8 ++++---- requirements.txt | 12 ++++++------ requirements_for_test.txt | 8 ++++---- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index e4f8ff58e..191965988 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ __pycache__/ *.py[cod] venv/ +venv-freeze/ # C extensions *.so diff --git a/requirements-app.txt b/requirements-app.txt index 613e31c88..addb6fb16 100644 --- a/requirements-app.txt +++ b/requirements-app.txt @@ -5,7 +5,7 @@ cffi==1.11.5 celery==3.1.26.post2 # pyup: <4 docopt==0.6.2 Flask-Bcrypt==0.7.1 -flask-marshmallow==0.8.0 +flask-marshmallow==0.9.0 Flask-Migrate==2.2.1 Flask-SQLAlchemy==2.3.2 Flask==1.0.2 @@ -15,12 +15,12 @@ gunicorn==19.7.1 iso8601==0.1.12 jsonschema==2.6.0 marshmallow-sqlalchemy==0.14.0 -marshmallow==2.15.3 +marshmallow==2.15.4 psycopg2-binary==2.7.5 PyJWT==1.6.4 -SQLAlchemy==1.2.9 +SQLAlchemy==1.2.10 -notifications-python-client==4.8.2 +notifications-python-client==5.0.0 # PaaS awscli-cwlogs>=1.4,<1.5 diff --git a/requirements.txt b/requirements.txt index 61a7ff250..68bcf7bf9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ cffi==1.11.5 celery==3.1.26.post2 # pyup: <4 docopt==0.6.2 Flask-Bcrypt==0.7.1 -flask-marshmallow==0.8.0 +flask-marshmallow==0.9.0 Flask-Migrate==2.2.1 Flask-SQLAlchemy==2.3.2 Flask==1.0.2 @@ -17,12 +17,12 @@ gunicorn==19.7.1 iso8601==0.1.12 jsonschema==2.6.0 marshmallow-sqlalchemy==0.14.0 -marshmallow==2.15.3 +marshmallow==2.15.4 psycopg2-binary==2.7.5 PyJWT==1.6.4 -SQLAlchemy==1.2.9 +SQLAlchemy==1.2.10 -notifications-python-client==4.8.2 +notifications-python-client==5.0.0 # PaaS awscli-cwlogs>=1.4,<1.5 @@ -35,12 +35,12 @@ git+https://github.com/alphagov/boto.git@2.43.0-patch3#egg=boto==2.43.0-patch3 alembic==1.0.0 amqp==1.4.9 anyjson==0.3.3 -awscli==1.15.70 +awscli==1.15.74 bcrypt==3.1.4 billiard==3.3.0.23 bleach==2.1.3 boto3==1.6.16 -botocore==1.10.69 +botocore==1.10.73 certifi==2018.4.16 chardet==3.0.4 click==6.7 diff --git a/requirements_for_test.txt b/requirements_for_test.txt index b26445b34..1555e3d64 100644 --- a/requirements_for_test.txt +++ b/requirements_for_test.txt @@ -1,14 +1,14 @@ -r requirements.txt flake8==3.5.0 moto==1.3.3 -pytest==3.6.3 +pytest==3.7.1 pytest-env==0.6.2 pytest-mock==1.10.0 pytest-cov==2.5.1 -pytest-xdist==1.22.2 +pytest-xdist==1.22.5 coveralls==1.3.0 freezegun==0.3.10 -requests-mock==1.5.0 +requests-mock==1.5.2 # optional requirements for jsonschema strict-rfc3339==0.7 -rfc3987==1.3.7 +rfc3987==1.3.8 From 62d70dbd4d59f6d67d26155241911c5a65b29998 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Wed, 8 Aug 2018 17:01:32 +0100 Subject: [PATCH 2/4] use contextmanager freeze time instead of decorator it doesn't appear to work nicely with pytest fixtures in the newer versions of pytest --- tests/app/letters/test_letter_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/app/letters/test_letter_utils.py b/tests/app/letters/test_letter_utils.py index 8d5f5017c..2430c57cf 100644 --- a/tests/app/letters/test_letter_utils.py +++ b/tests/app/letters/test_letter_utils.py @@ -21,13 +21,13 @@ FROZEN_DATE_TIME = "2018-03-14 17:00:00" @pytest.fixture() -@freeze_time(FROZEN_DATE_TIME) def sample_precompiled_letter_notification_using_test_key(sample_letter_notification): sample_letter_notification.template.hidden = True sample_letter_notification.template.name = PRECOMPILED_TEMPLATE_NAME sample_letter_notification.key_type = KEY_TYPE_TEST sample_letter_notification.reference = 'foo' - sample_letter_notification.created_at = datetime.utcnow() + with freeze_time(FROZEN_DATE_TIME): + sample_letter_notification.created_at = datetime.utcnow() return sample_letter_notification From 1ff729e75f5ea7050dd88f67113015f7585cbda6 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Wed, 8 Aug 2018 17:21:16 +0100 Subject: [PATCH 3/4] read first file returned from s3 rather than looping through, just use `next`. We only expect to return one file, so this won't actually affect the code flow. If, for whatever reason, the file isn't on s3, whereas previously it would error when trying to return an uninstantiated variable, now it will raise a StopIteration --- app/letters/utils.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/letters/utils.py b/app/letters/utils.py index c14cc80d1..a293663c1 100644 --- a/app/letters/utils.py +++ b/app/letters/utils.py @@ -135,14 +135,15 @@ def get_letter_pdf(notification): s3 = boto3.resource('s3') bucket = s3.Bucket(bucket_name) - for item in bucket.objects.filter(Prefix=get_bucket_prefix_for_notification(notification, is_test_letter)): - obj = s3.Object( - bucket_name=bucket_name, - key=item.key - ) - file_content = obj.get()["Body"].read() + item = next(x for x in bucket.objects.filter( + Prefix=get_bucket_prefix_for_notification(notification, is_test_letter) + )) - return file_content + obj = s3.Object( + bucket_name=bucket_name, + key=item.key + ) + return obj.get()["Body"].read() def _move_s3_object(source_bucket, source_filename, target_bucket, target_filename): From ef447931fdc4d062c777591f3b49f44056a8ba48 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Thu, 9 Aug 2018 10:30:51 +0100 Subject: [PATCH 4/4] bump utils --- requirements-app.txt | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements-app.txt b/requirements-app.txt index addb6fb16..500f01f06 100644 --- a/requirements-app.txt +++ b/requirements-app.txt @@ -25,6 +25,6 @@ notifications-python-client==5.0.0 # PaaS awscli-cwlogs>=1.4,<1.5 -git+https://github.com/alphagov/notifications-utils.git@29.3.4#egg=notifications-utils==29.3.4 +git+https://github.com/alphagov/notifications-utils.git@29.3.5#egg=notifications-utils==29.3.5 git+https://github.com/alphagov/boto.git@2.43.0-patch3#egg=boto==2.43.0-patch3 diff --git a/requirements.txt b/requirements.txt index 68bcf7bf9..1d69a09bd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -27,7 +27,7 @@ notifications-python-client==5.0.0 # PaaS awscli-cwlogs>=1.4,<1.5 -git+https://github.com/alphagov/notifications-utils.git@29.3.4#egg=notifications-utils==29.3.4 +git+https://github.com/alphagov/notifications-utils.git@29.3.5#egg=notifications-utils==29.3.5 git+https://github.com/alphagov/boto.git@2.43.0-patch3#egg=boto==2.43.0-patch3