def setUp(self):
     self.productFromDict = Product(self.testDict)
     self.productDefaults = Product(True)
     self.productFromJson = Product(self.testJson)
class TestProduct(unittest.TestCase):

    productFromDict = None
    productDefaults = None
    productFromJson = None

    testDict = dict({
        'productKey': '00000000',
        'productPhoto': 'TEST',
        'skuNumber': 'TEST0000',
        'category': 'test',
        'title': 'Test',
        'description': 'test',
        'price': 1.11,
        'unit': 'test',
        'costPerUnit': 2.22,
        'unitsOnHand': 333
    })
    testJson = '''{
        "productKey"  : "00000000",
        "productPhoto": "TEST",
        "skuNumber"   : "TEST0000",
        "category"    : "test",
        "title"       : "Test",
        "description" : "test",
        "price"       : 1.11,
        "unit"        : "test",
        "costPerUnit" : 2.22,
        "unitsOnHand" : 333
    }'''

    def setUp(self):
        self.productFromDict = Product(self.testDict)
        self.productDefaults = Product(True)
        self.productFromJson = Product(self.testJson)

    def test_product_from_dict(self):
        expected = '00000000'
        actual = self.productFromDict.getKey()
        self.assertEqual(expected, actual)

    def test_product_from_dict_get_and_set(self):
        self.productFromDict.set('skuNumber', '99999999')
        expected = '99999999'
        actual = self.productFromDict.get('skuNumber')
        self.assertEqual(expected, actual)

    def test_product_from_dict_to_json(self):
        expected = json.loads(self.testJson)
        actual = json.loads(self.productFromDict.toJson())
        self.assertEqual(expected, actual)

    def test_product_from_json(self):
        expected = '00000000'
        actual = self.productFromJson.getKey()
        self.assertEqual(expected, actual)

    def test_product_from_blank(self):
        expected = ''
        actual = self.productDefaults.getKey()
        self.assertEqual(expected, actual)
Example #3
0
from sweetscomplete.entity.product import Product

# initialize test data
key = 'TEST' + date.today().isoformat().replace('-', '')
doc = dict({
    'productKey'  : key,
    'productPhoto': 'TEST',
    'skuNumber'   : 'TEST0000',
    'category'    : 'test',
    'title'       : 'Test',
    'description' : 'test',
    'price'       : 2.22,
    'unit'        : 'test',
    'costPerUnit' : 1.11,
    'unitsOnHand' : 333
})

# test blank product entity
product = Product(True)
print("\nBlank Product Entity")
print('Title: '   + product.getTitle())
print('Category: ' + product.get('category'))
print(product.toJson())

# test product entity initialized from a dictionary
product = Product(doc)
print("\nProduct Entity Initialized from Dictionary")
print('Title: '   + product.getTitle())
print('Category: ' + product.get('category'))
print(product.toJson())
        "category":"test",
        "title":"Test",
        "description":"test",
        "price":"1.11"
    },
    "InventoryInfo" : {
        "unit":"test",
        "costPerUnit":"2.22",
        "unitsOnHand":333
    }
}
'''.replace('%key%', key)

# adding a new product
print("\nAdding a Single Test Product\n")
product = Product(doc)
if service.addOne(product):
    print("\nProduct " + key + " added successfully\n")

# running a query for a single item
print("\nFetch Product by Key\n")
doc = service.fetchByKey(key)
if doc:
    print(doc.toJson())

# updating a single product
updateDoc = {
    'productPhoto': 'REVISED PHOTO',
    'MainProductInfo.price': 2.22
}
Example #5
0
# testing database connection to sweetscomplete.customer collection

# tell python where to find module source code
import os, sys
sys.path.append(os.path.realpath("src"))

import pprint
import db.mongodb.connection
from sweetscomplete.entity.product import Product

# setting up the connection + collection
conn = db.mongodb.connection.Connection('localhost', 27017, Product)
db = conn.getDatabase("sweetscomplete")

# testing blank entity
prod = Product(True)
print("\nResult from Query:")
print('Class: ' + str(type(prod)))
print('Key: ' + prod.getKey())
print('Title: ' + prod.getTitle())
print('Category' + prod.get('category'))
print('JSON:' + prod.toJson(['productPhoto']))

# testing products collection query
prod = db.products.find_one()
print("\nResult from Query:")
print('Class: ' + str(type(prod)))
print('Key: ' + prod.getKey())
print('Title: ' + prod.getTitle())
print('Category' + prod.get('category'))
print('JSON:' + prod.toJson(['productPhoto']))