From 0c0bcc371cd197881f2d75d47a47b15b283bb1a8 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 4 Aug 2021 13:04:35 +0100 Subject: [PATCH] Create some test shares --- shares.py | 46 ++++++++++++++++++++++++++++++++++++++++++++-- tests.py | 22 +++++++++++++++++++++- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/shares.py b/shares.py index 066c97bf1..c69b62bed 100644 --- a/shares.py +++ b/shares.py @@ -12,6 +12,7 @@ import re import secrets import time import datetime +from pprint import pprint from session import getJson from webfinger import webfingerHandle from auth import createBasicAuthHeader @@ -689,6 +690,41 @@ def sendUndoShareViaServer(baseDir: str, session, 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, nickname: str, domain: str, port: int, messageJson: {}, debug: bool, city: str, @@ -737,14 +773,20 @@ def outboxShareUpload(baseDir: str, httpPrefix: str, location = '' if messageJson['object'].get('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, httpPrefix, nickname, domain, port, messageJson['object']['displayName'], messageJson['object']['summary'], - messageJson['object']['imageFilename'], + imageFilename, itemQty, messageJson['object']['itemType'], - messageJson['object']['itemCategory'], + messageJson['object']['category'], location, messageJson['object']['duration'], debug, city, diff --git a/tests.py b/tests.py index 292cb4a7a..66793259b 100644 --- a/tests.py +++ b/tests.py @@ -140,6 +140,7 @@ from shares import createSharedItemFederationToken from shares import updateSharedItemFederationToken from shares import mergeSharedItemTokens from shares import sendShareViaServer +from shares import getSharedItemsCatalogViaServer testServerGroupRunning = False testServerAliceRunning = False @@ -1461,7 +1462,7 @@ def testSharedItemsFederation(): assert not isGroupActor(aliceDir, bobActor, alicePersonCache) print('\n\n*********************************************************') - print('Bob publishes a shared item') + print('Bob publishes some shared items') sessionBob = createSession(proxyType) sharedItemName = 'cheddar' sharedItemDescription = 'Some cheese' @@ -1533,6 +1534,23 @@ def testSharedItemsFederation(): assert shareJson 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('Alice sends a message to Bob') alicePostLog = [] @@ -1584,6 +1602,8 @@ def testSharedItemsFederation(): os.chdir(baseDir) shutil.rmtree(baseDir + '/.tests') + print('Testing federation of shared items between ' + + 'Alice and Bob is complete') def testGroupFollow():