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

Update dependencies and Python version to 3.12 #1249

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
a549fc0
made updates to get tests passing on Python 3.11. Ran black on 3 files
jamesstottmoj Feb 14, 2024
bb03c5d
Merge branch 'main' into python-311-test
jamesstottmoj Feb 14, 2024
db39385
Fixed flaky test by checking attached role is in role name rather tha…
jamesstottmoj Feb 14, 2024
8ced4cd
Merge branch 'python-311-test' of github.com:ministryofjustice/analyt…
jamesstottmoj Feb 14, 2024
053e465
attempted to bump version to python 311 in dockerfile
jamesstottmoj Feb 15, 2024
4734bfd
bumped down requirements for kubernetes
jamesstottmoj Feb 15, 2024
05f84f3
added 3.11 image to Dockerfile
jamesstottmoj Feb 26, 2024
d1d87fa
Attempted to fix add user now we're using an alpine image
jamesstottmoj Feb 26, 2024
11136da
Further attempt to fix Dockerfile using apk command
jamesstottmoj Feb 26, 2024
0c6266d
replaced failing packages with what I think are their apk equivalents
jamesstottmoj Feb 26, 2024
6fc6de7
updated python3-dev to python3.11-dev
jamesstottmoj Feb 26, 2024
94cd951
reverted python-dev
jamesstottmoj Feb 26, 2024
4bf5e4d
added new image dependency
jamesstottmoj Feb 26, 2024
dcaa117
added another package in an attempt to fix stdio error
jamesstottmoj Feb 26, 2024
a72997a
removed warning
jamesstottmoj Feb 26, 2024
109a919
updated to test if file gets picked up
jamesstottmoj Feb 26, 2024
42220b3
added purposeful breaking change to see if it is picked up on test pi…
jamesstottmoj Feb 26, 2024
bef6250
removed breaking change as tests did not run
jamesstottmoj Feb 26, 2024
4dc5d05
added import on line 8 to check if it gets picked up
jamesstottmoj Feb 26, 2024
224e3fc
removed import
jamesstottmoj Feb 26, 2024
31d159f
adding new test to see if it's picked up
jamesstottmoj Feb 26, 2024
872983c
removing all tests from file as a test
jamesstottmoj Feb 26, 2024
a985206
adding tests back
jamesstottmoj Feb 26, 2024
510e087
Merge branch 'main' into python-311-test
jamesstottmoj Feb 26, 2024
33288d9
fixed merge conflicts
jamesstottmoj Feb 26, 2024
f6b2521
removed test
jamesstottmoj Feb 26, 2024
a319ad9
Merge branch 'main' into python-311-test
jamesstottmoj Feb 27, 2024
c27b801
Merge branch 'main' into python-311-test
jamesstottmoj Mar 12, 2024
86fd452
merge main into branch
jamesstottmoj Apr 4, 2024
880628f
bumped python version to 3.12. Bumped some dependencies to latest ver…
jamesstottmoj Apr 4, 2024
4b31610
attempt to fix tests
jamesstottmoj Apr 4, 2024
a3a6f5a
fixed tests that failed as a result of bumping to 3.12
jamesstottmoj Apr 4, 2024
d404b0b
updated to model-bakery
jamesstottmoj Apr 5, 2024
527d03e
moved model-bakery to requirements
jamesstottmoj Apr 5, 2024
7440b58
bumped model-bakery to latest version
jamesstottmoj Apr 5, 2024
d03f5e8
Merge branch 'main' into python-311-test
jamesstottmoj Apr 8, 2024
85c76f0
updated node package
jamesstottmoj Apr 8, 2024
f1f3afe
Merge branch 'python-311-test' of github.com:ministryofjustice/analyt…
jamesstottmoj Apr 8, 2024
14e09ba
Removed commented out tests. Updated running.md to specify python 3.12
jamesstottmoj Apr 9, 2024
0d28395
made updates to get tests passing on Python 3.11. Ran black on 3 files
jamesstottmoj Feb 14, 2024
7a44e27
attempted to bump version to python 311 in dockerfile
jamesstottmoj Feb 15, 2024
fd8c9f4
added 3.11 image to Dockerfile
jamesstottmoj Feb 26, 2024
ae5f964
Attempted to fix add user now we're using an alpine image
jamesstottmoj Feb 26, 2024
99a0d63
Further attempt to fix Dockerfile using apk command
jamesstottmoj Feb 26, 2024
a9bdac5
replaced failing packages with what I think are their apk equivalents
jamesstottmoj Feb 26, 2024
539bc44
updated python3-dev to python3.11-dev
jamesstottmoj Feb 26, 2024
668bd84
reverted python-dev
jamesstottmoj Feb 26, 2024
19ef268
added new image dependency
jamesstottmoj Feb 26, 2024
f4438fc
added another package in an attempt to fix stdio error
jamesstottmoj Feb 26, 2024
3b7ce7f
removed warning
jamesstottmoj Feb 26, 2024
7aaa6eb
updated to test if file gets picked up
jamesstottmoj Feb 26, 2024
7e81bbb
adding new test to see if it's picked up
jamesstottmoj Feb 26, 2024
b6189bd
fixed merge conflicts
jamesstottmoj Feb 26, 2024
e8c9f87
removed test
jamesstottmoj Feb 26, 2024
516edee
bumped python version to 3.12. Bumped some dependencies to latest ver…
jamesstottmoj Apr 4, 2024
5cb135f
attempt to fix tests
jamesstottmoj Apr 4, 2024
caa4a2c
fixed tests that failed as a result of bumping to 3.12
jamesstottmoj Apr 4, 2024
14f4ae9
updated to model-bakery
jamesstottmoj Apr 5, 2024
95fb48a
moved model-bakery to requirements
jamesstottmoj Apr 5, 2024
a69b978
updated node package
jamesstottmoj Apr 8, 2024
659ed79
Removed commented out tests. Updated running.md to specify python 3.12
jamesstottmoj Apr 9, 2024
0904be1
Merge branch 'python-311-test' of github.com:ministryofjustice/analyt…
jamesstottmoj Apr 9, 2024
34475c9
Resetting commit history - Python bumped to 3.12, dependencies bumped…
jamesstottmoj Apr 9, 2024
663f774
Merge branch 'python-311-test' of github.com:ministryofjustice/analyt…
jamesstottmoj Apr 9, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ __pycache__
/static
/tags
/venv
/venv_311
/.python-version
/coverage/
.idea/
Expand Down
18 changes: 10 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN ./node_modules/.bin/sass --load-path=node_modules/ --style=compressed src/ap
WORKDIR /src
RUN /node_modules/.bin/jest

