예제 #1
0
 def test_query_product_price(self):
     self.mox.StubOutWithMock(db, 'region_get_by_name')
     self.mox.StubOutWithMock(db, 'item_get_by_name')
     self.mox.StubOutWithMock(db, 'item_type_get_by_name')
     self.mox.StubOutWithMock(db, 'payment_type_get_by_name')
     self.mox.StubOutWithMock(db, 'product_get_all')
     db.region_get_by_name(self.context, self.region_name).\
             AndReturn(self.region)
     db.item_get_by_name(self.context, self.item_name).AndReturn(self.item)
     db.item_type_get_by_name(self.context, self.item_type_name).\
             AndReturn(self.item_type)
     db.payment_type_get_by_name(self.context, self.payment_type_name).\
             AndReturn(self.payment_type)
     db.product_get_all(self.context,
                        filters={'region_id': self.region_id,
                                 'item_id': self.item_id,
                                 'item_type_id': self.item_type_id,
                                 'payment_type_id': self.payment_type_id}).\
                                         AndReturn(self.products)
     self.mox.ReplayAll()
     result = api.query_product_price(self.context, self.region_name,
                                      self.item_name, self.item_type_name,
                                      self.payment_type_name)
     self.mox.VerifyAll()
     self.assertEqual(result, {'data': {'price': self.product_price}})
예제 #2
0
 def test_query_product_price(self):
     self.mox.StubOutWithMock(db, 'region_get_by_name')
     self.mox.StubOutWithMock(db, 'item_get_by_name')
     self.mox.StubOutWithMock(db, 'item_type_get_by_name')
     self.mox.StubOutWithMock(db, 'payment_type_get_by_name')
     self.mox.StubOutWithMock(db, 'product_get_all')
     db.region_get_by_name(self.context, self.region_name).\
             AndReturn(self.region)
     db.item_get_by_name(self.context, self.item_name).AndReturn(self.item)
     db.item_type_get_by_name(self.context, self.item_type_name).\
             AndReturn(self.item_type)
     db.payment_type_get_by_name(self.context, self.payment_type_name).\
             AndReturn(self.payment_type)
     db.product_get_all(self.context,
                        filters={'region_id': self.region_id,
                                 'item_id': self.item_id,
                                 'item_type_id': self.item_type_id,
                                 'payment_type_id': self.payment_type_id}).\
                                         AndReturn(self.products)
     self.mox.ReplayAll()
     result = api.query_product_price(self.context, self.region_name,
                                      self.item_name, self.item_type_name,
                                      self.payment_type_name)
     self.mox.VerifyAll()
     self.assertEqual(result, {'data': {'price': self.product_price}})
예제 #3
0
파일: api.py 프로젝트: pperezrubio/dough
def query_payment_types(context, region=None, item=None, **kwargs):
    filters = dict()
    filters['region_id'] = db.region_get_by_name(context, region)['id']
    filters['item_id'] = db.item_get_by_name(context, item)['id']
    products = db.product_get_all(context, filters=filters)
    payment_type_info = {
        'payment_type_names': map(lambda x: x['payment_type']['name'],
                                  products),
        }
    return {'data': payment_type_info}
예제 #4
0
파일: test_api.py 프로젝트: soloxf/dough
 def test_unsubscribe_item(self):
     self.mox.StubOutWithMock(db, 'region_get_by_name')
     self.mox.StubOutWithMock(db, 'item_get_by_name')
     self.mox.StubOutWithMock(db, 'subscription_get_all')
     self.mox.StubOutWithMock(db, 'subscription_destroy')
     db.region_get_by_name(self.context, self.region_name).\
             AndReturn(self.region)
     db.item_get_by_name(self.context, self.item_name).AndReturn(self.item)
     db.subscription_get_all(self.context,
                             filters={
                                 'region_id': self.region_id,
                                 'item_id': self.item_id,
                                 'project_id': self.context.project_id,
                                 'resource_uuid': self.resource_uuid
                                 }).AndReturn(self.subscriptions)
     db.subscription_destroy(self.context, self.subscription_id).\
             AndReturn(None)
     self.mox.ReplayAll()
     result = api.unsubscribe_item(self.context, self.region_name,
                                   self.item_name, self.resource_uuid)
     self.mox.VerifyAll()
     self.assertEqual(result, {})
