mirror of https://gitlab.com/bashrc2/epicyon
Create some test shares
parent
521f431764
commit
0c0bcc371c
46
shares.py
46
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,
|
||||
|
|
22
tests.py
22
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():
|
||||
|
|
Loading…
Reference in New Issue