FROM 593291632749.dkr.ecr.eu-west-1.amazonaws.com/python:3.9-slim-buster AS base
FROM public.ecr.aws/docker/library/python:3.11-alpine3.18 AS base

ARG HELM_VERSION=3.14.1
ARG HELM_TARBALL=helm-v${HELM_VERSION}-linux-amd64.tar.gz
Expand All @@ -22,18 +22,20 @@ ENV DJANGO_SETTINGS_MODULE="controlpanel.settings" \
HELM_DATA_HOME=/tmp/helm/data

# create a user to run as
RUN addgroup -gid 1000 controlpanel && \
adduser -uid 1000 --gid 1000 controlpanel
RUN addgroup -g 1000 controlpanel \
&& adduser -G controlpanel -u 1000 controlpanel -D

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
RUN apk update \
&& apk add --no-cache \
postgresql-client \
wget \
gcc \
libcurl4-gnutls-dev \
curl-dev \
python3-dev \
libgnutls28-dev \
libssl-dev \
gnutls-dev \
openssl-dev \
libffi-dev \
musl-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /home/controlpanel
Expand Down
50 changes: 25 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
black==23.3.0
django-debug-toolbar==3.2.4
black==24.2.0
django-debug-toolbar==4.3.0
django-debug-toolbar-requests==1.0.5
django-elasticsearch-debug-toolbar==2.0.0
flake8==6.0.0
django-elasticsearch-debug-toolbar==3.0.2
flake8==7.0.0
ipdb==0.13.13
ipython==8.13.2
isort==5.12.0
pre-commit==2.20.0
pylint==2.17.4
pylint-django==2.4.4
pandas==1.5.2
ipython==8.21.0
isort==5.13.2
pandas==2.2.0
pre-commit==3.6.1
pylint==3.0.3
pylint-django==2.5.5
38 changes: 19 additions & 19 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
asgiref==3.7.2
auth0-python==4.5.0
beautifulsoup4==4.12.2
boto3==1.26.143
celery[sqs]==5.3.1
auth0-python==4.7.0
beautifulsoup4==4.12.3
boto3==1.34.41
celery[sqs]==5.3.6
channels==4.0.0
channels-redis==4.2.0
daphne==4.0.0
Django==4.2.10
daphne==4.1.0
Django==5.0.2
django-crequest==2018.5.11
django-extensions==3.2.3
django-filter==22.1
django-filter==23.5
django-prometheus==2.3.1
django-redis==5.4.0
django-simple-history==3.3.0
django-structlog==2.2.0
django-simple-history==3.4.0
django-structlog==7.1.0
djangorestframework==3.14.0
djproxy==2.3.6
elasticsearch-dsl==7.4.1
gunicorn==20.1.0
gunicorn==21.2.0
Jinja2==3.1.3
kubernetes==25.3.0
MarkupSafe==2.1.3
MarkupSafe==2.1.5
model-mommy==2.0.0
moto==1.3.14
moto==5.0.1
mozilla-django-oidc==4.0.0
psycopg2-binary==2.9.6
psycopg2-binary==2.9.9
PyNaCl==1.5.0
pytest==7.3.1
pytest-django==4.5.2
python-dotenv==1.0.0
pytest==8.0.0
pytest-django==4.8.0
python-dotenv==1.0.1
python-jose==3.3.0
pyyaml==6.0.1
rules==3.3
sentry-sdk==1.14.0
sentry-sdk==1.40.4
slackclient==2.9.4
urllib3==1.26.18
uvicorn[standard]==0.20.0
urllib3==2.0.7
uvicorn[standard]==0.27.1
2 changes: 1 addition & 1 deletion tests/api/cluster/test_access_to_s3buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def grant_policy_bucket_access():
) as grant_policy_bucket_access_action:
yield grant_policy_bucket_access_action

