Beispiel #1
0
def rateList(params):
    try:
        if len(params) == 0:
            ret = map(lambda c: c.values, rates.get_all())

        elif len(params) == 1:
            ret = map(lambda c: c.values, rates.get_by_tariff(params["tariff_id"]))

    except Exception, e:
        LOG.error(e)
        return jsonrpc.result_error("ServerError", {"status": "error", "message": "Unable to obtain rate list"})
Beispiel #2
0
	def test_rates_get_all(self):
		"""Check getting rates from db"""


		tariffs_list = [str(uuid.uuid4()) for i in range(5)]
		metrics_list = [str(uuid.uuid4()) for i in range(5)]

		rat = {}
		for tar in tariffs_list:
			rat[tar] = {}
			random.shuffle(metrics_list)
			for met in metrics_list[:random.randint(1, 5)]:

				data = {
					'id':           str(uuid.uuid4()),
					'description':  str(uuid.uuid4()),
					'metric_id':    met,
					'tariff_id':    tar,
					'rate':         random.randint(10**3, 10**10),
					'currency':     rates.constants.CURRENCY_RUB,
					'state':        random.choice([rates.constants.STATE_ACTIVE,
										rates.constants.STATE_DELETED,
										rates.constants.STATE_UPDATE]),
					'time_create':  int(time.time()),
					'time_destroy': 0
					}

				rat[tar][met] = rates.Rate(data)

				with database.DBConnect() as db:
					db.insert('rates', data)

		list_all = itertools.chain(*[rat[j].itervalues() for j in rat.iterkeys()])
		self.assertEquals(set(list(rates.get_all())),
				set(filter(lambda x: x.state<rates.constants.STATE_DELETED,list_all)))

		for tar_id in rat.keys():
			self.assertEquals(set(list(rates.get_by_tariff(tar_id))),
				set(filter(lambda x: x.state<rates.constants.STATE_DELETED,
							rat[tar_id].values())))