'firstName'               : 'Fred',
    'lastName'                : 'Flintstone',
    'phoneNumber'             : '+1-222-333-4444',
    'email'                   : '*****@*****.**',
    'streetAddressOfBuilding' : '123 Rocky Way',
    'city'                    : 'Bedrock',
    'stateProvince'           : 'ZZ',
    'country'                 : 'ZZ',
    'postalCode'              : '00000',
    'latitude'                : 11.1111,
    'longitude'               : -11.1111,
    # products purchased
    'productsPurchased'       : prods_purchased
})

# test blank product entity
purchase = Purchase(True)
print("\nBlank Purchase Entity")
print('Transaction ID: ' + purchase.getKey())
print('Date: ' + purchase.get('dateOfPurchase'))
print('Customer: ' + purchase.getCustomerName())
print(purchase.toJson())

# test purchase entity initialized from dictionary
purchase = Purchase(doc)
print("\nPurchase Entity Initialized from Dictionary")
print('Transaction ID: ' + purchase.getKey())
print('Date: ' + purchase.get('dateOfPurchase'))
print('Customer: ' + purchase.getCustomerName())
print(purchase.toJson())
Пример #2
0
if 'purchase' in form:

    # establish date of purchase and purchase key
    import datetime
    import random
    today = datetime.datetime.today()
    dateOfPurchase = today.strftime('%Y-%m-%d %H:%M:%S')
    ymd = today.strftime('%Y%m%d')
    fname = cust.get('firstName')
    lname = cust.get('lastName')
    transactionId = ymd + fname[0:4] + lname[0:4] + str(random.randint(
        0, 9999))

    # create Purchase entity
    purchase = Purchase()
    purchase.set('transactionId', transactionId)
    purchase.set('dateOfPurchase', dateOfPurchase)

    # add customer info
    purchase.set('customerKey', cust.getKey())
    purchase.set('firstName', cust.get('firstName'))
    purchase.set('lastName', cust.get('lastName'))
    purchase.set('phoneNumber', cust.get('phoneNumber'))
    purchase.set('email', cust.get('email'))
    purchase.set('streetAddressOfBuilding',
                 cust.get('streetAddressOfBuilding'))
    purchase.set('city', cust.get('city'))
    purchase.set('stateProvince', cust.get('stateProvince'))
    purchase.set('locality', cust.get('locality'))
    purchase.set('country', cust.get('country'))
Пример #3
0
 def setUp(self):
     self.purchaseFromDict = Purchase(self.testDict)
     self.purchaseDefaults = Purchase(True)
     self.purchaseFromJson = Purchase(self.testJson)
Пример #4
0
			"productKey" : "valentines_day_chocolate_pack",
			"qtyPurchased" : 434,
			"MainProductInfo" : {
				"skuNumber" : "VALE270",
				"category" : "chocolate",
				"title" : "Valentines Day Chocolate Pack",
				"description" : "Nam gravida libero ac malesuada cursus. Vivamus semper justo sed dictum aliquam.",
				"price" : 19.99
			}
		}
	]
}'''.replace('%key%', key).replace('%date%', dateOfPurchase)

# adding a new purchase
print("Adding a Single Test Purchase")
if service.addOne(Purchase(doc)):
    print("Purchase " + key + " added successfully")

# running a query for a single item
print("\nFetch Purchase by Key")
doc = service.fetchByKey(key)
if doc:
    print(doc.toJson())
else:
    print("Unable to find purchase " + key + "\n")
"""
# updating a single purchase
updateDoc = {
    'purchasePhoto' :'REVISED PHOTO',
    'MainPurchaseInfo.price' : 2.22
};
# 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 db.mongodb.connection
from sweetscomplete.entity.purchase import Purchase

# testing blank purchase entity
purch = Purchase(True)
print("\nBlank Entity:")
print('Class: '    + str(type(purch)))
print('Key: '      + purch.getKey())
print('Customer: ' + purch.getCustomer())
print('Date: '     + purch.get('dateOfPurchase'))
print('JSON:'      + purch.toJson())

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

# testing purchases collection query
purch = db.purchases.find_one()
print("\nResult from Query:")
print('Class: '    + str(type(purch)))
print('Key: '      + purch.getKey())
print('Customer: ' + purch.getCustomer())
print('Date: '     + purch.get('dateOfPurchase'))
print('JSON:'      + purch.toJson())