Rather than creating demo scripts, it is considered a best practice to create a unit test. First, you need to import unittest and set up a test class that inherits from unittest.TestCase:. Create a file named test_product.py and place it in a directory structure named test/sweetscomplete/entity. As with our demo script mentioned previously, we use the os and sys modules to tell Python where to find the source code. We also import json, unittest, and our Product class:
# sweetscomplete.entity.product.Product test
import os,sys
sys.path.append(os.path.realpath("../../../src"))
import json
import unittest
from sweetscomplete.entity.product import Product
class TestProduct(unittest.TestCase) :
productFromDict = None
Next, you define a dictionary with fields that are populated with test data. The productFromDict property is then initialized in the test method, setUp():
testDict = dict({
'productKey' : &apos...