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
00d005db
Commit
00d005db
authored
Apr 04, 2018
by
asadazam93
Committed by
AsadAzam
Apr 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added log for publish course run
parent
674c60e2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
course_discovery/apps/publisher/api/v1/tests/test_views.py
+13
-5
course_discovery/apps/publisher/api/v1/views.py
+9
-1
No files found.
course_discovery/apps/publisher/api/v1/tests/test_views.py
View file @
00d005db
import
json
import
json
import
random
import
random
from
datetime
import
date
import
mock
import
mock
import
responses
import
responses
from
django.test
import
override_settings
from
django.test
import
override_settings
from
django.urls
import
reverse
from
django.urls
import
reverse
from
rest_framework.test
import
APITestCase
from
rest_framework.test
import
APITestCase
from
testfixtures
import
LogCapture
from
course_discovery.apps.core.models
import
Currency
,
Partner
from
course_discovery.apps.core.models
import
Currency
,
Partner
from
course_discovery.apps.core.tests.factories
import
StaffUserFactory
,
UserFactory
from
course_discovery.apps.core.tests.factories
import
StaffUserFactory
,
UserFactory
...
@@ -24,6 +26,8 @@ from course_discovery.apps.publisher.tests.factories import CourseEntitlementFac
...
@@ -24,6 +26,8 @@ from course_discovery.apps.publisher.tests.factories import CourseEntitlementFac
PUBLISHER_UPGRADE_DEADLINE_DAYS
=
random
.
randint
(
1
,
21
)
PUBLISHER_UPGRADE_DEADLINE_DAYS
=
random
.
randint
(
1
,
21
)
LOGGER_NAME
=
'course_discovery.apps.publisher.api.v1.views'
class
CourseRunViewSetTests
(
APITestCase
):
class
CourseRunViewSetTests
(
APITestCase
):
...
@@ -56,7 +60,8 @@ class CourseRunViewSetTests(APITestCase):
...
@@ -56,7 +60,8 @@ class CourseRunViewSetTests(APITestCase):
def
_set_test_client_domain_and_login
(
self
,
partner
):
def
_set_test_client_domain_and_login
(
self
,
partner
):
# pylint:disable=attribute-defined-outside-init
# pylint:disable=attribute-defined-outside-init
self
.
client
=
self
.
client_class
(
SERVER_NAME
=
partner
.
site
.
domain
)
self
.
client
=
self
.
client_class
(
SERVER_NAME
=
partner
.
site
.
domain
)
self
.
client
.
force_login
(
StaffUserFactory
())
self
.
user
=
StaffUserFactory
()
self
.
client
.
force_login
(
self
.
user
)
def
_mock_studio_api_success
(
self
,
publisher_course_run
):
def
_mock_studio_api_success
(
self
,
publisher_course_run
):
partner
=
publisher_course_run
.
course
.
organizations
.
first
()
.
partner
partner
=
publisher_course_run
.
course
.
organizations
.
first
()
.
partner
...
@@ -108,10 +113,13 @@ class CourseRunViewSetTests(APITestCase):
...
@@ -108,10 +113,13 @@ class CourseRunViewSetTests(APITestCase):
self
.
_mock_studio_api_success
(
publisher_course_run
)
self
.
_mock_studio_api_success
(
publisher_course_run
)
self
.
_mock_ecommerce_api
(
publisher_course_run
)
self
.
_mock_ecommerce_api
(
publisher_course_run
)
with
LogCapture
(
LOGGER_NAME
)
as
log
:
url
=
reverse
(
'publisher:api:v1:course_run-publish'
,
kwargs
=
{
'pk'
:
publisher_course_run
.
pk
})
url
=
reverse
(
'publisher:api:v1:course_run-publish'
,
kwargs
=
{
'pk'
:
publisher_course_run
.
pk
})
response
=
self
.
client
.
post
(
url
,
{})
response
=
self
.
client
.
post
(
url
,
{})
assert
response
.
status_code
==
200
assert
response
.
status_code
==
200
log
.
check
((
LOGGER_NAME
,
'INFO'
,
'Published course run with id: [{}] lms_course_id: [{}], user: [{}], date: [{}]'
.
format
(
publisher_course_run
.
id
,
publisher_course_run
.
lms_course_id
,
self
.
user
,
date
.
today
())))
assert
len
(
responses
.
calls
)
==
3
assert
len
(
responses
.
calls
)
==
3
expected
=
{
expected
=
{
'discovery'
:
CourseRunViewSet
.
PUBLICATION_SUCCESS_STATUS
,
'discovery'
:
CourseRunViewSet
.
PUBLICATION_SUCCESS_STATUS
,
...
...
course_discovery/apps/publisher/api/v1/views.py
View file @
00d005db
import
logging
import
logging
from
collections
import
OrderedDict
from
collections
import
OrderedDict
from
datetime
import
date
from
edx_rest_api_client.client
import
EdxRestApiClient
from
edx_rest_api_client.client
import
EdxRestApiClient
from
edx_rest_framework_extensions.authentication
import
JwtAuthentication
from
edx_rest_framework_extensions.authentication
import
JwtAuthentication
...
@@ -60,7 +61,14 @@ class CourseRunViewSet(viewsets.GenericViewSet):
...
@@ -60,7 +61,14 @@ class CourseRunViewSet(viewsets.GenericViewSet):
if
not
_status
.
startswith
(
self
.
PUBLICATION_SUCCESS_STATUS
):
if
not
_status
.
startswith
(
self
.
PUBLICATION_SUCCESS_STATUS
):
status_code
=
status
.
HTTP_502_BAD_GATEWAY
status_code
=
status
.
HTTP_502_BAD_GATEWAY
break
break
if
status_code
==
status
.
HTTP_200_OK
:
logger
.
info
(
'Published course run with id: [
%
d] lms_course_id: [
%
s], user: [
%
s], date: [
%
s]'
,
course_run
.
id
,
course_run
.
lms_course_id
,
request
.
user
,
date
.
today
()
)
return
Response
(
publication_status
,
status
=
status_code
)
return
Response
(
publication_status
,
status
=
status_code
)
def
publish_to_studio
(
self
,
partner
,
course_run
):
def
publish_to_studio
(
self
,
partner
,
course_run
):
...
...
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