Skip to content
This repository has been archived by the owner on May 3, 2023. It is now read-only.

Commit

Permalink
Merge branch 'feature/54-mentions' into develop. Closes #54
Browse files Browse the repository at this point in the history
  • Loading branch information
SoftlySplinter committed Feb 1, 2013
2 parents 8a1e166 + 21168fa commit 5f362fa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion tentd/blueprints/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ def delete(self, post_id):
post.delete()
return make_response(), 200

@posts.route_class('/<string:post_id>/versions', endpoint='post_versions')
@posts.route_class('/<string:post_id>/versions', endpoint='versions')
class VersionsView(MethodView):

decorators = [require_authorization]

def get(self, post_id):
return jsonify(g.entity.posts.get_or_404(id=post_id).versions)

@posts.route_class('/<string:post_id>/mentions', endpoint='mentions')
class MentionsView(MethodView):
def get(self, post_id):
return jsonify(g.entity.posts.get_or_404(id=post_id).versions[0].mentions)
8 changes: 6 additions & 2 deletions tentd/documents/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from mongoengine import *

from tentd.documents import db, EntityMixin
from tentd.documents import db, EntityMixin, BetterURLField
from tentd.utils import time_to_string, json_attributes

class Version(db.EmbeddedDocument):
Expand All @@ -32,6 +32,9 @@ class Version(db.EmbeddedDocument):
#: The content of the post
content = DictField(required=True)

#: The mentions of this post
mentions = ListField(BetterURLField)

def __repr__(self):
return '<Version {}: {}'.format(self.version, self.content)

Expand All @@ -40,6 +43,7 @@ def to_json(self):
'content': self.content,
'published_at': time_to_string(self.published_at),
'received_at': time_to_string(self.received_at),
'mentions': self.mentions,
}

class Post(EntityMixin, db.Document):
Expand All @@ -58,7 +62,7 @@ class Post(EntityMixin, db.Document):
}

#: The post type
schema = URLField(required=True)
schema = BetterURLField(required=True)

#: The versions of the post
versions = SortedListField(
Expand Down
7 changes: 7 additions & 0 deletions tentd/tests/blueprints/test_posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ def test_delete_post_version(self):
self.assertJSONError(self.client.delete(
'/testuser/posts/{}?version=0'.format(self.post.id)))

def test_get_post_mentions(self):
"""Test that the mentions of a post can be returned."""
resp = self.client.get('/{}/posts/{}/mentions'.format(self.name,
self.post.id))
self.assertStatus(resp, 200)
assert resp.json() == self.post.versions[0].mentions

class MorePostsTest(EntityTentdTestCase):
"""Tests for posts without having existing posts."""
def test_create_invalid_post(self):
Expand Down

0 comments on commit 5f362fa

Please sign in to comment.