Skip to content

Commit

Permalink
Merge pull request #418 from ccnmtl/version-view
Browse files Browse the repository at this point in the history
Project Version View Fix
  • Loading branch information
thraxil committed Nov 9, 2015
2 parents 8cab76b + 7c8e4de commit a97bd9e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mediathread/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def create_collaboration(self, create, extracted, **kwargs):
if create:
Collaboration.objects.get_or_create(
content_type=ContentType.objects.get_for_model(Course),
object_pk=str(self.pk))
object_pk=str(self.pk), slug=self.slug())


class SourceFactory(factory.DjangoModelFactory):
Expand Down
2 changes: 1 addition & 1 deletion mediathread/projects/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def test_reset_publish_to_world(self):
policy='PublicEditorsAreOwners')
self.assertEquals(
public.public_url(),
'/s/collaboration/%s/' % public.get_collaboration().id)
'/s/%s/project/%s/' % (self.sample_course.slug(), public.id))

Project.objects.reset_publish_to_world(self.sample_course)
self.assertIsNone(public.public_url())
Expand Down
47 changes: 45 additions & 2 deletions mediathread/projects/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
from django.core.urlresolvers import reverse
from django.test import TestCase
from django.test.client import RequestFactory
import reversion

from mediathread.factories import MediathreadTestMixin, UserFactory, \
AssetFactory, SherdNoteFactory, ProjectFactory, AssignmentItemFactory, \
ProjectNoteFactory
from mediathread.projects.models import Project, \
RESPONSE_VIEW_POLICY, RESPONSE_VIEW_NEVER, RESPONSE_VIEW_SUBMITTED
RESPONSE_VIEW_POLICY, RESPONSE_VIEW_NEVER, RESPONSE_VIEW_SUBMITTED, \
PUBLISH_WHOLE_WORLD
from mediathread.projects.views import SelectionAssignmentView, ProjectItemView
import reversion


class ProjectViewTest(MediathreadTestMixin, TestCase):
Expand Down Expand Up @@ -339,6 +340,48 @@ def test_project_revisions(self):
the_json = loads(response.content)
self.assertEquals(len(the_json['revisions']), 1)

def test_project_view_readonly(self):
version = self.project_private.versions().next()
url = reverse('project-view-readonly',
kwargs={'project_id': self.project_private.id,
'version_number': version.revision_id})

# anonymous
response = self.client.get(url, {})
self.assertEquals(response.status_code, 403)

# forbidden
self.client.login(username=self.student_two.username, password='test')
response = self.client.get(url, {})
self.assertEquals(response.status_code, 403)

# owner
self.client.login(username=self.student_one.username, password='test')
response = self.client.get(url, {})
self.assertEquals(response.status_code, 200)

# ajax
response = self.client.get(url, {},
HTTP_X_REQUESTED_WITH='XmlHttpRequest')
self.assertEquals(response.status_code, 200)

def test_project_public_view(self):
url = self.project_private.get_collaboration().get_absolute_url()

# still private
response = self.client.get(url, {})
self.assertEquals(response.status_code, 403)

# reset to public
self.project_private.create_or_update_collaboration(
PUBLISH_WHOLE_WORLD[0])
self.project_private.date_submitted = datetime.now()
self.project_private.save()

url = self.project_private.public_url()
response = self.client.get(url, {})
self.assertEquals(response.status_code, 200)

def test_project_workspace_errors(self):
project_id = self.project_private.id
url = reverse('project-workspace', args=[project_id])
Expand Down
4 changes: 3 additions & 1 deletion mediathread/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ def project_view_readonly(request, project_id, version_number=None):
context_instance=RequestContext(request))
else:
if version_number:
version = get_object_or_404(Version, revision_id=version_number)
version = get_object_or_404(Version,
object_id=str(project.id),
revision_id=version_number)
project = version.object_version.object

panels = []
Expand Down

0 comments on commit a97bd9e

Please sign in to comment.