Create some test shares

merge-requests/30/head
Bob Mottram 2021-08-04 13:04:35 +01:00
parent 521f431764
commit 0c0bcc371c
2 changed files with 65 additions and 3 deletions

View File

@ -12,6 +12,7 @@ import re
import secrets import secrets
import time import time
import datetime import datetime
from pprint import pprint
from session import getJson from session import getJson
from webfinger import webfingerHandle from webfinger import webfingerHandle
from auth import createBasicAuthHeader from auth import createBasicAuthHeader
@ -689,6 +690,41 @@ def sendUndoShareViaServer(baseDir: str, session,
return undoShareJson return undoShareJson
def getSharedItemsCatalogViaServer(baseDir, session,
nickname: str, password: str,
domain: str, port: int,
httpPrefix: str, debug: bool) -> {}:
"""Returns the shared items catalog via c2s
"""
if not session:
print('WARN: No session for getSharedItemsCatalogViaServer')
return 6
authHeader = createBasicAuthHeader(nickname, password)
headers = {
'host': domain,
'Content-type': 'application/json',
'Authorization': authHeader,
'Accept': 'application/json'
}
domainFull = getFullDomain(domain, port)
url = httpPrefix + '://' + domainFull + '/users/' + nickname + '/catalog'
if debug:
print('Shared items catalog request to: ' + url)
catalogJson = getJson(session, url, headers, None, debug,
__version__, httpPrefix, None)
if not catalogJson:
if debug:
print('DEBUG: GET shared items catalog failed for c2s to ' + url)
# return 5
if debug:
print('DEBUG: c2s GET shared items catalog success')
return catalogJson
def outboxShareUpload(baseDir: str, httpPrefix: str, def outboxShareUpload(baseDir: str, httpPrefix: str,
nickname: str, domain: str, port: int, nickname: str, domain: str, port: int,
messageJson: {}, debug: bool, city: str, messageJson: {}, debug: bool, city: str,
@ -737,14 +773,20 @@ def outboxShareUpload(baseDir: str, httpPrefix: str,
location = '' location = ''
if messageJson['object'].get('location'): if messageJson['object'].get('location'):
location = messageJson['object']['location'] location = messageJson['object']['location']
imageFilename = None
if messageJson['object'].get('imageFilename'):
imageFilename = messageJson['object']['imageFilename']
if debug:
print('Adding shared item')
pprint(messageJson)
addShare(baseDir, addShare(baseDir,
httpPrefix, nickname, domain, port, httpPrefix, nickname, domain, port,
messageJson['object']['displayName'], messageJson['object']['displayName'],
messageJson['object']['summary'], messageJson['object']['summary'],
messageJson['object']['imageFilename'], imageFilename,
itemQty, itemQty,
messageJson['object']['itemType'], messageJson['object']['itemType'],
messageJson['object']['itemCategory'], messageJson['object']['category'],
location, location,
messageJson['object']['duration'], messageJson['object']['duration'],
debug, city, debug, city,

View File

@ -140,6 +140,7 @@ from shares import createSharedItemFederationToken
from shares import updateSharedItemFederationToken from shares import updateSharedItemFederationToken
from shares import mergeSharedItemTokens from shares import mergeSharedItemTokens
from shares import sendShareViaServer from shares import sendShareViaServer
from shares import getSharedItemsCatalogViaServer
testServerGroupRunning = False testServerGroupRunning = False
testServerAliceRunning = False testServerAliceRunning = False
@ -1461,7 +1462,7 @@ def testSharedItemsFederation():
assert not isGroupActor(aliceDir, bobActor, alicePersonCache) assert not isGroupActor(aliceDir, bobActor, alicePersonCache)
print('\n\n*********************************************************') print('\n\n*********************************************************')
print('Bob publishes a shared item') print('Bob publishes some shared items')
sessionBob = createSession(proxyType) sessionBob = createSession(proxyType)
sharedItemName = 'cheddar' sharedItemName = 'cheddar'
sharedItemDescription = 'Some cheese' sharedItemDescription = 'Some cheese'
@ -1533,6 +1534,23 @@ def testSharedItemsFederation():
assert shareJson assert shareJson
assert isinstance(shareJson, dict) assert isinstance(shareJson, dict)
print('\n\n*********************************************************')
print('Bob has a shares.json file')
sharesFilename = bobDir + '/accounts/bob@' + bobDomain + '/shares.json'
assert os.path.isfile(sharesFilename)
print('\n\n*********************************************************')
print('Bob can read the shared items catalog on his own instance')
time.sleep(10)
catalogJson = \
getSharedItemsCatalogViaServer(bobDir, sessionBob, 'bob', bobPassword,
bobDomain, bobPort, httpPrefix, True)
assert catalogJson
pprint(catalogJson)
assert 'DFC:supplies' in catalogJson
assert len(catalogJson.get('DFC:supplies')) == 3
print('\n\n*********************************************************') print('\n\n*********************************************************')
print('Alice sends a message to Bob') print('Alice sends a message to Bob')
alicePostLog = [] alicePostLog = []
@ -1584,6 +1602,8 @@ def testSharedItemsFederation():
os.chdir(baseDir) os.chdir(baseDir)
shutil.rmtree(baseDir + '/.tests') shutil.rmtree(baseDir + '/.tests')
print('Testing federation of shared items between ' +
'Alice and Bob is complete')
def testGroupFollow(): def testGroupFollow():