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
3e5c9c3b
Commit
3e5c9c3b
authored
Dec 21, 2017
by
Awais Jibran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improving logging
parent
e0459477
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
21 deletions
+40
-21
course_discovery/apps/publisher/tests/test_views.py
+32
-18
course_discovery/apps/publisher/views.py
+8
-3
No files found.
course_discovery/apps/publisher/tests/test_views.py
View file @
3e5c9c3b
...
@@ -26,21 +26,26 @@ from course_discovery.apps.core.models import User
...
@@ -26,21 +26,26 @@ from course_discovery.apps.core.models import User
from
course_discovery.apps.core.tests.factories
import
USER_PASSWORD
,
UserFactory
from
course_discovery.apps.core.tests.factories
import
USER_PASSWORD
,
UserFactory
from
course_discovery.apps.core.tests.helpers
import
make_image_file
from
course_discovery.apps.core.tests.helpers
import
make_image_file
from
course_discovery.apps.course_metadata.tests
import
toggle_switch
from
course_discovery.apps.course_metadata.tests
import
toggle_switch
from
course_discovery.apps.course_metadata.tests.factories
import
(
CourseFactory
,
OrganizationFactory
,
PersonFactory
,
from
course_discovery.apps.course_metadata.tests.factories
import
(
SubjectFactory
)
CourseFactory
,
OrganizationFactory
,
PersonFactory
,
SubjectFactory
)
from
course_discovery.apps.ietf_language_tags.models
import
LanguageTag
from
course_discovery.apps.ietf_language_tags.models
import
LanguageTag
from
course_discovery.apps.publisher.choices
import
(
CourseRunStateChoices
,
CourseStateChoices
,
InternalUserRole
,
from
course_discovery.apps.publisher.choices
import
(
PublisherUserRole
)
CourseRunStateChoices
,
CourseStateChoices
,
InternalUserRole
,
PublisherUserRole
from
course_discovery.apps.publisher.constants
import
(
ADMIN_GROUP_NAME
,
INTERNAL_USER_GROUP_NAME
,
)
PROJECT_COORDINATOR_GROUP_NAME
,
REVIEWER_GROUP_NAME
)
from
course_discovery.apps.publisher.constants
import
(
from
course_discovery.apps.publisher.models
import
(
Course
,
CourseRun
,
CourseRunState
,
CourseState
,
ADMIN_GROUP_NAME
,
INTERNAL_USER_GROUP_NAME
,
PROJECT_COORDINATOR_GROUP_NAME
,
REVIEWER_GROUP_NAME
OrganizationExtension
,
Seat
)
)
from
course_discovery.apps.publisher.models
import
(
Course
,
CourseRun
,
CourseRunState
,
CourseState
,
OrganizationExtension
,
Seat
)
from
course_discovery.apps.publisher.tests
import
factories
from
course_discovery.apps.publisher.tests
import
factories
from
course_discovery.apps.publisher.tests.utils
import
create_non_staff_user_and_login
from
course_discovery.apps.publisher.tests.utils
import
create_non_staff_user_and_login
from
course_discovery.apps.publisher.utils
import
is_email_notification_enabled
from
course_discovery.apps.publisher.utils
import
is_email_notification_enabled
from
course_discovery.apps.publisher.views
import
logger
as
publisher_views_logger
from
course_discovery.apps.publisher.views
import
logger
as
publisher_views_logger
from
course_discovery.apps.publisher.views
import
(
COURSES_ALLOWED_PAGE_SIZES
,
CourseRunDetailView
,
from
course_discovery.apps.publisher.views
import
(
get_course_role_widgets_data
)
COURSE_ROLES
,
COURSES_ALLOWED_PAGE_SIZES
,
CourseRunDetailView
,
get_course_role_widgets_data
)
from
course_discovery.apps.publisher.wrappers
import
CourseRunWrapper
from
course_discovery.apps.publisher.wrappers
import
CourseRunWrapper
from
course_discovery.apps.publisher_comments.models
import
CommentTypeChoices
from
course_discovery.apps.publisher_comments.models
import
CommentTypeChoices
from
course_discovery.apps.publisher_comments.tests.factories
import
CommentFactory
from
course_discovery.apps.publisher_comments.tests.factories
import
CommentFactory
...
@@ -535,18 +540,27 @@ class CreateCourseRunViewTests(SiteMixin, TestCase):
...
@@ -535,18 +540,27 @@ class CreateCourseRunViewTests(SiteMixin, TestCase):
def
test_cannot_create_course_run_without_roles
(
self
):
def
test_cannot_create_course_run_without_roles
(
self
):
"""
"""
Verify that user can
create a new course run with credit seat
.
Verify that user can
not create a new course run if the course user roles are not complete
.
"""
"""
organization_extension
=
factories
.
OrganizationExtensionFactory
()
organization_extension
=
factories
.
OrganizationExtensionFactory
()
course
=
factories
.
CourseFactory
(
organizations
=
[
organization_extension
.
organization
])
course
=
factories
.
CourseFactory
(
organizations
=
[
organization_extension
.
organization
])
self
.
user
.
groups
.
add
(
organization_extension
.
group
)
self
.
user
.
groups
.
add
(
organization_extension
.
group
)
create_course_run_url
=
reverse
(
'publisher:publisher_course_runs_new'
,
kwargs
=
{
'parent_course_id'
:
course
.
id
})
response
=
self
.
client
.
post
(
course_user_roles
=
course
.
course_user_roles
.
filter
(
role__in
=
COURSE_ROLES
)
reverse
(
'publisher:publisher_course_runs_new'
,
kwargs
=
{
'parent_course_id'
:
course
.
id
}),
with
LogCapture
(
publisher_views_logger
.
name
)
as
log_capture
:
{}
response
=
self
.
client
.
post
(
create_course_run_url
,
{})
)
self
.
assertContains
(
response
,
'Your organization does not have default roles'
,
status_code
=
400
)
log_capture
.
check
(
self
.
assertContains
(
response
,
'Your organization does not have default roles'
,
status_code
=
400
)
(
publisher_views_logger
.
name
,
'ERROR'
,
'Course [{}] is missing default course roles. Current roles [{}], required roles [{}]'
.
format
(
course
.
id
,
course_user_roles
.
count
(),
len
(
COURSE_ROLES
)
)
)
)
@ddt.ddt
@ddt.ddt
...
...
course_discovery/apps/publisher/views.py
View file @
3e5c9c3b
...
@@ -596,10 +596,9 @@ class CreateCourseRunView(mixins.LoginRequiredMixin, mixins.PublisherUserRequire
...
@@ -596,10 +596,9 @@ class CreateCourseRunView(mixins.LoginRequiredMixin, mixins.PublisherUserRequire
run_form
=
self
.
run_form
(
request
.
POST
)
run_form
=
self
.
run_form
(
request
.
POST
)
seat_form
=
self
.
seat_form
(
request
.
POST
)
seat_form
=
self
.
seat_form
(
request
.
POST
)
course_user_roles
=
parent_course
.
course_user_roles
.
filter
(
role__in
=
COURSE_ROLES
)
if
parent_course
.
course_user_roles
.
filter
(
role__in
=
COURSE_ROLES
)
.
count
()
==
len
(
COURSE_ROLES
)
or
\
if
course_user_roles
.
count
()
==
len
(
COURSE_ROLES
)
or
waffle
.
switch_is_active
(
'disable_publisher_permissions'
):
waffle
.
switch_is_active
(
'disable_publisher_permissions'
):
if
run_form
.
is_valid
()
and
seat_form
.
is_valid
():
if
run_form
.
is_valid
()
and
seat_form
.
is_valid
():
try
:
try
:
with
transaction
.
atomic
():
with
transaction
.
atomic
():
...
@@ -628,6 +627,12 @@ class CreateCourseRunView(mixins.LoginRequiredMixin, mixins.PublisherUserRequire
...
@@ -628,6 +627,12 @@ class CreateCourseRunView(mixins.LoginRequiredMixin, mixins.PublisherUserRequire
request
,
_
(
'The page could not be updated. Make sure that all values are correct, then try again.'
)
request
,
_
(
'The page could not be updated. Make sure that all values are correct, then try again.'
)
)
)
else
:
else
:
logger
.
error
(
'Course [
%
s] is missing default course roles. Current roles [
%
s], required roles [
%
s]'
,
parent_course
.
id
,
course_user_roles
.
count
(),
len
(
COURSE_ROLES
),
)
messages
.
error
(
messages
.
error
(
request
,
request
,
_
(
_
(
...
...
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