예제 #5
0
 def test_subscribe_item(self):
     self.mox.StubOutWithMock(db, 'region_get_by_name')
     self.mox.StubOutWithMock(db, 'item_get_by_name')
     self.mox.StubOutWithMock(db, 'item_type_get_by_name')
     self.mox.StubOutWithMock(db, 'payment_type_get_by_name')
     self.mox.StubOutWithMock(db, 'product_get_all')
     self.mox.StubOutWithMock(db, 'subscription_create')
     self.mox.StubOutWithMock(db, 'subscription_extend')
     db.region_get_by_name(self.context, self.region_name).\
             AndReturn(self.region)
     db.item_get_by_name(self.context, self.item_name).AndReturn(self.item)
     db.item_type_get_by_name(self.context, self.item_type_name).\
             AndReturn(self.item_type)
     db.payment_type_get_by_name(self.context, self.payment_type_name).\
             AndReturn(self.payment_type)
     db.product_get_all(self.context,
                        filters={'region_id': self.region_id,
                                 'item_id': self.item_id,
                                 'item_type_id': self.item_type_id,
                                 'payment_type_id': self.payment_type_id}).\
                                         AndReturn(self.products)
     db.subscription_create(self.context,
                            {'project_id': self.context.project_id,
                             'product_id': self.product_id,
                             'resource_uuid': self.resource_uuid,
                             'resource_name': self.resource_name}).\
                                     AndReturn(self.subscription)
     db.subscription_extend(self.context, self.subscription_id,
                            self.created_at).AndReturn(None)
     self.mox.ReplayAll()
     result = api.subscribe_item(self.context, self.region_name,
                                 self.item_name, self.item_type_name,
                                 self.payment_type_name, self.resource_uuid,
                                 self.resource_name)
     self.mox.VerifyAll()
     self.assertEqual(result, {})
예제 #6
0
 def test_subscribe_item(self):
     self.mox.StubOutWithMock(db, 'region_get_by_name')
     self.mox.StubOutWithMock(db, 'item_get_by_name')
     self.mox.StubOutWithMock(db, 'item_type_get_by_name')
     self.mox.StubOutWithMock(db, 'payment_type_get_by_name')
     self.mox.StubOutWithMock(db, 'product_get_all')
     self.mox.StubOutWithMock(db, 'subscription_create')
     self.mox.StubOutWithMock(db, 'subscription_extend')
     db.region_get_by_name(self.context, self.region_name).\
             AndReturn(self.region)
     db.item_get_by_name(self.context, self.item_name).AndReturn(self.item)
     db.item_type_get_by_name(self.context, self.item_type_name).\
             AndReturn(self.item_type)
     db.payment_type_get_by_name(self.context, self.payment_type_name).\
             AndReturn(self.payment_type)
     db.product_get_all(self.context,
                        filters={'region_id': self.region_id,
                                 'item_id': self.item_id,
                                 'item_type_id': self.item_type_id,
                                 'payment_type_id': self.payment_type_id}).\
                                         AndReturn(self.products)
     db.subscription_create(self.context,
                            {'project_id': self.context.project_id,
                             'product_id': self.product_id,
                             'resource_uuid': self.resource_uuid,
                             'resource_name': self.resource_name}).\
                                     AndReturn(self.subscription)
     db.subscription_extend(self.context, self.subscription_id,
                            self.created_at).AndReturn(None)
     self.mox.ReplayAll()
     result = api.subscribe_item(self.context, self.region_name,
                                 self.item_name, self.item_type_name,
                                 self.payment_type_name, self.resource_uuid,
                                 self.resource_name)
     self.mox.VerifyAll()
     self.assertEqual(result, {})
