-
Notifications
You must be signed in to change notification settings - Fork 171
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
fix: 500 error during opening program certificate page (master) #4182
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
from django.test import TestCase | ||
|
||
from course_discovery.apps.api.tests.mixins import SiteMixin | ||
from course_discovery.apps.core.tests.factories import USER_PASSWORD, UserFactory | ||
from course_discovery.apps.course_metadata.choices import ProgramStatus | ||
from course_discovery.apps.course_metadata.forms import ProgramAdminForm | ||
from course_discovery.apps.course_metadata.tests import factories | ||
|
||
|
||
class ProgramAdminFormTests(SiteMixin, TestCase): | ||
""" Tests ProgramAdminForm. """ | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.user = UserFactory(is_staff=True, is_superuser=True) | ||
cls.course_runs = factories.CourseRunFactory.create_batch(3) | ||
cls.courses = [course_run.course for course_run in cls.course_runs] | ||
cls.product_source = factories.SourceFactory() | ||
|
||
cls.excluded_course_run = factories.CourseRunFactory(course=cls.courses[0]) | ||
cls.program = factories.ProgramFactory( | ||
courses=cls.courses, | ||
excluded_course_runs=[cls.excluded_course_run], | ||
partner=cls.partner, | ||
) | ||
cls.org_1 = factories.OrganizationFactory(certificate_logo_image=None) | ||
cls.org_2 = factories.OrganizationFactory(certificate_logo_image=None) | ||
cls.org_3 = factories.OrganizationFactory() | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.client.login(username=self.user.username, password=USER_PASSWORD) | ||
|
||
def _post_data(self, status=ProgramStatus.Unpublished, marketing_slug='/foo'): | ||
return { | ||
'title': 'some test title', | ||
'courses': [self.courses[0].id], | ||
'type': self.program.type.id, | ||
'status': status, | ||
'marketing_slug': marketing_slug, | ||
'partner': self.program.partner.id, | ||
'product_source': self.product_source.id, | ||
'authoring_organizations': [self.org_1.id, self.org_2.id, self.org_3.id], | ||
} | ||
|
||
def test_clean_authoring_organizations_with_empty_certificate_logo_image(self): | ||
""" | ||
Test verifies that the form is invalid if certificate_logo_image | ||
is empty for any of the authoring_organizations. | ||
""" | ||
data = self._post_data() | ||
form = ProgramAdminForm(data=data) | ||
self.assertFalse(form.is_valid()) | ||
expected_error_message = f'Certificate logo image cannot be empty for organizations: ' \ | ||
f'{self.org_1.name}, {self.org_2.name}.' | ||
|
||
self.assertEqual(form.errors['authoring_organizations'][0], expected_error_message) | ||
|
||
def test_clean_authoring_organizations_with_non_empty_certificate_logo_image(self): | ||
""" | ||
Test verifies that the form is valid only if certificate_logo_image | ||
is not empty for all authoring_organizations. | ||
""" | ||
self.org_1.certificate_logo_image = 'logo1.jpg' | ||
self.org_1.save() | ||
self.org_2.certificate_logo_image = 'logo2.jpg' | ||
self.org_2.save() | ||
data = self._post_data() | ||
form = ProgramAdminForm(data=data) | ||
|
||
self.assertTrue(form.is_valid()) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add method docstring
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AfaqShuaib09 done