コード例 #1
0
    def test_get(self, verify_token):
        """Test the institution_timeline_handler get method."""
        user = mocks.create_user()
        verify_token._mock_return_value = {'email': user.email[0]}
        institution = mocks.create_institution()
        institution.address = mocks.create_address()
        user.add_institution(institution.key)
        institution.add_member(user)

        post = mocks.create_post(user.key, institution.key)
        post.last_modified_by = user.key
        post_aux = mocks.create_post(user.key, institution.key)
        post_aux.last_modified_by = user.key

        post.put()
        post_aux.put()

        # Call the get method
        posts = self.testapp.get("/api/institutions/%s/timeline?page=0&&limit=2" %
                                 institution.key.urlsafe())
        # Update the objects
        post_top = (posts.json['posts'])[0]
        post_last = (posts.json['posts'])[1]

        # Verify if the posts was published and your informations
        self.assertEqual(
            post_top, 
            post_aux.make(posts.request.host),
            "The maked post should be equal to the expected one"
        )
        self.assertEqual(
            post_last, 
            post.make(posts.request.host),
            "The maked post should be equal to the expected one"
        )

        # Call the delete method for a post that has activity
        post = post.like(user.key)
        post.delete(user)

        # Call the get method
        posts = self.testapp.get("/api/institutions/%s/timeline?page=0&&limit=2" %
                                 institution.key.urlsafe())

        # Update the objects
        post_top = (posts.json['posts'])[0]
        post_last = (posts.json['posts'])[1]

        # Verify if the post was deleted and your informations
        self.assertEqual(post_top["title"], None,
                         "The title expected was null")
        self.assertEqual(post_top["text"], None,
                         "The text expected was null")
        self.assertEqual(post_top["state"], 'deleted',
                         "The state of post should be deleted")
        self.assertEqual(
            post_last, 
            post_aux.make(posts.request.host),
            "The maked post should be equal to the expected one"
        )
コード例 #2
0
    def test_get_with_deleted_post(self, verify_token):
        """Test the institution_timeline_handler get method with deleted post."""
        user = mocks.create_user()
        verify_token._mock_return_value = {'email': user.email[0]}
        institution = mocks.create_institution()
        user.add_institution(institution.key)
        institution.add_member(user)
        
        post = mocks.create_post(user.key, institution.key)
        post.last_modified_by = user.key
        other_post = mocks.create_post(user.key, institution.key)
        other_post.last_modified_by = user.key
        other_post.delete(user)
        post.put()
        other_post.put()

        posts = self.testapp.get("/api/institutions/%s/timeline?page=0&&limit=2" %
                                 institution.key.urlsafe())
        
        post_json = (posts.json['posts'])[0]

        self.assertEqual(
            len(posts.json['posts']), 
            1,
            "Number of posts should be equal 1"
        )
        self.assertEqual(
            post_json, 
            post.make(posts.request.host),
            "The maked post should be equal to the expected one"    
        )
コード例 #3
0
    def setUp(cls):
        """Provide the base for the tests."""
        super(PostCommentHandlerTest, cls).setUp()
        app = cls.webapp2.WSGIApplication(
            [("/api/posts/(.*)/comments/(.*)", PostCommentHandler),
             ("/api/posts/(.*)/comments", PostCommentHandler)],
            debug=True)
        cls.testapp = cls.webtest.TestApp(app)

        # Create models
        # new User
        cls.user = mocks.create_user(USER_EMAIL)
        # new User
        cls.other_user = mocks.create_user(OTHER_USER_EMAIL)
        # new Institution
        cls.institution = mocks.create_institution()
        cls.institution.members = [cls.user.key]
        cls.institution.followers = [cls.user.key]
        cls.institution.admin = cls.user.key
        cls.institution.put()
        cls.user.add_institution(cls.institution.key)
        cls.other_user.add_institution(cls.institution.key)
        # POST of user To institution
        cls.user_post = mocks.create_post(cls.user.key, cls.institution.key)
        # Comments
        cls.comment = {
            'text': 'Frist comment. Using in Test',
            'institution_key': cls.institution.key.urlsafe()
        }
        cls.other_comment = {
            'text': 'Second comment. Using in Test',
            'institution_key': cls.institution.key.urlsafe()
        }
        # http post body
        cls.body = {'commentData': cls.comment}
