Commit 250e26b0 authored by Joan Pascual Sana's avatar Joan Pascual Sana

Write tests: modify a post with thumbnail

parent c402b30c
......@@ -15,9 +15,15 @@ from __future__ import absolute_import
import unittest
import openapi_client
from openapi_client.models import req_rs_gxs_channels_get_channels_info
from openapi_client.models.req_rs_gxs_channels_create_post_v2 import ReqRsGxsChannelsCreatePostV2 # noqa: E501
from openapi_client.rest import ApiException
from test import API_INSTANCE
from openapi_client.models.req_rs_gxs_channels_create_post_v2 import ReqRsGxsChannelsCreatePostV2
from openapi_client.models.rs_gxs_channel_group import RsGxsChannelGroup
from openapi_client.models.req_rs_gxs_channels_get_channels_info import ReqRsGxsChannelsGetChannelsInfo
from openapi_client.models.rs_msg_meta_data import RsMsgMetaData
import base64
class TestReqRsGxsChannelsCreatePostV2(unittest.TestCase):
"""ReqRsGxsChannelsCreatePostV2 unit test stubs"""
......@@ -30,8 +36,72 @@ class TestReqRsGxsChannelsCreatePostV2(unittest.TestCase):
def testReqRsGxsChannelsCreatePostV2(self):
"""Test ReqRsGxsChannelsCreatePostV2"""
# FIXME: construct object with mandatory attributes with example values
# model = openapi_client.models.req_rs_gxs_channels_create_post_v2.ReqRsGxsChannelsCreatePostV2() # noqa: E501
api_instance = API_INSTANCE
req = ReqRsGxsChannelsCreatePostV2()
# Used to get the channel that we want to modify
# resp = api_instance.rs_gxs_channels_get_channels_summaries()
# for channel in resp.channels:
# print(channel)
# The id of the channel to modify
channelId = "21add155d4d2f015d19ddbd3bb4598dc"
req = ReqRsGxsChannelsGetChannelsInfo(chan_ids=[channelId])
# req = {"chanIds": [channelId]}
# Get a channel object
channelsInfoResponse = api_instance.rs_gxs_channels_get_channels_info(req_rs_gxs_channels_get_channels_info=req)
channelToModify = RsGxsChannelGroup(channelsInfoResponse.channels_info[0]) # Not work properly, bad m_meta assignation
# Get channel posts
req_rs_gxs_channels_get_content_summaries = {
"channelId": channelId}
channelPostsSummariesResponse = api_instance.rs_gxs_channels_get_content_summaries(
req_rs_gxs_channels_get_content_summaries=req_rs_gxs_channels_get_content_summaries)
rsMsgMeta = RsMsgMetaData(channelPostsSummariesResponse.summaries[0]) # Don't work, bad assignment
rsMsgMeta = channelPostsSummariesResponse.summaries[0]
# Get the info of the post
req_rs_gxs_channels_get_channel_content = {
"channelId": channelId,
"contentsIds": [rsMsgMeta.m_msg_id]
} # ReqRsGxsChannelsGetChannelContent | channelId: ( RsGxsGroupId)id of the channel of which the content is requested contentsIds: ( set<RsGxsMessageId>)ids of requested contents (optional)
channelContentResponse = api_instance.rs_gxs_channels_get_channel_content(req_rs_gxs_channels_get_channel_content=req_rs_gxs_channels_get_channel_content)
print(channelContentResponse)
## Modify the post with an image
# Get the new image
# TODO: The image thumbnail set doesn't work
imgPath = '/tmp/test.png'
# Encode it to base64
with open(imgPath, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read())
# Encode it to utf8 string
b64imgstr = encoded_string.decode('utf-8')
print(b64imgstr)
req_rs_gxs_channels_create_post_v2 = {
"channelId": channelId,
"title": "This is the post title modified",
"mBody": "( string)Text content of the post",
# "files": "( list<RsGxsFile>)Optional list of attached files. These are supposed to be already shared,",
"thumbnail": b64imgstr,
"origPostId": rsMsgMeta.m_msg_id
} # ReqRsGxsChannelsCreatePostV2 | channelId: ( RsGxsGroupId)Id of the channel where to put the post. Beware you need publish rights on that channel to post. title: ( string)Title of the post mBody: ( string)Text content of the post files: ( list<RsGxsFile>)Optional list of attached files. These are supposed to be already shared, thumbnail: ( RsGxsImage)Optional thumbnail image for the post. origPostId: ( RsGxsMessageId)If this is supposed to replace an already existent post, the id of the old post. If left blank a new post will be created. (optional)
# print(req_rs_gxs_channels_create_post_v2)
# try:
# # Create channel post. Blocking API.
# api_response = api_instance.rs_gxs_channels_create_post_v2(
# req_rs_gxs_channels_create_post_v2=req_rs_gxs_channels_create_post_v2)
# print(api_response)
# except ApiException as e:
# print("Exception when calling DefaultApi->rs_gxs_channels_get_content_summaries: %s\n" % e)
pass
......
......@@ -28,6 +28,8 @@ Here some test examples to follow:
this have also an example of how to loop through channel summaries.
* [Create an identity](test/test_req_rs_identity_create_identity.py) or
[update it](test/test_req_rs_identity_update_identity.py).
* [Modify a post and add a thumbnail](test/test_req_rs_gxs_channels_create_post_v2.py).
Here we can see the process to add a base64 image.
## File uploads
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment