Commit 5d278776 by tasawernawaz Committed by Tasawer Nawaz

view added for getting history of courses ECOM-7012

parent 4b8b3c0d
......@@ -2030,3 +2030,55 @@ class CourseRunEditViewTests(TestCase):
response = self.client.get(self.edit_page_url)
self.assertContains(response, '<div id="SeatPriceBlock" class="col col-6')
class CourseRevisionViewTests(TestCase):
""" Tests for CourseReview"""
def setUp(self):
super(CourseRevisionViewTests, self).setUp()
self.course = factories.CourseFactory()
self.user = UserFactory()
self.client.login(username=self.user.username, password=USER_PASSWORD)
def test_get_revision(self):
"""
Verify that view return history_object against given revision_id.
"""
self.course.title = 'Updated title'
self.course.save()
# index 0 will return the latest object
revision_id = self.course.history.all()[1].history_id
response = self._get_response(course_id=self.course.id, revision_id=revision_id)
history_object = response.context['history_object']
self.assertIn('history_object', response.context)
self.assertNotEqual(self.course.title, history_object.title)
def test_get_with_invalid_revision_id(self):
"""
Verify that view returns 404 response if revision id does not found.
"""
response = self._get_response(course_id=self.course.id, revision_id='0000')
self.assertEqual(response.status_code, 404)
def test_get_with_invalid_course_id(self):
"""
Verify that view returns 404 response if course id does not found.
"""
self.course.title = 'Updated title'
self.course.save()
# index 0 will return the latest object
revision_id = self.course.history.all()[1].history_id
response = self._get_response(course_id='0000', revision_id=revision_id)
self.assertEqual(response.status_code, 404)
def _get_response(self, course_id, revision_id):
""" Return the response object with given revision_id. """
revision_path = reverse('publisher:publisher_course_revision',
kwargs={'pk': course_id, 'revision_id': revision_id})
return self.client.get(path=revision_path)
......@@ -30,4 +30,6 @@ urlpatterns = [
views.ToggleEmailNotification.as_view(),
name='publisher_toggle_email_settings'
),
url(r'^courses/(?P<pk>\d+)/revisions/(?P<revision_id>\d+)/$', views.CourseRevisionView.as_view(),
name='publisher_course_revision'),
]
......@@ -8,8 +8,9 @@ import waffle
from django.contrib import messages
from django.core.urlresolvers import reverse
from django.core.exceptions import ObjectDoesNotExist
from django.db import transaction
from django.http import HttpResponseRedirect, JsonResponse
from django.http import HttpResponseRedirect, JsonResponse, Http404
from django.shortcuts import render, get_object_or_404
from django.utils.translation import ugettext_lazy as _
from django.views.generic import View, CreateView, UpdateView, DetailView, ListView
......@@ -644,3 +645,18 @@ class CourseListView(mixins.LoginRequiredMixin, ListView):
context = super(CourseListView, self).get_context_data(**kwargs)
context['publisher_hide_features_for_pilot'] = waffle.switch_is_active('publisher_hide_features_for_pilot')
return context
class CourseRevisionView(mixins.LoginRequiredMixin, DetailView):
"""Course revisions view """
model = Course
template_name = 'publisher/course_revision_history.html'
def get_context_data(self, **kwargs):
context = super(CourseRevisionView, self).get_context_data(**kwargs)
try:
context['history_object'] = self.object.history.get(history_id=self.kwargs.get('revision_id'))
except ObjectDoesNotExist:
raise Http404
return context
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
{#TODO revision template will be added in other subtask#}
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment