From 9c435b9f7ef1b0a17b22e5c3520691bf7c89026f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 4 Aug 2021 13:44:24 +0100 Subject: [PATCH] Test that shares.json gets created --- shares.py | 8 ++++++-- tests.py | 16 +++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/shares.py b/shares.py index c69b62bed..515262689 100644 --- a/shares.py +++ b/shares.py @@ -172,8 +172,12 @@ def _dfcProductTypeFromCategory(itemCategory: str, translate: {}) -> str: productTypesList = _dfcProductTypes() categoryLower = itemCategory.lower() for productType in productTypesList: - if translate[productType] in categoryLower: - return productType + if translate.get(productType): + if translate[productType] in categoryLower: + return productType + else: + if productType in categoryLower: + return productType return None diff --git a/tests.py b/tests.py index 66793259b..e2e438acf 100644 --- a/tests.py +++ b/tests.py @@ -12,6 +12,7 @@ import os import shutil import json import datetime +from shutil import copyfile from random import randint from time import gmtime, strftime from pprint import pprint @@ -1463,10 +1464,11 @@ def testSharedItemsFederation(): print('\n\n*********************************************************') print('Bob publishes some shared items') + copyfile(baseDir + '/img/logo.png', bobDir + '/logo.png') sessionBob = createSession(proxyType) sharedItemName = 'cheddar' sharedItemDescription = 'Some cheese' - sharedItemImageFilename = 'img/logo.png' + sharedItemImageFilename = 'logo.png' sharedItemQty = 1 sharedItemType = 'Cheese' sharedItemCategory = 'Food' @@ -1489,7 +1491,7 @@ def testSharedItemsFederation(): assert isinstance(shareJson, dict) sharedItemName = 'Epicyon T-shirt' sharedItemDescription = 'A fashionable item' - sharedItemImageFilename = 'img/logo.png' + sharedItemImageFilename = 'logo.png' sharedItemQty = 1 sharedItemType = 'T-Shirt' sharedItemCategory = 'Clothes' @@ -1512,7 +1514,7 @@ def testSharedItemsFederation(): assert isinstance(shareJson, dict) sharedItemName = 'Soldering iron' sharedItemDescription = 'A soldering iron' - sharedItemImageFilename = 'img/logo.png' + sharedItemImageFilename = 'logo.png' sharedItemQty = 1 sharedItemType = 'Soldering iron' sharedItemCategory = 'Tools' @@ -1534,15 +1536,19 @@ def testSharedItemsFederation(): assert shareJson assert isinstance(shareJson, dict) + time.sleep(2) 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' assert os.path.isfile(sharesFilename) + sharesJson = loadJson(sharesFilename) + assert sharesJson + pprint(sharesJson) + assert len(sharesJson.items()) == 3 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)