def storyProviderEditPending(db, test, story, items, pid):
    printHeader(story)

    # Add five randomized donations and print the contents of the first
    dids = []
    for i in range(5):
        dids.append(addDonationRandom(db, pid, None, items, 5, 7))
    did = dids[0]
    print('DONATION {0} ITEMS'.format(did).center(80))
    itemList = getDonationItems(db, did)
    printDonationItems(itemList)
    print('')

    # Update a random item count in first donation and print result
    iid = editDonationRandom(db, test, did, False)
    if iid < 1:
        print('ITEM EDIT FAILED: MODIFY COUNT'.center(80))
    else:
        print('DONATION {0} ITEMS (modified item {1} count)'.format(
            did, iid).center(80))
        itemList = getDonationItems(db, did)
        printDonationItems(itemList)
    print('')

    # Delete a random item in first donation and print result
    iid = editDonationRandom(db, test, did, True)  # Delete a random item
    if iid < 1:
        print('ITEM EDIT FAILED: DELETE ITEM'.center(80))
    else:
        print('DONATION {0} ITEMS (deleted item {1})'.format(did,
                                                             iid).center(80))
        itemList = getDonationItems(db, did)
        printDonationItems(itemList)
def storyProviderDeletePending(db, test, story, items, pid):
    printHeader(story)

    # Record test, initializing key if necessary
    testFunc = 'getProviderPending'
    if testFunc in test.keys(): test[testFunc][0] += 1  # Increment test count
    else: test[testFunc] = [1, 0]  # Initialize to one test

    # Add and print five randomized donations,
    dids = []
    for i in range(5):
        dids.append(addDonationRandom(db, pid, None, items, 5, 7))
    did = dids[0]
    print('PENDING DONATION PACKAGES'.center(80))
    dList = getProviderPending(db, pid)
    if dList != testGPPending(db, pid):
        test[testFunc][1] += 1  # record failure
    printDonation(dList)

    # Choose one donation at random and print contents
    did = dList[random.randint(0, len(dList) - 1)][0]
    itemList = getDonationItems(db, did)
    print('')
    print('DONATION {0} ITEMS'.format(did).center(80))
    printDonationItems(itemList)
    print('')

    # Record test, initializing key if necessary
    testFunc = 'deleteDonation'
    if testFunc in test.keys(): test[testFunc][0] += 1  # Increment test count
    else: test[testFunc] = [1, 0]  # Initialize to one test

    # Attempt to delete donation chosen in previous block, print results
    if not deleteDonation(db, did):
        test[testFunc][1] += 1  # Record failure
        print('FAILED TO REMOVE DONATION {0}'.format(did).center(80))
    else:
        print('DELETED DONATION {0}'.format(did).center(80))
    testFunc = 'getProviderPending'  # Reset testFunc for new test
    test[testFunc][0] += 1  # Increment test count
    dList = getProviderPending(db, pid)
    if dList != testGPPending(db, pid):
        test[testFunc][1] += 1  # record failure
    printDonation(dList)
    itemList = getDonationItems(db, did)
    print('')
    print('DONATION {0} ITEMS'.format(did).center(80))
    printDonationItems(itemList)
Exemplo n.º 3
0
def showProviderPending(test, db, provider):

    # Test listProviderDonations pending
    test['listProviderDonations'][0] += 1
    result = listProviderDonations(db, provider, 0b01)

    # if no donations found
    if result is []:
        test['listProviderDonations'][1] += 1
        print('No pending donations found for provider: {0}', format(provider))

    # if donation found
    else:
        # Show donations
        print('\n\t\t\t\tPending Donations')
        for r in result:
            print('\nrow\tprovider\treceiver\tcreated\t\t\t\tcompleted')
            print('{0}\t{1}\t\t{2}\t\t{3}\t{4}'.format(r[0], r[1], r[2], r[3],
                                                       r[4]))

            # Get items for current donation
            test['getDonationItems'][0] += 1
            items = getDonationItems(db, r[0])

            # If no items found
            if items is []:
                test['getDonationItems'][1] += 1
                print('No items found for donation: r[0]')

            # If items found
            else:
                print(
                    '\nItems in donation {0}:\niid\tdid\tbarcode\ttitle\t\tcount\tunits'
                    .format(r[0]))
                for i in items:
                    for j in i:
                        print('{0}\t'.format(j), end='')
                    print('')
def editDonationRandom(db, test, did, dFlag):  # Update a random item

    items = getDonationItems(db, did)
    target = items[random.randrange(0, len(items))]
    iid = target[0]

    # Record test, initializing key if necessary
    testFunc = 'editDonation'
    if testFunc in test.keys(): test[testFunc][0] += 1  # Increment test count
    else: test[testFunc] = [1, 0]

    if dFlag:
        result = editDonation(db, did, iid, 0)
    else:
        icount = target[4]
        while True:
            newCount = random.randint(1, 50)
            if newCount is not icount: break
        result = editDonation(db, did, iid, newCount)
    if result:
        return iid
    else:
        test[testFunc][1] += 1  # Record failure
        return -1