예제 #7
0
파일: api.py 프로젝트: soloxf/dough
def unsubscribe_item(context, region=None, item=None,
                     resource_uuid=None, **kwargs):
    """
    """
    filters = {
        'project_id': context.project_id,
        'resource_uuid': resource_uuid,
        }
    try:
        filters['region_id'] = db.region_get_by_name(context, region)['id']
        filters['item_id'] = db.item_get_by_name(context, item)['id']
        subscriptions = db.subscription_get_all(context, filters=filters)
        # TODO(lzyeval): check if subscriptions size is not 1
        db.subscription_destroy(context, subscriptions[0]['id'])
    except Exception, e:
        # TODO(lzyeval): report
        raise
예제 #8
0
파일: api.py 프로젝트: pperezrubio/dough
def _product_get_all(context, region=None, item=None, item_type=None,
                     payment_type=None):
    """
    """
    products = None
    try:
        # filter to get product_id
        filters = dict()
        filters['region_id'] = db.region_get_by_name(context, region)['id']
        filters['item_id'] = db.item_get_by_name(context, item)['id']
        filters['item_type_id'] = db.item_type_get_by_name(context,
                                                           item_type)['id']
        filters['payment_type_id'] = db.payment_type_get_by_name(context,
                                                            payment_type)['id']
        products = db.product_get_all(context, filters=filters)
    except Exception, e:
        # TODO(lzyeval): report
        raise
예제 #9
0
파일: api.py 프로젝트: young8/dough
def _product_get_all(context, region=None, item=None, item_type=None,
                     payment_type=None):
    """
    """
    products = None
    try:
        # filter to get product_id
        filters = dict()
        filters['region_id'] = db.region_get_by_name(context, region)['id']
        filters['item_id'] = db.item_get_by_name(context, item)['id']
        filters['item_type_id'] = db.item_type_get_by_name(context,
                                                           item_type)['id']
        filters['payment_type_id'] = db.payment_type_get_by_name(context,
                                                            payment_type)['id']
        products = db.product_get_all(context, filters=filters)
    except Exception, e:
        # TODO(lzyeval): report
        print e
        raise
예제 #10
0
파일: api.py 프로젝트: pengyuwei/dough
def query_item_products(context, region=None, item=None, **kwargs):
    product_info = dict()
    filters = dict()
    filters['region_id'] = db.region_get_by_name(context, region)['id']
    filters['item_id'] = db.item_get_by_name(context, item)['id']
    products = db.product_get_all(context, filters=filters)
    for product in products:
        item_type_name = product['item_type']['name']
        payment_type_name = product['payment_type']['name']
        order_unit = product['order_unit']
        order_size = product['order_size']
        price = product['price']
        currency = product['currency']
        item_type_info = product_info.setdefault(item_type_name, dict())
        item_type_info[payment_type_name] = {
            'order_unit': order_unit,
            'order_size': order_size,
            'price': price,
            'currency': currency,
            }
    return {'data': product_info}
예제 #11
0
def query_item_products(context, region=None, item=None, **kwargs):
    product_info = dict()
    filters = dict()
    filters['region_id'] = db.region_get_by_name(context, region)['id']
    filters['item_id'] = db.item_get_by_name(context, item)['id']
    products = db.product_get_all(context, filters=filters)
    for product in products:
        item_type_name = product['item_type']['name']
        payment_type_name = product['payment_type']['name']
        order_unit = product['order_unit']
        order_size = product['order_size']
        price = product['price']
        currency = product['currency']
        item_type_info = product_info.setdefault(item_type_name, dict())
        item_type_info[payment_type_name] = {
            'order_unit': order_unit,
            'order_size': order_size,
            'price': price,
            'currency': currency,
        }
    return {'data': product_info}