Skip to content

Commit

Permalink
selenium tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
sdreher committed Aug 12, 2014
1 parent 2d7f664 commit 5f50bb4
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 65 deletions.
2 changes: 1 addition & 1 deletion media/templates/asset_workspace.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
</td>
{{/thumb_url?}}
<td>
<div class="global-annotation-analysis">
<div class="global-annotation-analysis">
{{^global_annotation_analysis}}
<center>
<div>You have no notes or tags for this item.</div>
Expand Down
2 changes: 1 addition & 1 deletion media/templates/homepage.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
<div class="metadata">
<span class="metadata-label">by</span>
<span class="metadata-value metadata-value-author">{{#authors}}{{name}}{{^last}}, {{/last}}{{/authors}}</span>
<span class="metadata-value metadata-value-author">{{#participants}}{{name}}{{^last}}, {{/last}}{{/participants}}</span>
<span class="metadata-label">saved on</span>
<span class="metadata-value">{{modified_date}} at {{modified_time}}</span>
</div>
Expand Down
34 changes: 17 additions & 17 deletions mediathread/assetmgr/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,9 @@
import time


class SourceResource(ModelResource):
class Meta:
queryset = Source.objects.none()
resource_name = 'source'
allowed_methods = ['get']
excludes = ['id', 'modified', 'size', 'media_type']

def dehydrate(self, bundle):
bundle.data['url'] = bundle.obj.url_processed(bundle.request,
bundle.obj.asset)
return bundle


class AssetResource(ModelResource):

author = fields.ForeignKey(UserResource, 'author', full=True)
sources = fields.ToManyField(SourceResource, 'source_set',
blank=True, null=True, full=True, )

class Meta:
queryset = Asset.objects.none()
Expand Down Expand Up @@ -71,6 +56,16 @@ def dehydrate(self, bundle):
bundle.data['my_annotation_count'] = 0
bundle.data['modified'] = self.format_time(bundle.obj.modified)

sources = {}
for s in bundle.obj.source_set.all():
sources[s.label] = {'label': s.label,
'url': s.url_processed(bundle.request,
bundle.obj),
'width': s.width,
'height': s.height,
'primary': s.primary}
bundle.data['sources'] = sources

for key, value in self.extras.items():
bundle.data[key] = value

Expand Down Expand Up @@ -98,6 +93,11 @@ def render_one(self, request, asset, notes=None):

if note.is_global_annotation():
the_json['global_annotation'] = note_ctx

the_json['global_annotation_analysis'] = (
len(note_ctx['vocabulary']) > 0 or
len(note_ctx['metadata']['body']) > 0 or
len(note_ctx['metadata']['tags']) > 0)
else:
the_json['annotations'].append(note_ctx)

Expand All @@ -106,7 +106,7 @@ def render_one(self, request, asset, notes=None):
except Source.DoesNotExist:
return None

def render_list(self, request, record_owner, assets, notes):
def render_list(self, request, me, assets, notes):
note_resource = SherdNoteResource()
ctx = {}
for note in notes.all():
Expand All @@ -119,7 +119,7 @@ def render_list(self, request, record_owner, assets, notes):
is_global = note.is_global_annotation()
if not is_global:
ctx[note.asset.id]['annotation_count'] += 1
if note.author == record_owner:
if note.author == me:
ctx[note.asset.id]['my_annotation_count'] += 1

if note.modified > note.asset.modified:
Expand Down
5 changes: 4 additions & 1 deletion mediathread/assetmgr/features/collection.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Feature: Collection View
Then I am at the Mediathread Collection page

Finished using Selenium

Scenario Outline: collection.feature 2. Collection - Viewing Items & Selections
Using selenium

Expand Down Expand Up @@ -124,10 +124,13 @@ Feature: Collection View
And the "MAAP Award Reception" item has 2 selections, 1 by me

And I can filter by "student_one_selection" in the asset-workspace column
And the "MAAP Award Reception" item has 1 selections, 1 by me

And I can filter by "student_one_item" in the asset-workspace column

# Student Two
When I select "Student Two" as the owner
And I clear all tags
Then the owner is "Student Two" in the asset-workspace column
Then the Collection panel has a "MAAP Award Reception" item
And the "MAAP Award Reception" item has 2 selections, 1 by me
Expand Down
3 changes: 2 additions & 1 deletion mediathread/assetmgr/features/single_asset_view.feature
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ Feature: Single Asset View
Then the item header is "MAAP Award Reception"
And I see "Here are my notes"
And I see "abc"
And I do not see "student one item note"
And I do not see "student one item note" in the item tab
Then I wait 1 second
And I do not see "student_one_item"

Finished using Selenium
18 changes: 15 additions & 3 deletions mediathread/assetmgr/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ def get(self, request, asset_id=None, annot_id=None):
# @todo - refactor this context out of the mix
# ideally, the client would simply request the json
# the mixin is expecting a queryset, so this becomes awkward here
self.record_owner = request.user
assets = Asset.objects.filter(pk=asset_id)
(assets, notes) = self.visible_assets_and_notes(request, assets)
context['assets'] = {
Expand Down Expand Up @@ -531,6 +532,7 @@ class AssetDetailView(LoggedInMixin, RestrictedMaterialsMixin,
AjaxRequiredMixin, JSONResponseMixin, View):

def get(self, request, asset_id):
self.record_owner = request.user
assets = Asset.objects.filter(pk=asset_id, course=request.course)
if assets.count() == 0:
return asset_switch_course(request, asset_id)
Expand Down Expand Up @@ -572,6 +574,8 @@ class AssetCollectionView(LoggedInMixin, RestrictedMaterialsMixin,
def get_context(self, request, assets, notes):
# Allow the logged in user to add assets to his composition
citable = request.GET.get('citable', '') == 'true'

# Include annotation metadata. (makes response much larger)
include_annotations = request.GET.get('annotations', '') == 'true'

# Initialize the context
Expand All @@ -592,15 +596,23 @@ def get_context(self, request, assets, notes):
ctx['editable'] = self.viewing_own_records
ctx['citable'] = citable

# render the assets
ares = AssetResource(include_annotations=include_annotations,
extras={'editable': self.viewing_own_records,
'citable': citable})
ctx['assets'] = ares.render_list(request, self.record_owner,
ctx['assets'] = ares.render_list(request,
self.record_viewer,
assets, notes)

return ctx

def add_metadata(self, request, notes):
def add_metadata(self, request, assets):
# metadata for all notes associated with these assets
# is displayed in the filtered list.
# Not sure this is exactly right...will discuss with team
notes = SherdNote.objects.get_related_notes(
assets, self.record_owner or None, self.visible_authors)

tags = TagResource().render_related(request, notes)
vocab = VocabularyResource().render_related(request, notes)
return {'active_tags': tags, 'active_vocabulary': vocab}
Expand Down Expand Up @@ -632,7 +644,7 @@ def get(self, request):
if offset == 0:
# add relevant tags & metadata for all visible notes
# needs to come before the pagination step
ctx.update(self.add_metadata(request, notes))
ctx.update(self.add_metadata(request, assets))

# slice down the list to speed rendering
(assets, notes) = self.apply_pagination(assets, notes, offset, limit)
Expand Down
6 changes: 4 additions & 2 deletions mediathread/djangosherd/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ def get_related_notes(self, assets, record_owner, visible_authors,

# filter by tag string, date, vocabulary
self = self.filter_by_tags(tag_string)
self = self.filter_by_date(modified)
self = self.filter_by_vocabulary(vocabulary)
if self.count() > 0:
self = self.filter_by_date(modified)
if self.count() > 0:
self = self.filter_by_vocabulary(vocabulary)
return self


Expand Down
7 changes: 2 additions & 5 deletions mediathread/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ def dispatch(self, *args, **kwargs):
# Does the course allow viewing other user selections?
# The viewer can always view their own records + faculty records
# If the viewer is faculty, they can view all records
self.all_selections_are_visible = (
all_selections_are_visible(self.request.course) or
self.viewing_own_records or self.viewing_faculty_records or
self.is_viewer_faculty)
self.all_selections_are_visible = \
all_selections_are_visible(self.request.course)

self.visible_authors = []
if not self.all_selections_are_visible and not self.is_viewer_faculty:
Expand All @@ -96,7 +94,6 @@ def visible_assets_and_notes(self, request, assets):
ids = visible_notes.values_list('asset__id', flat=True)
visible_assets = assets.filter(id__in=ids).distinct()
return (visible_assets, visible_notes)
return None


class AjaxRequiredMixin(object):
Expand Down
37 changes: 28 additions & 9 deletions mediathread/projects/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ProjectResource(ModelResource):

author = fields.ForeignKey(UserResource, 'author', full=True)

date_fmt = "%m/%d/%y %I:%M %p"

def __init__(self, *args, **kwargs):
# @todo: extras is a side-effect of the Mustache templating system
# not supporting the ability to reference variables in the parent
Expand Down Expand Up @@ -48,7 +50,7 @@ def dehydrate(self, bundle):
bundle.data['is_faculty'] = self.is_viewer_faculty

participants = bundle.obj.attribution_list()
bundle.data['authors'] = [{
bundle.data['participants'] = [{
'name': p.get_full_name(),
'username': p.username,
'public_name': get_public_name(p, bundle.request),
Expand Down Expand Up @@ -98,18 +100,35 @@ def render_one(self, request, project, version_number=None):
data['responses'] = []
for response in project.responses(request):
if response.can_read(request):
bundle = self.build_bundle(obj=response, request=request)
dehydrated = self.full_dehydrate(bundle)
ctx = self._meta.serializer.to_simple(dehydrated, None)
data['responses'].append(ctx)
obj = {
'url': response.get_absolute_url(),
'title': response.title,
'modified': response.modified.strftime(self.date_fmt),
'attribution_list': []}

last = len(response.attribution_list()) - 1
for idx, author in enumerate(response.attribution_list()):
obj['attribution_list'].append({
'name': get_public_name(author, request),
'last': idx == last})

data['responses'].append(obj)
data['response_count'] = len(data['responses'])

my_responses = []
for response in project.responses_by(request, request.user):
bundle = self.build_bundle(obj=response, request=request)
dehydrated = self.full_dehydrate(bundle)
ctx = self._meta.serializer.to_simple(dehydrated, None)
my_responses.append(ctx)
obj = {'url': response.get_absolute_url(),
'title': response.title,
'modified': response.modified.strftime(self.date_fmt),
'attribution_list': []}

last = len(response.attribution_list()) - 1
for idx, author in enumerate(response.attribution_list()):
obj['attribution_list'].append({
'name': get_public_name(author, request),
'last': idx == last})

my_responses.append(obj)

if len(my_responses) == 1:
data['my_response'] = my_responses[0]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Feature: Public Compositions



Scenario Outline: publishtoworld.composition.feature 1. Instructor creates public to world composition - verify visibility
Using selenium
Given I am test_instructor in Sample Course
Expand Down
2 changes: 1 addition & 1 deletion mediathread/projects/tests/test_homepage.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class HomepageTest(TestCase):

def assertProjectEquals(self, project, title, author, editable):
self.assertEquals(project['title'], title)
self.assertEquals(project['authors'][0]['public_name'], author)
self.assertEquals(project['participants'][0]['public_name'], author)
self.assertEquals(project['editable'], editable)

def test_get_my_projectlist_as_student(self):
Expand Down
5 changes: 2 additions & 3 deletions mediathread/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,9 @@ def project_view_readonly(request, project_id, version_number=None):
# Requested project, either assignment or composition
request.public = True

is_faculty = request.course.is_faculty(request.user)
resource = ProjectResource(record_viewer=request.user,
is_viewer_faculty=is_faculty,
editable=project.can_edit(request))
is_viewer_faculty=False,
editable=False)
project_context = resource.render_one(request, project, version_number)
panel = {'panel_state': 'open',
'panel_state_label': "Version View",
Expand Down
6 changes: 3 additions & 3 deletions mediathread/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

DEBUG = True

COMPRESS_ROOT = "/Users/sdreher/workspace/mediathread/media/"

PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))

DATABASES = {
Expand All @@ -19,7 +17,9 @@
}

LETTUCE_SERVER_PORT = 8002
BROWSER = 'Firefox' # ["Chrome", "Firefox", "Headless"}
#BROWSER = 'Firefox'
BROWSER = 'Headless'
#BROWSER = 'Chrome'

LETTUCE_APPS = (
'mediathread.main',
Expand Down
3 changes: 3 additions & 0 deletions mediathread/taxonomy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def render_list(self, request, vocabularies):
return data

def render_related(self, request, object_list):
if len(object_list) < 1:
return []

ctx = {}
term_resource = TermResource()

Expand Down
2 changes: 1 addition & 1 deletion mediathread/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<a href="/?unset_course">Switch Course</a>
{% endif %}

<a href="/accounts/logout/">Log Out</a>
<a href="/accounts/logout/?next=/">Log Out</a>
</div>
</li>

Expand Down
Loading

0 comments on commit 5f50bb4

Please sign in to comment.