Skip to content

Commit

Permalink
chore: bump python to 3.9 (#107)
Browse files Browse the repository at this point in the history
* chore: bump python to 3.9

* fix: updated version in CI

* fix: failed python tests

* fix: f string formatting issue

* revert: temporary CI fix

* fix: removed unnecessary try block
  • Loading branch information
Anas12091101 authored Jun 24, 2024
1 parent 9340157 commit c7f3722
Show file tree
Hide file tree
Showing 26 changed files with 58 additions and 93 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.5"
env:
PIP_TRUSTED_HOST: "pypi.python.org pypi.org files.pythonhosted.org"
python-version: "3.9"

- id: cache
uses: actions/cache@v1
Expand Down
1 change: 0 additions & 1 deletion edx_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
edX python REST API client
"""
Expand Down
2 changes: 1 addition & 1 deletion edx_api/bulk_user_retirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
log = logging.getLogger(__name__)


class BulkUserRetirement(object):
class BulkUserRetirement:
"""
API client for interacting with user retirement API
"""
Expand Down
2 changes: 1 addition & 1 deletion edx_api/ccx.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
log = logging.getLogger(__name__)


class CCX(object):
class CCX:
"""
API Client for interacting w/ CCXs
"""
Expand Down
2 changes: 1 addition & 1 deletion edx_api/ccx_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os.path
import requests

from mock import create_autospec
from unittest.mock import create_autospec
from .ccx import CCX


Expand Down
7 changes: 2 additions & 5 deletions edx_api/certificates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .models import Certificate, Certificates


class UserCertificates(object):
class UserCertificates:
"""
edX student certificates client
"""
Expand Down Expand Up @@ -37,10 +37,7 @@ def get_student_certificate(self, username, course_id):
resp = self.requester.get(
urljoin(
self.base_url,
'/api/certificates/v0/certificates/{username}/courses/{course_key}/'.format(
username=username,
course_key=course_id
)
f'/api/certificates/v0/certificates/{username}/courses/{course_id}/'
)
)

Expand Down
9 changes: 3 additions & 6 deletions edx_api/certificates/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dateutil import parser


class Certificates(object):
class Certificates:
"""
The certificates object
This assumes that there can be only one certificate
Expand Down Expand Up @@ -56,18 +56,15 @@ def has_verified_cert(self, course_id):
return course_id in self.verified_certificates


class Certificate(object):
class Certificate:
"""
The certificate object
"""
def __init__(self, json):
self.json = json

def __str__(self):
return "<Certificate for user {username} for course {course_id}>".format(
username=self.username,
course_id=self.course_id
)
return f"<Certificate for user {self.username} for course {self.course_id}>"

@property
def is_verified(self):
Expand Down
6 changes: 2 additions & 4 deletions edx_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .user_info import UserInfo


class EdxApi(object):
class EdxApi:
"""
A client for speaking with edX.
"""
Expand All @@ -41,9 +41,7 @@ def get_requester(self, token_type="Bearer"):
session = requests.session()
session.headers.update(
{
"Authorization": "{} {}".format(
token_type, self.credentials["access_token"]
)
"Authorization": f"{token_type} {self.credentials['access_token']}"
}
)

Expand Down
2 changes: 1 addition & 1 deletion edx_api/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ def test_instantiation_happypath():
"""instantiatable with correct args"""
token = 'asdf'
client = EdxApi({'access_token': token})
assert client.get_requester().headers['Authorization'] == 'Bearer {token}'.format(token=token)
assert client.get_requester().headers['Authorization'] == f'Bearer {token}'
15 changes: 5 additions & 10 deletions edx_api/course_detail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


# pylint: disable=too-few-public-methods
class CourseDetails(object):
class CourseDetails:
"""
API Client to interface with the course detail API.
"""
Expand All @@ -32,17 +32,14 @@ def get_detail(self, course_id, username=None):
resp = self._requester.get(
urljoin(
self._base_url,
"/api/courses/v1/courses/{course_key}".format(course_key=course_id),
f"/api/courses/v1/courses/{course_id}",
)
)
else:
resp = self._requester.get(
urljoin(
self._base_url,
"/api/courses/v1/courses/{course_key}/"
"?username={username}".format(
course_key=course_id, username=username
),
f"/api/courses/v1/courses/{course_id}/?username={username}"
)
)

Expand All @@ -51,7 +48,7 @@ def get_detail(self, course_id, username=None):
return CourseDetail(resp.json())


class CourseModes(object):
class CourseModes:
"""
API Client to interface with the course modes API.
"""
Expand All @@ -73,9 +70,7 @@ def get_mode(self, course_id):
resp = self._requester.get(
urljoin(
self._base_url,
"/api/course_modes/v1/courses/{course_key}".format(
course_key=course_id
),
f"/api/course_modes/v1/courses/{course_id}",
)
)

Expand Down
8 changes: 4 additions & 4 deletions edx_api/course_detail/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Media = namedtuple("Media", ["type", "url"])


class CourseDetail(object):
class CourseDetail:
"""
The course detail object
"""
Expand All @@ -17,7 +17,7 @@ def __init__(self, payload):
self.json = payload

def __str__(self):
return "<Course detail for {}>".format(self.course_id)
return f"<Course detail for {self.course_id}>"

def __repr__(self):
return self.__str__()
Expand Down Expand Up @@ -145,7 +145,7 @@ def is_self_paced(self):
return self.pacing == "self"


class CourseMode(object):
class CourseMode:
"""
The course mode object
"""
Expand All @@ -154,7 +154,7 @@ def __init__(self, payload):
self.json = payload

def __str__(self):
return "<Course mode for {}>".format(self.course_id)
return f"<Course mode for {self.course_id}>"

def __repr__(self):
return self.__str__()
Expand Down
2 changes: 1 addition & 1 deletion edx_api/course_structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .models import Structure


class CourseStructure(object):
class CourseStructure:
"""
API Client to interface with the course structure API.
"""
Expand Down
6 changes: 3 additions & 3 deletions edx_api/course_structure/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Business objects for the course structure API"""


class Structure(object):
class Structure:
"""
The course structure object, which represents a tree of nodes.
"""
Expand All @@ -25,10 +25,10 @@ def root(self):
return Block(root_id, self.payload)

def __str__(self):
return 'Structure for {}'.format(self._root_id)
return f'Structure for {self._root_id}'


class Block(object):
class Block:
"""
Represents a single block within the course structure.
"""
Expand Down
2 changes: 1 addition & 1 deletion edx_api/email_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
log = logging.getLogger(__name__)


class EmailSettings(object):
class EmailSettings:
"""
API client for interacting with email settings
"""
Expand Down
2 changes: 1 addition & 1 deletion edx_api/enrollments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


# pylint: disable=too-few-public-methods
class CourseEnrollments(object):
class CourseEnrollments:
"""
edX student enrollments client
"""
Expand Down
7 changes: 2 additions & 5 deletions edx_api/enrollments/init_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import os
from unittest import TestCase

try:
from mock import patch
except ImportError:
from unittest.mock import patch
from unittest.mock import patch

import requests_mock
from urllib.parse import urljoin
Expand Down Expand Up @@ -154,7 +151,7 @@ def test_get_enrollments_list(self, mock_req):
)
mock_req.register_uri(
'GET',
'{url}?cursor=next-cursor'.format(url=CourseEnrollments.enrollment_list_url),
f'{CourseEnrollments.enrollment_list_url}?cursor=next-cursor',
text=json.dumps({
'previous': 'http://base_url/enrl/?cursor=next-cursor',
'results': self.enrollments_list_json[2:],
Expand Down
17 changes: 7 additions & 10 deletions edx_api/enrollments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# pylint: disable=too-few-public-methods


class Enrollments(object):
class Enrollments:
"""
The enrollments object
"""
Expand Down Expand Up @@ -76,18 +76,15 @@ def get_enrollment_for_course(self, course_id):
return self.enrollments.get(course_id)


class Enrollment(object):
class Enrollment:
"""
Single enrollment object representation
"""
def __init__(self, json):
self.json = json

def __str__(self):
return "<Enrollment for user {user} in course {course}>".format(
user=self.user,
course=self.course_id
)
return f"<Enrollment for user {self.user} in course {self.course_id}>"

@property
def course_id(self):
Expand Down Expand Up @@ -130,15 +127,15 @@ def is_verified(self):
return self.mode == 'verified'


class CourseDetails(object):
class CourseDetails:
"""
Course enrollment info
"""
def __init__(self, json):
self.json = json

def __str__(self):
return "<Enrollment details for course {}>".format(self.course_id)
return f"<Enrollment details for course {self.course_id}>"

@property
def course_id(self):
Expand Down Expand Up @@ -207,15 +204,15 @@ def course_modes(self):
yield CourseMode(course_mode_json)


class CourseMode(object):
class CourseMode:
"""
Course enrollment mode
"""
def __init__(self, json):
self.json = json

def __str__(self):
return "<Enrollment mode {}>".format(self.slug)
return f"<Enrollment mode {self.slug}>"

@property
def currency(self):
Expand Down
11 changes: 4 additions & 7 deletions edx_api/grades/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .models import CurrentGrade, CurrentGradesByUser, CurrentGradesByCourse


class UserCurrentGrades(object):
class UserCurrentGrades:
"""
edX student certificates client
"""
Expand Down Expand Up @@ -37,10 +37,7 @@ def get_student_current_grade(self, username, course_id):
resp = self.requester.get(
urljoin(
self.base_url,
'/api/grades/v1/courses/{course_key}/?username={username}'.format(
username=username,
course_key=course_id
)
f'/api/grades/v1/courses/{course_id}/?username={username}'
)
)

Expand Down Expand Up @@ -92,7 +89,7 @@ def get_course_current_grades(self, course_id):
resp = self.requester.get(
urljoin(
self.base_url,
'/api/grades/v1/courses/{course_key}/'.format(course_key=course_id)
f'/api/grades/v1/courses/{course_id}/'
)
)
resp.raise_for_status()
Expand All @@ -103,7 +100,7 @@ def get_course_current_grades(self, course_id):
resp = self.requester.get(resp_json['next'])
resp.raise_for_status()
resp_json = resp.json()
grade_entries.extend((CurrentGrade(entry) for entry in resp_json["results"]))
grade_entries.extend(CurrentGrade(entry) for entry in resp_json["results"])
else:
grade_entries = [CurrentGrade(entry) for entry in resp_json]

Expand Down
2 changes: 1 addition & 1 deletion edx_api/grades/init_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GradesApiTestCase(TestCase):
base_url = "https://edx.example.com"

def setUp(self):
super(GradesApiTestCase, self).setUp()
super().setUp()

with open(
os.path.join(
Expand Down
Loading

0 comments on commit c7f3722

Please sign in to comment.