Commit 39ff028c authored by Joan Pascual Sana's avatar Joan Pascual Sana

Write tests: create post with files

parent aa0df326
......@@ -17,7 +17,8 @@ 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"""
......@@ -31,7 +32,25 @@ class TestReqRsFilesAddSharedDirectory(unittest.TestCase):
def testReqRsFilesAddSharedDirectory(self):
"""Test ReqRsFilesAddSharedDirectory"""
# FIXME: construct object with mandatory attributes with example values
# model = openapi_client.models.req_rs_files_add_shared_directory.ReqRsFilesAddSharedDirectory() # noqa: E501
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
......
......@@ -17,11 +17,43 @@ 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
......@@ -30,8 +62,50 @@ class TestReqRsGxsChannelsCreatePost(unittest.TestCase):
def testReqRsGxsChannelsCreatePost(self):
"""Test ReqRsGxsChannelsCreatePost"""
# FIXME: construct object with mandatory attributes with example values
# model = openapi_client.models.req_rs_gxs_channels_create_post.ReqRsGxsChannelsCreatePost() # noqa: E501
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
......
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