Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
ede1fbcc
Commit
ede1fbcc
authored
Aug 23, 2016
by
Awais
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ECOM-5311
Adding constraint A program status to "Active" without a banner image.
parent
20d2736d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
3 deletions
+68
-3
course_discovery/apps/course_metadata/admin.py
+6
-2
course_discovery/apps/course_metadata/forms.py
+10
-1
course_discovery/apps/course_metadata/tests/test_admin.py
+52
-0
No files found.
course_discovery/apps/course_metadata/admin.py
View file @
ede1fbcc
...
...
@@ -71,11 +71,15 @@ class ProgramAdmin(admin.ModelAdmin):
search_fields
=
(
'uuid'
,
'title'
,
'marketing_slug'
)
filter_horizontal
=
(
'job_outlook_items'
,
'expected_learning_items'
,
'credit_backing_organizations'
,)
filter_horizontal
=
(
'job_outlook_items'
,
'expected_learning_items'
,
'credit_backing_organizations'
,
'authoring_organizations'
,
)
# ordering the field display on admin page.
fields
=
(
'title'
,
'status'
,
'type'
,
'banner_image_url'
,
'card_image_url'
,
'overview'
,
'video'
,
'title'
,
'status'
,
'type'
,
'banner_image'
,
'banner_image_url'
,
'card_image_url'
,
'overview'
,
'video'
,
)
fields
+=
(
'courses'
,
'course_runs'
,
'excluded_course_runs'
...
...
course_discovery/apps/course_metadata/forms.py
View file @
ede1fbcc
from
django
import
forms
from
django.core.exceptions
import
ValidationError
from
django.forms.util
import
ErrorList
from
django.utils.translation
import
ugettext_lazy
as
_
from
course_discovery.apps.course_metadata.models
import
Program
,
CourseRun
...
...
@@ -11,13 +13,20 @@ class ProgramAdminForm(forms.ModelForm):
exclude
=
(
'subtitle'
,
'category'
,
'marketing_slug'
,
'weeks_to_complete'
,
'min_hours_effort_per_week'
,
'max_hours_effort_per_week'
,
'
authoring_organizations
'
,
'
partner
'
,
)
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
ProgramAdminForm
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
fields
[
'type'
]
.
required
=
True
def
clean
(
self
):
status
=
self
.
cleaned_data
.
get
(
'status'
)
banner_image
=
self
.
cleaned_data
.
get
(
'banner_image'
)
if
status
==
Program
.
ProgramStatus
.
Active
and
not
banner_image
:
raise
ValidationError
(
_
(
'Status cannot be change to active without banner image.'
))
return
self
.
cleaned_data
class
CourseRunSelectionForm
(
forms
.
ModelForm
):
...
...
course_discovery/apps/course_metadata/tests/test_admin.py
View file @
ede1fbcc
import
ddt
from
django.core.urlresolvers
import
reverse
from
django.test
import
TestCase
from
course_discovery.apps.course_metadata.forms
import
ProgramAdminForm
from
course_discovery.apps.course_metadata.models
import
Program
from
course_discovery.apps.course_metadata.tests
import
factories
from
course_discovery.apps.core.tests.factories
import
UserFactory
,
USER_PASSWORD
from
course_discovery.apps.core.tests.helpers
import
make_image_file
# pylint: disable=no-member
...
...
@@ -101,3 +104,52 @@ class AdminTests(TestCase):
self
.
assertEqual
(
4
,
len
(
self
.
program
.
course_runs
.
all
()))
response
=
self
.
client
.
get
(
reverse
(
'admin_metadata:update_course_runs'
,
args
=
(
self
.
program
.
id
,)))
self
.
assertNotContains
(
response
,
'<input checked="checked")'
)
def
test_program_without_image_and_active_status
(
self
):
""" Verify that new program cannot be added without `image` and active status together."""
data
=
self
.
_post_data
(
Program
.
ProgramStatus
.
Active
)
form
=
ProgramAdminForm
(
data
,
{
'banner_image'
:
''
})
self
.
assertFalse
(
form
.
is_valid
())
self
.
assertEqual
(
form
.
errors
[
'__all__'
],
[
'Status cannot be change to active without banner image.'
])
with
self
.
assertRaises
(
ValueError
):
form
.
save
()
@ddt.data
(
Program
.
ProgramStatus
.
Deleted
,
Program
.
ProgramStatus
.
Retired
,
Program
.
ProgramStatus
.
Unpublished
)
def
test_program_without_image_and_non_active_status
(
self
,
status
):
""" Verify that new program can be added without `image` and non-active
status using admin form.
"""
data
=
self
.
_post_data
(
status
)
data
[
'status'
]
=
status
self
.
valid_post_form
(
data
,
{
'banner_image'
:
''
})
@ddt.data
(
Program
.
ProgramStatus
.
Deleted
,
Program
.
ProgramStatus
.
Retired
,
Program
.
ProgramStatus
.
Unpublished
,
Program
.
ProgramStatus
.
Active
)
def
test_program_with_image
(
self
,
status
):
""" Verify that new program can be added with `image` and any status."""
data
=
self
.
_post_data
(
status
)
data
[
'status'
]
=
status
self
.
valid_post_form
(
data
,
{
'banner_image'
:
make_image_file
(
'test_banner.jpg'
)})
def
_post_data
(
self
,
status
):
return
{
'title'
:
'some test title'
,
'courses'
:
[
self
.
courses
[
0
]
.
id
],
'type'
:
self
.
program
.
type
.
id
,
'status'
:
status
}
def
valid_post_form
(
self
,
data
,
file_data
):
form
=
ProgramAdminForm
(
data
,
file_data
)
self
.
assertTrue
(
form
.
is_valid
())
program
=
form
.
save
()
response
=
self
.
client
.
get
(
reverse
(
'admin:course_metadata_program_change'
,
args
=
(
program
.
id
,)))
self
.
assertEqual
(
response
.
status_code
,
200
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment