Skip to content

Commit

Permalink
style: [EDXOLDMNG-200] files refomated by black
Browse files Browse the repository at this point in the history
  • Loading branch information
NiedielnitsevIvan committed Nov 29, 2022
1 parent 5c29b62 commit a3b1945
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 60 deletions.
2 changes: 1 addition & 1 deletion credentials/apps/api/v2/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class IsAdminUserOrReadOnly(permissions.BasePermission):
Grants access to edit only the administrator.
"""

SAFE_METHODS = ('GET', 'HEAD', 'OPTIONS')
SAFE_METHODS = ("GET", "HEAD", "OPTIONS")

def has_permission(self, request, view):
is_admin_user = request.user and (request.user.is_superuser or request.user.is_staff)
Expand Down
4 changes: 2 additions & 2 deletions credentials/apps/api/v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


logger = logging.getLogger(__name__)
DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S"


class CredentialField(serializers.Field):
Expand Down Expand Up @@ -306,7 +306,7 @@ class Meta:
def validate_image(self, value):
if value:
extension = Path(value.name).suffix[1:].lower()
if extension != 'png':
if extension != "png":
raise ValidationError("Only PNG files can be uploaded. Please select a file ending in .png to upload.")
return value

Expand Down
56 changes: 20 additions & 36 deletions credentials/apps/api/v2/tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,24 +326,14 @@ def test_create_signatory_missing_image(self):

def test_validation(self):
png_image = create_test_image("png")
data = {
"image": png_image,
"name": "signatory 1",
"organization": "edX",
"title": "title"
}
data = {"image": png_image, "name": "signatory 1", "organization": "edX", "title": "title"}
actual = SignatorySerializer(data=data).is_valid()

self.assertEqual(actual, True)

def test_validation_with_wrong_image_extension(self):
jpg_image = create_test_image("jpg")
data = {
"image": jpg_image,
"name": "signatory 1",
"organization": "edX",
"title": "title"
}
data = {"image": jpg_image, "name": "signatory 1", "organization": "edX", "title": "title"}
actual = SignatorySerializer(data=data).is_valid()

self.assertEqual(actual, False)
Expand Down Expand Up @@ -425,34 +415,28 @@ def test_create_without_course_run_raises_warning(self):

def test_parse_signatories_in_files(self):
png_image = create_test_image("png")
signatories_data = [{
"image": "/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.png",
"name": "signatory 1",
"organization": "edX",
"title": "title"
},
{
"image": "/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image+1.png",
"name": "signatory 2",
"organization": "edX",
"title": "title"
}]
signatories_data = [
{
"image": "/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.png",
"name": "signatory 1",
"organization": "edX",
"title": "title",
},
{
"image": "/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image+1.png",
"name": "signatory 2",
"organization": "edX",
"title": "title",
},
]
files = {
"/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.png": png_image,
"/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image+1.png": png_image,
}

actual = CourseCertificateSerializer.parse_signatories_in_files(json.dumps(signatories_data), files)
expected = [{
"image": png_image,
"name": "signatory 1",
"organization": "edX",
"title": "title"
},
{
"image": png_image,
"name": "signatory 2",
"organization": "edX",
"title": "title"
}]
expected = [
{"image": png_image, "name": "signatory 1", "organization": "edX", "title": "title"},
{"image": png_image, "name": "signatory 2", "organization": "edX", "title": "title"},
]
self.assertEqual(actual, expected)
40 changes: 19 additions & 21 deletions credentials/apps/api/v2/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,24 +719,28 @@ def setUp(self):
"certificate_available_date": self.certificate.certificate_available_date,
"is_active": self.certificate.is_active,
"signatories": list(self.certificate.signatories.all()),
"title": self.certificate.title
"title": self.certificate.title,
}
self.valid_data = {
"course_id": "course-v1:edX+DemoX+Demo_Course",
"certificate_type": "honor",
"title": "Name of the certificate",
"signatories": json.dumps([{
"image": "/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.png",
"name": "signatory 1",
"organization": "edX",
"title": "title"
},
{
"image": "/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image+1.png",
"name": "signatory 2",
"organization": "edX",
"title": "title"
}]),
"signatories": json.dumps(
[
{
"image": "/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image.png",
"name": "signatory 1",
"organization": "edX",
"title": "title",
},
{
"image": "/asset-v1:edX+DemoX+Demo_Course+type@asset+block@images_course_image+1.png",
"name": "signatory 2",
"organization": "edX",
"title": "title",
},
]
),
"is_active": True,
}

Expand All @@ -746,21 +750,15 @@ def authenticate_user(self, user):
self.client.login(username=user.username, password=USER_PASSWORD)

def test_get_for_anonymous(self):
params = {
"course_id": self.certificate.course_id,
"certificate_type": self.certificate.certificate_type
}
params = {"course_id": self.certificate.course_id, "certificate_type": self.certificate.certificate_type}
response = self.client.get(self.url, data=params)

self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, self.certificate_data)

def test_get_for_staff(self):
self.authenticate_user(self.superuser)
params = {
"course_id": self.certificate.course_id,
"certificate_type": self.certificate.certificate_type
}
params = {"course_id": self.certificate.course_id, "certificate_type": self.certificate.certificate_type}
response = self.client.get(self.url, data=params)

self.assertEqual(response.status_code, 200)
Expand Down

0 comments on commit a3b1945

Please sign in to comment.