Skip to content

Commit

Permalink
Merge branch 'master' into huniafatima/replace-deprecated-github-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
huniafatima-arbi authored Oct 2, 2024
2 parents 2fdcaa4 + 4022cd3 commit 459823b
Show file tree
Hide file tree
Showing 31 changed files with 606 additions and 256 deletions.
21 changes: 12 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['py38', 'py311', 'py312']
python-version: ['py312']
django-version: ['django42']
db-version: ['mysql80']
pytest-split-group: [1, 2, 3, 4, 5, 6]
Expand All @@ -23,8 +23,8 @@ jobs:
shell: bash
run: |
# Remove 'py' and insert a dot to format the version
FORMATTED_VERSION=${{ matrix.python-version }} # e.g., py38
FORMATTED_VERSION=${FORMATTED_VERSION/py3/3.} # becomes 3.8
FORMATTED_VERSION=${{ matrix.python-version }} # e.g., py312
FORMATTED_VERSION=${FORMATTED_VERSION/py3/3.} # becomes 3.12
# Set environment variables
echo "PYTHON_VERSION=$FORMATTED_VERSION" >> $GITHUB_ENV
Expand All @@ -44,7 +44,7 @@ jobs:
continue-on-error: ${{ matrix.status == 'ignored' }}
- name: Upload coverage
if: matrix.db-version == 'mysql80'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: coverage${{ matrix.pytest-split-group }}
path: .coverage
Expand All @@ -57,28 +57,31 @@ jobs:
- uses: actions/checkout@v3
- run: make ci_up
env:
PYTHON_VERSION: 3.8
PYTHON_VERSION: 3.12
- name: Download all artifacts
# Downloads coverage1, coverage2, etc.
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
- name: Run coverage
run: make ci_coverage
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: make ci_up
env:
PYTHON_VERSION: 3.8
PYTHON_VERSION: 3.12
- run: make ci_quality

semgrep:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.11', '3.12']
python-version: ['3.12']
steps:
- uses: actions/checkout@v3
- run: make ci_up
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/migrations-check-mysql8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-20.04 ]
python-version: [ 3.8 ]
os: [ ubuntu-latest ]
python-version: [ 3.12 ]

steps:
- name: Checkout repo
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/requirements-upgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ on:

jobs:
upgrade_requirements:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [ '3.8' ]
python-version: [ '3.12' ]

steps:
- name: setup target branch
Expand Down
15 changes: 11 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
FROM ubuntu:focal as app

ARG PYTHON_VERSION=3.8
ARG PYTHON_VERSION=3.12

ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC

# System requirements.
RUN apt-get update && \
apt-get install -y software-properties-common && \
Expand All @@ -14,8 +16,6 @@ RUN apt-get update && \
git \
language-pack-en \
build-essential \
python${PYTHON_VERSION}-dev \
python${PYTHON_VERSION}-distutils \
libmysqlclient-dev \
libssl-dev \
# TODO: Current version of Pillow (9.5.0) doesn't provide pre-built wheel for python 3.12,
Expand All @@ -24,7 +24,11 @@ RUN apt-get update && \
libjpeg-dev \
# mysqlclient >= 2.2.0 requires pkg-config.
pkg-config \
libcairo2-dev && \
libcairo2-dev \
python3-pip \
python${PYTHON_VERSION} \
python${PYTHON_VERSION}-dev \
python${PYTHON_VERSION}-distutils && \
rm -rf /var/lib/apt/lists/*

# Use UTF-8.
Expand All @@ -47,6 +51,9 @@ ENV DISCOVERY_CODE_DIR "${DISCOVERY_CODE_DIR}"
ENV DISCOVERY_APP_DIR "${DISCOVERY_APP_DIR}"
ENV PYTHON_VERSION "${PYTHON_VERSION}"

# Setup zoneinfo for Python 3.12
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION}
RUN pip install virtualenv

Expand Down
8 changes: 3 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ $(COMMON_CONSTRAINTS_TXT):
upgrade: $(COMMON_CONSTRAINTS_TXT)
sed 's/django-simple-history==3.0.0//g' requirements/common_constraints.txt > requirements/common_constraints.tmp
mv requirements/common_constraints.tmp requirements/common_constraints.txt
sed 's/Django<4.0//g' requirements/common_constraints.txt > requirements/common_constraints.tmp
mv requirements/common_constraints.tmp requirements/common_constraints.txt
pip install -q -r requirements/pip_tools.txt
pip-compile --allow-unsafe --upgrade -o requirements/pip.txt requirements/pip.in
pip-compile --upgrade -o requirements/pip_tools.txt requirements/pip_tools.in
Expand Down Expand Up @@ -92,10 +90,10 @@ html_coverage: ## Generate and view HTML coverage report
# This Make target should not be removed since it is relied on by a Jenkins job (`edx-internal/tools-edx-jenkins/translation-jobs.yml`), using `ecommerce-scripts/transifex`.
extract_translations: ## Extract strings to be translated, outputting .po and .mo files
# NOTE: We need PYTHONPATH defined to avoid ImportError(s) on CI.
cd course_discovery && PYTHONPATH="..:${PYTHONPATH}" django-admin.py makemessages -l en -v1 --ignore="assets/*" --ignore="static/bower_components/*" --ignore="static/build/*" -d django
cd course_discovery && PYTHONPATH="..:${PYTHONPATH}" django-admin.py makemessages -l en -v1 --ignore="assets/*" --ignore="static/bower_components/*" --ignore="static/build/*" -d djangojs
cd course_discovery && PYTHONPATH="..:${PYTHONPATH}" django-admin makemessages -l en -v1 --ignore="assets/*" --ignore="static/bower_components/*" --ignore="static/build/*" -d django
cd course_discovery && PYTHONPATH="..:${PYTHONPATH}" django-admin makemessages -l en -v1 --ignore="assets/*" --ignore="static/bower_components/*" --ignore="static/build/*" -d djangojs
cd course_discovery && PYTHONPATH="..:${PYTHONPATH}" i18n_tool dummy
cd course_discovery && PYTHONPATH="..:${PYTHONPATH}" django-admin.py compilemessages
cd course_discovery && PYTHONPATH="..:${PYTHONPATH}" django-admin compilemessages

# This Make target should not be removed since it is relied on by a Jenkins job (`edx-internal/tools-edx-jenkins/translation-jobs.yml`), using `ecommerce-scripts/transifex`.
ifeq ($(OPENEDX_ATLAS_PULL),)
Expand Down
2 changes: 2 additions & 0 deletions course_discovery/apps/api/tests/test_mixins.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from django.test.utils import override_settings
from django.urls import path, reverse
from mock import patch
Expand Down Expand Up @@ -68,6 +69,7 @@ def test_throttle_authenticated_user(self):
assert response.data == "Hello, World"
self.client.logout()

@pytest.mark.skip(reason="https://github.com/openedx/course-discovery/issues/4431")
def test_throttle_limit__authentication_classes(self):
"""
Verify that endpoint is throttled against unauthenticated users when requests are greater than limit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def test_courses_with_subjects_and_negative_query(self):
start=datetime.datetime(2015, 9, 1, tzinfo=pytz.UTC),
status=CourseRunStatus.Published,
type__is_marketable=True,
key=f'{name}/{factory.Faker("word").evaluate(None, None, {"locale":"en"})}/test',
key=f'{name}/{factory.Faker("word").evaluate(None, None, {"locale": "en"})}/test',
)
SeatFactory.create(course_run=course_run)

Expand All @@ -279,7 +279,7 @@ def test_courses_with_subjects_and_negative_query(self):
start=datetime.datetime(2015, 9, 1, tzinfo=pytz.UTC),
status=CourseRunStatus.Published,
type__is_marketable=True,
key=f'{name}/{factory.Faker("word").evaluate(None, None, {"locale":"en"})}/test',
key=f'{name}/{factory.Faker("word").evaluate(None, None, {"locale": "en"})}/test',
)
SeatFactory.create(course_run=course_run)
desired_courses.append(course_run.course)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,11 @@ def test_list_include_restricted(self, include_restriction_param):
else:
assert restricted_run.key not in retrieved_keys

@ddt.data([True, 4], [False, 3])
@ddt.data(
[True, 4],
# Skipping this because it's flaky: https://github.com/openedx/course-discovery/issues/4431
# [False, 3]
)
@ddt.unpack
def test_list_query_include_restricted(self, include_restriction_param, expected_result_count):
CourseRunFactory.create_batch(3, title='Some cool title', course__partner=self.partner)
Expand Down
2 changes: 2 additions & 0 deletions course_discovery/apps/api/v1/tests/test_views/test_courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def test_list(self):
self.serialize_course(Course.objects.all(), many=True)
)

@pytest.mark.skip(reason="https://github.com/openedx/course-discovery/issues/4431")
@responses.activate
def test_list_query(self):
""" Verify the endpoint returns a filtered list of courses """
Expand All @@ -366,6 +367,7 @@ def test_list_query(self):
response = self.client.get(url)
self.assertListEqual(response.data['results'], self.serialize_course(courses, many=True))

@pytest.mark.skip(reason="https://github.com/openedx/course-discovery/issues/4431")
def test_list_key_filter(self):
""" Verify the endpoint returns a list of courses filtered by the specified keys. """
courses = CourseFactory.create_batch(3, partner=self.partner)
Expand Down
29 changes: 4 additions & 25 deletions course_discovery/apps/api/v1/tests/test_views/test_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import json
import sys
import urllib.parse
import uuid

Expand Down Expand Up @@ -69,12 +68,7 @@ def assert_successful_search(self, path=None, serializer=None):
'next': None,
}
actual = response_data['objects'] if path == self.faceted_path else response_data
if sys.version_info > (3, 9):
# Remove this pylint disable once discovery reaches python 3.11+
# pylint: disable=unsupported-binary-operation
self.assertEqual(actual, actual | expected) # pragma: no cover
else:
self.assertDictContainsSubset(expected, actual)
self.assertEqual(actual, actual | expected) # pragma: no cover

return course_run, response_data

Expand All @@ -99,12 +93,7 @@ def assert_response_includes_availability_facets(self, response_data):
},
}

if sys.version_info > (3, 9):
# Remove this pylint disable once discovery reaches python 3.11+
# pylint: disable=unsupported-binary-operation
self.assertEqual(response_data['queries'], response_data['queries'] | expected) # pragma: no cover
else:
self.assertDictContainsSubset(expected, response_data['queries'])
self.assertEqual(response_data['queries'], response_data['queries'] | expected) # pragma: no cover

@ddt.data(faceted_path, list_path, detailed_path)
def test_authentication(self, path):
Expand Down Expand Up @@ -160,12 +149,7 @@ def test_faceted_search(self):
'count': 1,
}
actual = response_data['fields']['pacing_type'][0]
if sys.version_info > (3, 9):
# Remove this pylint disable once discovery reaches python 3.11+
# pylint: disable=unsupported-binary-operation
self.assertEqual(actual, actual | expected) # pragma: no cover
else:
self.assertDictContainsSubset(expected, actual)
self.assertEqual(actual, actual | expected) # pragma: no cover

def test_invalid_query_facet(self):
""" Verify the endpoint returns HTTP 400 if an invalid facet is requested. """
Expand Down Expand Up @@ -250,12 +234,7 @@ def test_exclude_unavailable_program_types(self, path, serializer, result_locati
self.serialize_course_run_search(course_run, serializer=serializer)
]
}
if sys.version_info > (3, 9):
# Remove this pylint disable once discovery reaches python 3.11+
# pylint: disable=unsupported-binary-operation
self.assertEqual(response_data, response_data | expected) # pragma: no cover
else:
self.assertDictContainsSubset(expected, response_data)
self.assertEqual(response_data, response_data | expected) # pragma: no cover

# Check that the program is indeed the active one.
for key in result_location_keys:
Expand Down
4 changes: 2 additions & 2 deletions course_discovery/apps/course_metadata/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ def display_degrees_on_org_page(self, request, queryset):
updated = queryset.update(display_on_org_page=True)
self.message_user(
request,
f"{updated} {'degrees were' if updated>1 else 'degree was'} successfully set to display on org page.",
f"{updated} {'degrees were' if updated > 1 else 'degree was'} successfully set to display on org page.",
messages.SUCCESS,
)

Expand All @@ -886,7 +886,7 @@ def hide_degrees_on_org_page(self, request, queryset):
updated = queryset.update(display_on_org_page=False)
self.message_user(
request,
f"{updated} {'degrees were' if updated>1 else 'degree was'} successfully set to be hidden on org page.",
f"{updated} {'degrees were' if updated > 1 else 'degree was'} successfully set to be hidden on org page.",
messages.SUCCESS,
)

Expand Down
Loading

0 comments on commit 459823b

Please sign in to comment.