def test_assets_for_course(self, authorized_user_session): asset_feed = Asset.get_assets(authorized_user_session, sort='recent', offset=0, limit=20, filters={}) # Feed shape assert asset_feed['offset'] == 0 assert asset_feed['total'] == 2 assert len(asset_feed['results']) == 2 # Ordering assert asset_feed['results'][0]['id'] > asset_feed['results'][1]['id'] # Asset structure for asset in asset_feed['results']: assert asset['body'] is None assert asset['canvasAssignmentId'] is None assert asset['commentCount'] == 0 assert asset['courseId'] == authorized_user_session.course.id assert asset['createdAt'] is not None assert asset['deletedAt'] is None assert asset['description'] is None assert asset['downloadUrl'] is None assert asset['imageUrl'] is None assert asset['liked'] is False assert asset['likes'] == 0 assert asset['mime'] is None assert asset['pdfUrl'] is None assert asset['previewMetadata'] == '{}' assert asset['previewStatus'] == 'pending' assert asset['source'] is None assert asset['thumbnailUrl'] is None assert asset['title'] is not None assert asset['type'] == 'link' assert asset['createdAt'] is not None assert asset['updatedAt'] is not None assert asset['views'] == 0 assert asset['visible'] is True assert len(asset['users']) == 1 assert asset['users'][0]['id'] == authorized_user_session.user.id assert asset['users'][0]['canvasFullName'] == 'Oliver Heyer' assert asset['users'][0]['canvasUserId'] == 9876543 assert asset['users'][0]['canvasCourseRole'] == 'Teacher' assert asset['users'][0]['canvasEnrollmentState'] == 'active' assert 'canvasCourseSections' in asset['users'][0] assert 'canvasImage' in asset['users'][0]
def get_assets(): params = request.get_json() sort = _get(params, 'sort', None) offset = params.get('offset') limit = params.get('limit') filters = { 'asset_type': _get(params, 'assetType', None), 'category_id': _get(params, 'categoryId', None), 'has_comments': _get(params, 'hasComments', None), 'has_likes': _get(params, 'hasLikes', None), 'has_views': _get(params, 'hasViews', None), 'keywords': _get(params, 'keywords', None), 'order_by': _get(params, 'orderBy', 'recent'), 'owner_id': _get(params, 'userId', None), 'section_id': _get(params, 'sectionId', None), } results = Asset.get_assets(session=current_user, sort=sort, offset=offset, limit=limit, filters=filters) return tolerant_jsonify(results)