Commit 86ce3fad authored by Joan Pascual Sana's avatar Joan Pascual Sana

Create own_test folder

parent 250e26b0
......@@ -24,4 +24,5 @@
.gitignore
test/__init__.py
wiki.md
\ No newline at end of file
wiki.md
own_test/
\ No newline at end of file
import openapi_client
configuration = openapi_client.Configuration()
# Configure HTTP basic authorization: BasicAuth
configuration.username = 'test'
configuration.password = 'test'
# Create an instance of the API class
API_INSTANCE = openapi_client.DefaultApi(openapi_client.ApiClient(configuration))
\ No newline at end of file
# coding: utf-8
"""
RetroShare OpenApi wrapper
RetroShare OpenApi wrapper generated using Doxygen documentation # noqa: E501
The version of the OpenAPI document: 0.0.1
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import openapi_client
from openapi_client.models.req_json_api_server_authorize_token import ReqJsonApiServerAuthorizeToken # noqa: E501
from openapi_client.rest import ApiException
class TestReqJsonApiServerVersion(unittest.TestCase):
"""ReqJsonApiServerAuthorizeToken unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def testReqJsonApiServerVersion(self):
"""Test ReqJsonApiServerVersion"""
# Create an instance of the API class
api_instance = openapi_client.DefaultApi()
try:
# Write version information to given paramethers
api_response = api_instance.json_api_server_version()
print(api_response)
except ApiException as e:
print("Exception when calling DefaultApi->json_api_server_version: %s\n" % e)
# FIXME: construct object with mandatory attributes with example values
# model = openapi_client.models.req_json_api_server_authorize_token.ReqJsonApiServerAuthorizeToken() # noqa: E501
pass
if __name__ == '__main__':
unittest.main()
# coding: utf-8
"""
RetroShare OpenApi wrapper
RetroShare OpenApi wrapper generated using Doxygen documentation # noqa: E501
The version of the OpenAPI document: 0.0.1
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import openapi_client
from openapi_client.models.req_rs_files_add_shared_directory import ReqRsFilesAddSharedDirectory # noqa: E501
from openapi_client.rest import ApiException
from test import API_INSTANCE
from openapi_client.models.shared_dir_info import SharedDirInfo
class TestReqRsFilesAddSharedDirectory(unittest.TestCase):
"""ReqRsFilesAddSharedDirectory unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def testReqRsFilesAddSharedDirectory(self):
"""Test ReqRsFilesAddSharedDirectory"""
# FIXME: construct object with mandatory attributes with example values
api_instance = API_INSTANCE
filename = "/tmp"
virtualname = "tmpTest"
shareflags = 128 # For share flags see FileStorageFlags
dir = SharedDirInfo(filename=filename, virtualname=virtualname,
shareflags=shareflags)
req_rs_files_add_shared_directory = {
"dir": dir} # ReqRsFilesAddSharedDirectory | dir: ( SharedDirInfo)directory to share with sharing options (optional)
try:
# Add shared directory
api_response = api_instance.rs_files_add_shared_directory(
req_rs_files_add_shared_directory=req_rs_files_add_shared_directory)
print(api_response)
except ApiException as e:
print("Exception when calling DefaultApi->rs_files_add_shared_directory: %s\n" % e)
pass
if __name__ == '__main__':
unittest.main()
# coding: utf-8
"""
RetroShare OpenApi wrapper
RetroShare OpenApi wrapper generated using Doxygen documentation # noqa: E501
The version of the OpenAPI document: 0.0.1
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import openapi_client
from openapi_client.models.req_rs_gxs_channels_create_channel import ReqRsGxsChannelsCreateChannel # noqa: E501
from openapi_client.rest import ApiException
from test import API_INSTANCE
from openapi_client.models.rs_gxs_channel_group import RsGxsChannelGroup
from openapi_client.models.rs_group_meta_data import RsGroupMetaData
class TestReqRsGxsChannelsCreateChannel(unittest.TestCase):
"""ReqRsGxsChannelsCreateChannel unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def testReqRsGxsChannelsCreateChannel(self):
"""Test ReqRsGxsChannelsCreateChannel"""
# FIXME: construct object with mandatory attributes with example values
api_instance = API_INSTANCE
groupMetada = RsGroupMetaData(m_group_name="Test channel with File Upload", m_group_flags=4, m_sign_flags=520)
channel = RsGxsChannelGroup(m_meta=groupMetada, m_description="This channel contain a post with a file")
# req_rs_gxs_channels_create_channel = {
# "channel": channel} # ReqRsGxsChannelsCreateChannel | channel: ( RsGxsChannelGroup)Channel data (name, description...) (optional)
model = openapi_client.models.req_rs_gxs_channels_create_channel.ReqRsGxsChannelsCreateChannel(channel= channel) # noqa: E501
try:
# Deprecated{ substituted by createChannelV2 }
api_response = api_instance.rs_gxs_channels_create_channel(
req_rs_gxs_channels_create_channel=model)
print(api_response)
except ApiException as e:
print("Exception when calling DefaultApi->rs_gxs_channels_create_channel: %s\n" % e)
pass
if __name__ == '__main__':
unittest.main()
# coding: utf-8
"""
RetroShare OpenApi wrapper
RetroShare OpenApi wrapper generated using Doxygen documentation # noqa: E501
The version of the OpenAPI document: 0.0.1
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import openapi_client
from openapi_client.models.req_rs_gxs_channels_create_channel_v2 import ReqRsGxsChannelsCreateChannelV2 # noqa: E501
from openapi_client.rest import ApiException
from test import API_INSTANCE
class TestReqRsGxsChannelsCreateChannelV2(unittest.TestCase):
"""ReqRsGxsChannelsCreateChannelV2 unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def testReqRsGxsChannelsCreateChannelV2(self):
"""Test ReqRsGxsChannelsCreateChannelV2"""
api_instance = API_INSTANCE
req_rs_gxs_channels_create_channel_v2 = {"name": "TestChannelV2 1",
"description": "( string)Description of the channel",
# "thumbnail": "( RsGxsImage)Optional image to show as channel thumbnail.",
# "authorId": "( RsGxsId)Optional id of the author. Leave empty for an anonymous channel.",
# "circleType": "( RsGxsCircleType)Optional visibility rule, default public.",
# "circleId": "( RsGxsCircleId)If the channel is not public specify the id of the circle who can see the channel. Depending on the value you pass for circleType this should be be an external circle if EXTERNAL is passed, a local friend group id if NODES_GROUP is passed, empty otherwise."
} # ReqRsGxsChannelsCreateChannelV2 | name: ( string)Name of the channel description: ( string)Description of the channel thumbnail: ( RsGxsImage)Optional image to show as channel thumbnail. authorId: ( RsGxsId)Optional id of the author. Leave empty for an anonymous channel. circleType: ( RsGxsCircleType)Optional visibility rule, default public. circleId: ( RsGxsCircleId)If the channel is not public specify the id of the circle who can see the channel. Depending on the value you pass for circleType this should be be an external circle if EXTERNAL is passed, a local friend group id if NODES_GROUP is passed, empty otherwise. (optional)
try:
# Create channel. Blocking API.
api_response = api_instance.rs_gxs_channels_create_channel_v2(
req_rs_gxs_channels_create_channel_v2=req_rs_gxs_channels_create_channel_v2)
print(api_response)
except ApiException as e:
print("Exception when calling DefaultApi->rs_gxs_channels_create_channel_v2: %s\n" % e)
pass
if __name__ == '__main__':
unittest.main()
# coding: utf-8
"""
RetroShare OpenApi wrapper
RetroShare OpenApi wrapper generated using Doxygen documentation # noqa: E501
The version of the OpenAPI document: 0.0.1
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import openapi_client
from openapi_client.models.req_rs_gxs_channels_create_post import ReqRsGxsChannelsCreatePost # noqa: E501
from openapi_client.rest import ApiException
from test import API_INSTANCE
from openapi_client.models.req_rs_gxs_channels_create_post import ReqRsGxsChannelsCreatePost
from openapi_client.models.rs_gxs_channel_post import RsGxsChannelPost
from openapi_client.models.rs_msg_meta_data import RsMsgMetaData
from openapi_client.models.rs_gxs_file import RsGxsFile
import os, hashlib
class TestReqRsGxsChannelsCreatePost(unittest.TestCase):
"""ReqRsGxsChannelsCreatePost unit test stubs"""
def getFileBytes(self, f):
return os.path.getsize(f)
# From https://stackoverflow.com/questions/22058048/hashing-a-file-in-python
def getSha1Sum(self, f):
# BUF_SIZE is totally arbitrary, change for your app!
BUF_SIZE = 65536 # lets read stuff in 64kb chunks!
sha1 = hashlib.sha1()
with open(f, 'rb') as file:
while True:
data = file.read(BUF_SIZE)
if not data:
break
sha1.update(data)
return sha1.hexdigest()
def getRsFile(self, filePath):
fh = open(filePath, 'r')
fByteSize = self.getFileBytes(filePath)
sha1sum = self.getSha1Sum(filePath)
return RsGxsFile(
m_name=filePath,
m_hash=str(sha1sum),
m_size=fByteSize
)
def setUp(self):
pass
def tearDown(self):
pass
def testReqRsGxsChannelsCreatePost(self):
"""Test ReqRsGxsChannelsCreatePost"""
api_instance = API_INSTANCE
# Get the channel id using it title
chanId = None
targetChannelTitle = "Test channel with File Upload"
channels = api_instance.rs_gxs_channels_get_channels_summaries()
for channel in channels["channels"]:
if channel["mGroupName"] in targetChannelTitle:
chanId = channel["mGroupId"]
if chanId is None:
raise Exception("Channel not found")
# Create channel metadata
postTitle = "This is the post title"
postDescription = "Description of the post"
meta = RsMsgMetaData(m_group_id=chanId,
m_msg_name=postTitle,
m_msg_flags=0,)
# Get the apropiate RsGxsFile for each file
fileList = ["/tmp/file1", "/tmp/file2"]
mfiles = []
for f in fileList:
mfiles.append(self.getRsFile(f))
# Create the post object
post = RsGxsChannelPost(m_meta=meta,
m_msg=postDescription,
m_files=mfiles)
# Create the request object
req = ReqRsGxsChannelsCreatePost(post=post)
try:
# Deprecated
api_response = api_instance.rs_gxs_channels_create_post(
req_rs_gxs_channels_create_post=req)
print(api_response)
except ApiException as e:
print("Exception when calling DefaultApi->rs_gxs_channels_create_post: %s\n" % e)
pass
if __name__ == '__main__':
unittest.main()
# coding: utf-8
"""
RetroShare OpenApi wrapper
RetroShare OpenApi wrapper generated using Doxygen documentation # noqa: E501
The version of the OpenAPI document: 0.0.1
Generated by: https://openapi-generator.tech
"""
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"""
def setUp(self):
pass
def tearDown(self):
pass
def testReqRsGxsChannelsCreatePostV2(self):
"""Test ReqRsGxsChannelsCreatePostV2"""
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
if __name__ == '__main__':
unittest.main()
# coding: utf-8
"""
RetroShare OpenApi wrapper
RetroShare OpenApi wrapper generated using Doxygen documentation # noqa: E501
The version of the OpenAPI document: 0.0.1
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import openapi_client
from openapi_client.models.req_rs_gxs_channels_get_channels_info import ReqRsGxsChannelsGetChannelsInfo # noqa: E501
from openapi_client.rest import ApiException
from openapi_client.models.req_rs_gxs_channels_get_channels_info import ReqRsGxsChannelsGetChannelsInfo
from test import API_INSTANCE
class TestReqRsGxsChannelsGetChannelsInfo(unittest.TestCase):
"""ReqRsGxsChannelsGetChannelsInfo unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def testReqRsGxsChannelsGetChannelsInfo(self):
"""Test ReqRsGxsChannelsGetChannelsInfo"""
# FIXME: construct object with mandatory attributes with example values
# model = openapi_client.models.req_rs_gxs_channels_get_channels_info.ReqRsGxsChannelsGetChannelsInfo() # noqa: E501
api_instance = API_INSTANCE
chanIds = ["20fee40b844cf68caaf87f5db23c8112"]
# req_rs_gxs_channels_get_channels_info = {
# "chanIds": channelsList } # ReqRsGxsChannelsGetChannelsInfo | chanIds: ( list<RsGxsGroupId>)ids of the channels of which to get the informations (optional)
chanIds = "20fee40b844cf68caaf87f5db23c8112"
req_rs_gxs_channels_get_channels_info = ReqRsGxsChannelsGetChannelsInfo(chan_ids = [chanIds])
try:
# Get channels information (description, thumbnail...). Blocking API.
api_response = api_instance.rs_gxs_channels_get_channels_info(
req_rs_gxs_channels_get_channels_info=req_rs_gxs_channels_get_channels_info)
print(api_response)
except ApiException as e:
print("Exception when calling DefaultApi->rs_gxs_channels_get_channels_info: %s\n" % e)
pass
if __name__ == '__main__':
unittest.main()
# coding: utf-8
"""
RetroShare OpenApi wrapper
RetroShare OpenApi wrapper generated using Doxygen documentation # noqa: E501
The version of the OpenAPI document: 0.0.1
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import openapi_client
from openapi_client.models.req_rs_gxs_channels_get_content_summaries import ReqRsGxsChannelsGetContentSummaries # noqa: E501
from openapi_client.rest import ApiException
from test import API_INSTANCE
class TestReqRsGxsChannelsGetChannelsSummaries(unittest.TestCase):
"""ReqRsGxsChannelsGetChannelsSummaries unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def testReqRsGxsChannelsGetChannelsSummaries(self):
api_instance = API_INSTANCE
try:
# Get channels summaries list. Blocking API.
api_response = api_instance.rs_gxs_channels_get_channels_summaries()
print(api_response)
except ApiException as e:
print("Exception when calling DefaultApi->rs_gxs_channels_get_channels_summaries: %s\n" % e)
pass
if __name__ == '__main__':
unittest.main()
# coding: utf-8
"""
RetroShare OpenApi wrapper
RetroShare OpenApi wrapper generated using Doxygen documentation # noqa: E501
The version of the OpenAPI document: 0.0.1
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import openapi_client
from openapi_client.models.req_rs_identity_create_identity import ReqRsIdentityCreateIdentity # noqa: E501
from openapi_client.rest import ApiException
from test import API_INSTANCE
class TestReqRsIdentityCreateIdentity(unittest.TestCase):
"""ReqRsIdentityCreateIdentity unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def testReqRsIdentityCreateIdentity(self):
"""Test ReqRsIdentityCreateIdentity"""
api_instance = API_INSTANCE
req_rs_identity_create_identity = {"name": "AnonymousIdTest1",
# "avatar": "( RsGxsImage)Image associated to the identity",
"pseudonimous": True,
# "pgpPassword": "( string)password to unlock PGP to sign identity, not implemented yet"
} # ReqRsIdentityCreateIdentity | name: ( string)Name of the identity avatar: ( RsGxsImage)Image associated to the identity pseudonimous: ( boolean)true for unsigned identity, false otherwise pgpPassword: ( string)password to unlock PGP to sign identity, not implemented yet (optional)
try:
# Create a new identity
api_response = api_instance.rs_identity_create_identity(
req_rs_identity_create_identity=req_rs_identity_create_identity)
print(api_response)
except ApiException as e:
print("Exception when calling DefaultApi->rs_identity_create_identity: %s\n" % e)
pass
if __name__ == '__main__':
unittest.main()
# coding: utf-8
"""
RetroShare OpenApi wrapper
RetroShare OpenApi wrapper generated using Doxygen documentation # noqa: E501
The version of the OpenAPI document: 0.0.1
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import openapi_client
from openapi_client.models.req_rs_identity_update_identity import ReqRsIdentityUpdateIdentity # noqa: E501
from openapi_client.rest import ApiException
# Used to update the identity
from openapi_client.models.rs_gxs_id_group import RsGxsIdGroup
from openapi_client.models.rs_group_meta_data import RsGroupMetaData
# Used to get identity info
from openapi_client.models.req_rs_identity_get_identities_info import ReqRsIdentityGetIdentitiesInfo
from test import API_INSTANCE
class TestReqRsIdentityUpdateIdentity(unittest.TestCase):
"""ReqRsIdentityUpdateIdentity unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def testReqRsIdentityUpdateIdentity(self):
"""Test ReqRsIdentityUpdateIdentity"""
api_instance = API_INSTANCE
# Get all identities info for debugging
# try:
# Get identities summaries list.
# api_response = api_instance.rs_identity_get_own_signed_ids()
# Could be also
# api_response = api_instance.rs_identity_get_identities_summaries()
# print(api_response)
# except ApiException as e:
# print("Exception when calling DefaultApi->rs_identity_get_identities_summaries: %s\n" % e)
# Get the RsGxsIdGroup data for the wanted identity
reqId = 'a96d9b1a009bb96ea6fdd0be053e44c4'
req_rs_identity_get_identities_info = {"ids": [reqId]}
try:
# Get identities information (name, avatar...). Blocking API.
api_response = api_instance.rs_identity_get_identities_info(
req_rs_identity_get_identities_info=req_rs_identity_get_identities_info)
# print(api_response)
except ApiException as e:
print("Exception when calling DefaultApi->rs_identity_get_identities_info: %s\n" % e)
# Now lets get the RsGxsIdGroup object from the array of returned ids
for id in api_response['idsInfo']:
if id['mMeta']['mGroupId'] == reqId:
reqId = id
# Now modify the desired components
print(reqId)
reqId['mMeta']['mGroupName'] = 'AnonymousIdTest2'
# This won't work because the API return the info on camelCase and the object attrs are stored in snake_case
# Todo: modify the openapi generator python template to be camelCase only (to unify with RS project)
# Todo: support to return objects using [out] params on the template generation
# rsGxsIdGroup = RsGxsIdGroup(reqId)
# rsGroupMetaData = RsGroupMetaData(rsGxsIdGroup.m_meta)
# Send the object
req_rs_identity_update_identity = {
"identityData": reqId} # ReqRsIdentityUpdateIdentity | identityData: ( RsGxsIdGroup)updated identiy data (optional)
try: