Test that shares.json gets created

main
Bob Mottram 2021-08-04 13:44:24 +01:00
parent 0c0bcc371c
commit 9c435b9f7e
2 changed files with 17 additions and 7 deletions

View File

@ -172,8 +172,12 @@ def _dfcProductTypeFromCategory(itemCategory: str, translate: {}) -> str:
productTypesList = _dfcProductTypes() productTypesList = _dfcProductTypes()
categoryLower = itemCategory.lower() categoryLower = itemCategory.lower()
for productType in productTypesList: for productType in productTypesList:
if translate[productType] in categoryLower: if translate.get(productType):
return productType if translate[productType] in categoryLower:
return productType
else:
if productType in categoryLower:
return productType
return None return None

View File

@ -12,6 +12,7 @@ import os
import shutil import shutil
import json import json
import datetime import datetime
from shutil import copyfile
from random import randint from random import randint
from time import gmtime, strftime from time import gmtime, strftime
from pprint import pprint from pprint import pprint
@ -1463,10 +1464,11 @@ def testSharedItemsFederation():
print('\n\n*********************************************************') print('\n\n*********************************************************')
print('Bob publishes some shared items') print('Bob publishes some shared items')
copyfile(baseDir + '/img/logo.png', bobDir + '/logo.png')
sessionBob = createSession(proxyType) sessionBob = createSession(proxyType)
sharedItemName = 'cheddar' sharedItemName = 'cheddar'
sharedItemDescription = 'Some cheese' sharedItemDescription = 'Some cheese'
sharedItemImageFilename = 'img/logo.png' sharedItemImageFilename = 'logo.png'
sharedItemQty = 1 sharedItemQty = 1
sharedItemType = 'Cheese' sharedItemType = 'Cheese'
sharedItemCategory = 'Food' sharedItemCategory = 'Food'
@ -1489,7 +1491,7 @@ def testSharedItemsFederation():
assert isinstance(shareJson, dict) assert isinstance(shareJson, dict)
sharedItemName = 'Epicyon T-shirt' sharedItemName = 'Epicyon T-shirt'
sharedItemDescription = 'A fashionable item' sharedItemDescription = 'A fashionable item'
sharedItemImageFilename = 'img/logo.png' sharedItemImageFilename = 'logo.png'
sharedItemQty = 1 sharedItemQty = 1
sharedItemType = 'T-Shirt' sharedItemType = 'T-Shirt'
sharedItemCategory = 'Clothes' sharedItemCategory = 'Clothes'
@ -1512,7 +1514,7 @@ def testSharedItemsFederation():
assert isinstance(shareJson, dict) assert isinstance(shareJson, dict)
sharedItemName = 'Soldering iron' sharedItemName = 'Soldering iron'
sharedItemDescription = 'A soldering iron' sharedItemDescription = 'A soldering iron'
sharedItemImageFilename = 'img/logo.png' sharedItemImageFilename = 'logo.png'
sharedItemQty = 1 sharedItemQty = 1
sharedItemType = 'Soldering iron' sharedItemType = 'Soldering iron'
sharedItemCategory = 'Tools' sharedItemCategory = 'Tools'
@ -1534,15 +1536,19 @@ def testSharedItemsFederation():
assert shareJson assert shareJson
assert isinstance(shareJson, dict) assert isinstance(shareJson, dict)
time.sleep(2)
print('\n\n*********************************************************') print('\n\n*********************************************************')
print('Bob has a shares.json file') print('Bob has a shares.json file containing the uploaded items')
sharesFilename = bobDir + '/accounts/bob@' + bobDomain + '/shares.json' sharesFilename = bobDir + '/accounts/bob@' + bobDomain + '/shares.json'
assert os.path.isfile(sharesFilename) assert os.path.isfile(sharesFilename)
sharesJson = loadJson(sharesFilename)
assert sharesJson
pprint(sharesJson)
assert len(sharesJson.items()) == 3
print('\n\n*********************************************************') print('\n\n*********************************************************')
print('Bob can read the shared items catalog on his own instance') print('Bob can read the shared items catalog on his own instance')
time.sleep(10)
catalogJson = \ catalogJson = \
getSharedItemsCatalogViaServer(bobDir, sessionBob, 'bob', bobPassword, getSharedItemsCatalogViaServer(bobDir, sessionBob, 'bob', bobPassword,
bobDomain, bobPort, httpPrefix, True) bobDomain, bobPort, httpPrefix, True)