コード例 #4
0
    def setUp(cls):
        """Provide the base for the tests."""
        super(ReplyCommentHandlerTest, cls).setUp()
        methods = set(cls.webapp2.WSGIApplication.allowed_methods)
        methods.add('PATCH')
        cls.webapp2.WSGIApplication.allowed_methods = frozenset(methods)
        app = cls.webapp2.WSGIApplication([
            ("/api/posts/(.*)/comments/(.*)/replies", ReplyCommentHandler),
            ("/api/posts/(.*)/comments/(.*)/replies/(.*)", ReplyCommentHandler)
        ],
                                          debug=True)
        cls.testapp = cls.webtest.TestApp(app)

        # create models
        # new User
        cls.user = mocks.create_user(USER_EMAIL)
        # other user
        cls.other_user = mocks.create_user(OTHER_USER_EMAIL)
        # third user
        cls.third_user = mocks.create_user(THIRD_USER_EMAIL)
        # new Institution CERTBIO
        cls.institution = mocks.create_institution()
        cls.third_user.add_institution(cls.institution.key)
        # POST of User To Certbio Institution
        cls.user_post = mocks.create_post(cls.user.key, cls.institution.key)
        # comment from other_user
        cls.other_user_comment = mocks.create_comment(
            cls.institution.key.urlsafe(), cls.other_user)
        # reply from third_user
        cls.reply = mocks.create_comment(cls.institution.key.urlsafe(),
                                         cls.third_user)
        # add comment to post
        cls.user_post.add_comment(cls.other_user_comment)
        cls.user_post = cls.user_post.key.get()
        cls.user_post.put()
コード例 #5
0
    def setUp(cls):
        """Provide the base for the tests."""
        super(LikeCommentHandlerTest, cls).setUp()
        app = cls.webapp2.WSGIApplication([
            ("/api/posts/(.*)/comments/(.*)/likes", LikeHandler),
        ],
                                          debug=True)
        cls.testapp = cls.webtest.TestApp(app)

        # mocking entities
        # new Users
        cls.user = mocks.create_user('*****@*****.**')
        cls.other_user = mocks.create_user('*****@*****.**')
        cls.third_user = mocks.create_user('*****@*****.**')
        # new Institution
        cls.institution = mocks.create_institution()
        cls.user.add_institution(cls.institution.key)
        cls.other_user.add_institution(cls.institution.key)
        # Post of User
        cls.post = mocks.create_post(cls.user.key, cls.institution.key)
        # comment
        cls.comment = mocks.create_comment(cls.institution.key.urlsafe(),
                                           cls.third_user)
        # add comment to post
        cls.post.add_comment(cls.comment)
        cls.post = cls.post.key.get()

        # creating uri
        cls.uri = '/api/posts/%s/comments/%s/likes' % (cls.post.key.urlsafe(),
                                                       cls.comment.id)
コード例 #6
0
    def setUp(cls):
        """Provide the base for the tests."""
        super(PostHandlerTest, cls).setUp()
        methods = set(cls.webapp2.WSGIApplication.allowed_methods)
        methods.add('PATCH')
        cls.webapp2.WSGIApplication.allowed_methods = frozenset(methods)
        app = cls.webapp2.WSGIApplication([
            ("/api/posts/(.*)", PostHandler),
        ],
                                          debug=True)
        cls.testapp = cls.webtest.TestApp(app)

        # first user
        cls.first_user = mocks.create_user('*****@*****.**')
        # second user
        cls.second_user = mocks.create_user('*****@*****.**')
        # institution
        cls.institution = mocks.create_institution('institution')
        cls.institution.add_member(cls.first_user)
        cls.institution.add_member(cls.second_user)
        cls.institution.follow(cls.first_user.key)
        cls.institution.follow(cls.second_user.key)
        cls.institution.set_admin(cls.first_user.key)
        cls.first_user.add_institution(cls.institution.key)
        cls.first_user.add_institution_admin(cls.institution.key)
        # POST of first_user To Institution
        cls.first_user_post = mocks.create_post(cls.first_user.key,
                                                cls.institution.key)
        # POST of first_user To institution
        cls.first_user_other_post = mocks.create_post(cls.first_user.key,
                                                      cls.institution.key)
        # Post of second_user
        cls.second_user_post = mocks.create_post(cls.second_user.key,
                                                 cls.institution.key)
        # update institution's posts
        cls.institution.posts = [
            cls.second_user_post.key, cls.first_user_post.key,
            cls.first_user_other_post.key
        ]
        cls.institution.put()
        # comment
        cls.second_user_comment = mocks.create_comment(
            cls.institution.key.urlsafe(), cls.second_user)
コード例 #7
0
    def test_create_entity_from_post(self):
        """Test create_entity method when the entity_key is from a post."""
        institution = mocks.create_institution()
        author = mocks.create_user()
        post = mocks.create_post(author.key, institution.key)
        entity = service_messages.create_entity(post.key.urlsafe())
        expected_entity = {
            "key": post.key.urlsafe()
        }

        self.assertEquals(
            entity,
            json.dumps(expected_entity),
            "The created entity should be equal to the expected one"
        )
