예제 #1
0
 async def test_handle_post_extras(self):
     new_doc = TargetResponse({"doc": "foo"})
     extras_doc = TargetResponse({"doc": "foo", "extras": 1})
     self.post.get_action = MagicMock(return_value="create")
     self.target._handle_new = asynctest.CoroutineMock(return_value=new_doc)
     self.target.handle_extras = asynctest.CoroutineMock(return_value=extras_doc)
     self.target._db.insert_post = asynctest.CoroutineMock(return_value=None)
     res = await self.target.handle_post(self.post)
     assert res is None
     self.target._handle_new.assert_called_once_with(self.post)
     self.target.handle_extras.assert_called_once_with(self.post)
     assert self.target._db.insert_post.call_count == 1
예제 #2
0
 async def post_item(self, post):
     post_url = "{}chat.postMessage".format(self.endpoint)
     data = await self._build_post_data({
         "text": post.content,
         "unfurl_links": True,
     })
     return TargetResponse(await self._post(post_url, data))
예제 #3
0
 async def post_item(self, post):
     post_url = None
     post_url = self._build_url("write/event/create.json",
                                {"ticker_id": self.target_id})
     response = await self._post(post_url, post.content)
     logger.info("post item response: ".format(response))
     return TargetResponse(response)
예제 #4
0
 async def delete_item(self, post):
     id_at_target = self.get_id_at_target(post)
     if not id_at_target:
         logger.warning("Handling deleted item without TARGET-ID: [{}] on {}".format(post.id, self.target_id))
         return False
     await self._check_login()
     delete_url = "{}/post/{}/delete?".format(self.endpoint, id_at_target)
     return TargetResponse(await self._get(delete_url))
예제 #5
0
 async def update_item(self, post):
     id_at_target = self.get_id_at_target(post)
     if not id_at_target:
         logger.warning("Handling updated item without TARGET-ID: [{}] on {}".format(post.id, self.target_id))
         return False
     await self._check_login()
     update_url = "{}/post/{}?".format(self.endpoint_v1, self.get_id_at_target(post))
     return TargetResponse(await self._put(update_url, post.content, post.images))
예제 #6
0
 async def delete_item(self, post):
     """Build your request to delete a post."""
     await self._login()
     # get id of post at target
     id_at_target = self.get_id_at_target(post)
     if not id_at_target:
         raise InvalidTargetResource("No id for resource at target found!")
     # delete post
     url = "{}/{}/{}".format(self.endpoint, "posts", id_at_target)
     data = {"deleted": True, "post_status": "open"}
     return TargetResponse(await self._patch(url, json.dumps(data), etag=self.get_etag_at_target(post)))
예제 #7
0
 async def post_item(self, post):
     """Build your request to create a post."""
     await self._login()
     # save item parts
     items = []
     for item in post.content:
         items.append(await self._save_item(item))
     # save new post
     data = self._build_post_data(post, items)
     url = "{}/{}".format(self.endpoint, "posts")
     return TargetResponse(await self._post(url, json.dumps(data), status=201))
예제 #8
0
    async def delete_item(self, post):
        id_at_target = self.get_id_at_target(post)
        if not id_at_target:
            logger.warning("Handling deleted item without TARGET-ID: [{}] on {}".format(post.id, self.target_id))
            return False

        url = "{}chat.delete".format(self.endpoint)
        data = await self._build_post_data({
            "ts": id_at_target,
        })
        return TargetResponse(await self._post(url, data))
예제 #9
0
    async def delete_item(self, post):
        event_id = self.get_event_id(post)
        if not event_id:
            logger.warning(
                "Handling deleted item without TARGET-ID: [{}, {}] on {}".
                format(self.target_id, self.target_local_id, post.id))
            return False

        delete_url = self._build_url("write/event/delete.json",
                                     {"event_local_id": event_id})
        response = await self._post(delete_url)
        return TargetResponse(response)
예제 #10
0
 async def test_handle_post_update(self):
     new_doc = TargetResponse({"doc": "foo"})
     self.post.get_action = MagicMock(return_value="update")
     self.target._handle_update = asynctest.CoroutineMock(return_value=new_doc)
     self.target.handle_extras = asynctest.CoroutineMock(return_value=None)
     self.target._db.update_post = asynctest.CoroutineMock(return_value=None)
     res = await self.target.handle_post(self.post)
     assert res is None
     self.target._handle_update.assert_called_once_with(self.post)
     self.target.handle_extras.assert_called_once_with(self.post)
     self.target._db.get_post.assert_called_once_with(self.target.target_id, self.post.id)
     self.target._get_converter.assert_called_once_with(self.post)
     assert self.target._db.update_post.call_count == 1
예제 #11
0
 async def update_item(self, post):
     """Build your request to update a post."""
     await self._login()
     # save item parts
     items = []
     for item in post.content:
         items.append(await self._save_item(item))
     data = self._build_post_data(post, items)
     # get id of post at target
     id_at_target = self.get_id_at_target(post)
     if not id_at_target:
         raise InvalidTargetResource("No id for resource at target found!")
     # patch existing post
     url = "{}/{}/{}".format(self.endpoint, "posts", id_at_target)
     return TargetResponse(await self._patch(url, json.dumps(data), etag=self.get_etag_at_target(post)))
예제 #12
0
    async def test_handle_post_without_converter(self):
        new_doc = TargetResponse({"doc": "foo"})
        self.post.get_action = MagicMock(return_value="create")
        self.target._handle_new = asynctest.CoroutineMock(return_value=new_doc)
        self.target.handle_extras = asynctest.CoroutineMock(return_value=None)
        self.target._db.insert_post = asynctest.CoroutineMock(return_value=None)
        self.target._get_converter = MagicMock(return_value=None)

        assert self.post.content == ""
        res = await self.target.handle_post(self.post)
        assert res is None
        self.target._handle_new.assert_called_once_with(self.post)
        self.target.handle_extras.assert_called_once_with(self.post)
        self.target._db.get_post.assert_called_once_with(self.target.target_id, self.post.id)
        assert self.target._db.insert_post.call_count == 1
        self.target._get_converter.assert_called_once_with(self.post)
        assert self.converter.convert.call_count == 0
        assert self.converter.remove_images.call_count == 0
        assert self.post.content == ""
예제 #13
0
 async def handle_extras(self, post):
     if self.get_id_at_target(post) and not post.is_deleted:
         return TargetResponse(await self._handle_sticky(post))
     return None
예제 #14
0
 async def post_item(self, post):
     await self._check_login()
     post_url = "{}/event/{}?".format(self.endpoint, self.event_id)
     return TargetResponse(await self._post(post_url, post.images, post.content))
 async def delete_item(self, post):
     """Build your request to update post at service."""
     delete_url = "/api/update"
     data = {"id": post.data.get("id")}
     return TargetResponse(await self._do_action(delete_url, data))
 async def post_item(self, post):
     """Build your request to create post at service."""
     create_url = "/api/create"
     data = {"text": post.content}
     return TargetResponse(await self._do_action(create_url, data))