@pytest.yield_fixture
@pytest.fixture
def grant_policy_folder_access():
with patch(
"controlpanel.api.cluster.AWSPolicy.grant_folder_access"
Expand Down
19 changes: 12 additions & 7 deletions tests/api/fixtures/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,31 @@ def aws_creds():

@pytest.fixture(autouse=True)
def iam(aws_creds):
with moto.mock_iam():
with moto.mock_aws():
yield boto3.Session().resource("iam")


@pytest.fixture(autouse=True)
def s3(aws_creds):
with moto.mock_s3():
with moto.mock_aws():
yield boto3.resource("s3")


@pytest.fixture(autouse=True)
def sts(aws_creds):
with moto.mock_sts():
with moto.mock_aws():
yield boto3.client("sts")


@pytest.fixture(autouse=True)
def ssm(aws_creds):
with moto.mock_ssm():
with moto.mock_aws():
yield boto3.client("ssm", region_name="eu-west-1")


@pytest.fixture(autouse=True)
def sqs(aws_creds):
with moto.mock_sqs():
with moto.mock_aws():
sqs = boto3.resource("sqs")
sqs.create_queue(QueueName=settings.DEFAULT_QUEUE)
sqs.create_queue(QueueName=settings.IAM_QUEUE_NAME)
Expand All @@ -53,7 +53,7 @@ def sqs(aws_creds):

@pytest.fixture(autouse=True)
def secretsmanager(aws_creds):
with moto.mock_secretsmanager():
with moto.mock_aws():
yield boto3.client("secretsmanager", region_name="eu-west-1")


Expand Down Expand Up @@ -161,4 +161,9 @@ def logs_bucket(s3):

@pytest.fixture()
def root_folder_bucket(s3):
yield s3.create_bucket(Bucket=settings.S3_FOLDER_BUCKET_NAME)
yield s3.create_bucket(
Bucket=settings.S3_FOLDER_BUCKET_NAME,
CreateBucketConfiguration={
"LocationConstraint": settings.BUCKET_REGION, # noqa: F405
},
)
19 changes: 8 additions & 11 deletions tests/api/test_auth0.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Standard library
import json
from unittest.mock import call, patch
from unittest.mock import call, patch, ANY

# Third-party
import mock
import pytest
from django.conf import settings
from auth0 import exceptions
Expand Down Expand Up @@ -511,9 +510,7 @@ def fixture_group_members_200(ExtendedAuth0):
yield


def test_group_member_more_than_100(
ExtendedAuth0, fixture_group_members_200
):
def test_group_member_more_than_100(ExtendedAuth0, fixture_group_members_200):
members = ExtendedAuth0.groups.get_group_members(group_id="foo-id-1")
assert len(members) == 200

Expand Down Expand Up @@ -585,7 +582,7 @@ def _clean_string(content):
"client_secret": "WNXFkM3FCTXJhUWs0Q1NwcKFu",
},
)
fixture_connection_create.assert_called_once_with(mock.ANY)
fixture_connection_create.assert_called_once_with(ANY)
with open("./tests/api/fixtures/nomis_body.json") as body_file:
expected = json.loads(body_file.read())

