示例#1
0
class GringottsDAOTest(TestCase):
    """The test cases on gringotts database operations """

    RESOURCE_ID = None

    @classmethod
    def setUpClass(cls):
        """
        setup the volume resource whose billing data will be checked for testing shared across
        all of the test cases
        """
        cinder_dao = CinderDAO("mysql+pymysql://root:^[email protected]/cinder")
        # TODO move project id to configuration file
        volume = cinder_dao.get_volumes("18fb285bfa4f4ddaaebb7512683b6a52")[0]
        GringottsDAOTest.RESOURCE_ID = volume.id

    def setUp(self):
        """setup gringotts dao whose logic will be tested"""
        self.gringotts_dao = GringottsDAO("mysql+pymysql://root:^[email protected]/gringotts")

    def test_init(self):
        """test class initialization"""
        self.assertIsNotNone(GringottsDAO("test url"))

    def test_get_orders(self):
        """ test getting orders of the given resource"""
        orders = self.gringotts_dao.get_orders(GringottsDAOTest.RESOURCE_ID)
        self.assertIsNotNone(orders)
        self.assertGreater(len(orders), 0)

    def test_get_bills(self):
        """test getting bills of the given order"""
        order = self.gringotts_dao.get_orders(GringottsDAOTest.RESOURCE_ID)[0]
        bills = self.gringotts_dao.get_bills(order.order_id)
        self.assertGreater(len(bills), 0)
示例#2
0
def verify_billing(resource_id, resource_type):
    gringotts_dao = GringottsDAO(
        "mysql+pymysql://root:^[email protected]/gringotts")

    orders = gringotts_dao.get_orders(resource_id)
    if len(orders) is 0:
        LOG.info("==================================================")
        LOG.error("NO ORDER FOUND for %s %s " % (resource_type, resource_id))
        return

    for order in orders:
        LOG.info("==================================================")
        LOG.info("Order")
        LOG.info("\torder_id: " + order.order_id)
        LOG.info("\ttype: " + order.type)
        LOG.info("\tstatus: " + order.status)

        bills = gringotts_dao.get_bills(order.order_id)

        if len(bills) is 0:
            LOG.info("--------------------------------------------------")
            LOG.error(
                    "NO BILL FOUND for order %s, which belongs to %s %s"
                    % (order, resource_type, resource_id))
            continue
        for bill in bills:
            LOG.info("--------------------------------------------------")
            LOG.info("Bill")
            LOG.info("\tbill_id: " + bill.bill_id)
            LOG.info("\tstatus: " + bill.status)
            LOG.info("\tstart_time: %s" % bill.start_time)
            LOG.info("\tend_time: %s" % bill.end_time)
    return
示例#3
0
 def setUp(self):
     """setup gringotts dao whose logic will be tested"""
     self.gringotts_dao = GringottsDAO("mysql+pymysql://root:^[email protected]/gringotts")