コード例 #8
0
    def setUp(cls):
        """Provide the base for the tests."""
        super(PostCollectionHandlerTest, cls).setUp()
        app = cls.webapp2.WSGIApplication([
            ("/api/posts", PostCollectionHandler),
        ],
                                          debug=True)
        cls.testapp = cls.webtest.TestApp(app)

        # create models
        # new User
        cls.user = mocks.create_user('*****@*****.**')
        cls.user.photo_url = 'urlphoto'
        cls.user.put()
        # new User
        cls.other_user = mocks.create_user('*****@*****.**')
        cls.other_user.photo_url = 'urlphoto'
        cls.user.put()
        # new Institution
        cls.institution = mocks.create_institution()
        cls.institution.photo_url = 'urlphoto'
        cls.institution.admin = cls.user.key
        cls.user.add_institution(cls.institution.key)
        cls.institution.follow(cls.other_user.key)
        cls.institution.put()
        # POST
        cls.post = mocks.create_post(cls.user.key, cls.institution.key)
        cls.post.last_modified_by = cls.user.key
        cls.post.put()
        # Update Institution
        cls.institution.posts.append(cls.post.key)
        cls.institution.followers.append(cls.user.key)
        cls.institution.put()
        # Update User
        cls.user.posts.append(cls.post.key)
        cls.user.add_institution(cls.institution.key)
        cls.post.put()
        # body for post method
        post_data = {
            'title': 'new post',
            'institution': cls.institution.key.urlsafe(),
            'text': 'testing new post'
        }
        cls.body = {'post': post_data}
コード例 #9
0
 def setUp(cls):
     """Provide the base for the tests."""
     super(LikePostHandlerTest, cls).setUp()
     app = cls.webapp2.WSGIApplication(
         [("/api/posts/(.*)/likes", LikeHandler),], debug=True
     )
     cls.testapp = cls.webtest.TestApp(app)
     
     # models creation
     # new User User
     cls.user = mocks.create_user('*****@*****.**')
     # new User Other User
     cls.other_user = mocks.create_user('*****@*****.**')
     # new Institution SPLAB
     cls.institution = mocks.create_institution()
     cls.user.add_institution(cls.institution.key)
     cls.other_user.add_institution(cls.institution.key)
     # new Post
     cls.post = mocks.create_post(cls.user.key, cls.institution.key)
コード例 #10
0
    def test_post_deleted_post(self, verify_token):
        institution = mocks.create_institution()
        user = mocks.create_user()
        institution.add_member(user)
        user.add_institution(institution.key)
        post = mocks.create_post(user.key, institution.key)

        post.delete(user)

        with self.assertRaises(Exception) as raises_context:
            self.testapp.post('/api/posts/%s/likes' % post.key.urlsafe(),
            headers={'institution-authorization': self.institution.key.urlsafe()})
        
        exception_message = self.get_message_exception(str(raises_context.exception))
        self.assertEqual(
            exception_message, 
            'Error! This post has been deleted',
            'Expected message of exception must be equal to Error! This post has been deleted'
        )
コード例 #11
0
    def test_send_message_notification(self, taskqueue_add, create_entity):
        """Test send_message_notification method."""
        sender = mocks.create_user()
        sender.photo_url = "photo-url"
        sender.put()
        receiver = mocks.create_user()
        institution = mocks.create_institution()
        current_institution = { "name": institution.name }
        post = mocks.create_post(receiver.key, institution.key)
        notification_type = "LIKE_POST"
        expected_message = {
            'from': {
                'name': sender.name.encode('utf8'),
                'photo_url': sender.photo_url,
                'institution_name': institution.name
            },
            'to': {
                'institution_name': ''
            },
            'current_institution': current_institution
        }

        service_messages.send_message_notification(
            receiver_key=receiver.key.urlsafe(),
            notification_type=notification_type,
            entity_key=post.key.urlsafe(),
            message=expected_message
        )

        self.assertTrue(
            create_entity.called,
            "Should have called the create_entity method"
        )
        self.assertTrue(
            taskqueue_add.called,
            "Should have called the add method from taskqueue"
        )
コード例 #12
0
def init(cls):
    """Init the models."""
    # new Users
    cls.user = mocks.create_user('*****@*****.**')
    cls.other_user = mocks.create_user('*****@*****.**')
    cls.third_user = mocks.create_user('*****@*****.**')
    # new Institution
    cls.institution = mocks.create_institution()
    # Post of User
    cls.post = mocks.create_post(cls.user.key, cls.institution.key)
    # comment
    cls.comment = mocks.create_comment(cls.institution.key.urlsafe(),
                                       cls.third_user)
    # reply
    cls.reply = mocks.create_comment(cls.institution.key.urlsafe(),
                                     cls.other_user)
    # add comment to post
    cls.post.add_comment(cls.comment)
    # add reply to comment
    cls.post = cls.post.key.get()
    cls.post.reply_comment(cls.reply, cls.comment.id)

    cls.uri = '/api/posts/%s/comments/%s/replies/%s/likes' % (
        cls.post.key.urlsafe(), cls.comment.id, cls.reply.id)