Expand All @@ -606,7 +603,8 @@ def _clean_string(content):
def test_create_custom_connection_with_allowed_error(ExtendedAuth0):
with patch.object(ExtendedAuth0.connections, "create") as connection_create:
connection_create.side_effect = exceptions.Auth0Error(
409, 409, 'The connection name existed already')
409, 409, "The connection name existed already"
)
ExtendedAuth0.connections.create_custom_connection(
"auth0_nomis",
input_values={
Expand All @@ -615,13 +613,12 @@ def test_create_custom_connection_with_allowed_error(ExtendedAuth0):
"client_secret": "WNXFkM3FCTXJhUWs0Q1NwcKFu",
},
)
connection_create.assert_called_once_with(mock.ANY)
connection_create.assert_called_once_with(ANY)


def test_create_custom_connection_with_notallowed_error(ExtendedAuth0):
with patch.object(ExtendedAuth0.connections, "create") as connection_create:
connection_create.side_effect = exceptions.Auth0Error(
400, 400, 'Error')
connection_create.side_effect = exceptions.Auth0Error(400, 400, "Error")
with pytest.raises(auth0.Auth0Error, match="400: Error"):
ExtendedAuth0.connections.create_custom_connection(
"auth0_nomis",
Expand All @@ -631,4 +628,4 @@ def test_create_custom_connection_with_notallowed_error(ExtendedAuth0):
"client_secret": "WNXFkM3FCTXJhUWs0Q1NwcKFu",
},
)
connection_create.assert_called_once_with(mock.ANY)
connection_create.assert_called_once_with(ANY)
10 changes: 7 additions & 3 deletions tests/api/test_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ def test_create_bucket(logs_bucket, s3):
def test_tag_bucket(s3):
bucket_name = f"bucket-{id(MagicMock())}"
bucket = s3.Bucket(bucket_name)
bucket.create()
bucket.create(
CreateBucketConfiguration={
"LocationConstraint": settings.BUCKET_REGION, # noqa: F405
}
)

aws.AWSBucket().tag_bucket(bucket_name, {"env": "test", "test-update": "old-value"})
aws.AWSBucket().tag_bucket(
Expand Down Expand Up @@ -557,8 +561,8 @@ def test_create_policy(iam, settings):
def assert_group_members(policy, role_names):
attached_roles = list(policy.attached_roles.all())
assert len(attached_roles) == len(role_names)
for role, role_name in zip(attached_roles, role_names):
assert role.role_name == role_name
for role in attached_roles:
assert role.role_name in role_names


@pytest.fixture
Expand Down
7 changes: 5 additions & 2 deletions tests/frontend/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pytest
from django.core.exceptions import ValidationError
from django.urls import reverse
from mock import MagicMock

# First-party/Local
from controlpanel.api import aws
Expand Down Expand Up @@ -411,6 +410,10 @@ def test_update_app_with_custom_connection():
assert "auth0_nomis_auth0_conn_name" in f.errors


def test_pass():
assert True


jamesstottmoj marked this conversation as resolved.
Show resolved Hide resolved
@pytest.mark.django_db
def test_ip_allowlist_form_invalid_ip():
"""
Expand Down Expand Up @@ -450,7 +453,7 @@ def test_ip_allowlist_form_missing_name():
@pytest.mark.parametrize("env", ["dev", "prod"])
@mock.patch(
"controlpanel.frontend.forms.CreateAppForm.get_datasource_queryset",
new=MagicMock,
new=mock.MagicMock,
)
def test_clean_namespace(env):
form = forms.CreateAppForm()
Expand Down
Loading