def rateModify(params): """ Modify rate """ try: srv = zones.write_zone(params["tariff_id"]) if not srv["local"]: return jsonrpc.result({"status": "redirect", "server": srv["server"]}) if len(params) <= 2: return jsonrpc.result_error("InvalidRequest", {"status": "error", "message": "More arguments required"}) if "currency" in params: v = rates.constants.import_currency(params["currency"]) if v == None: return jsonrpc.result_error( "InvalidRequest", {"status": "error", "message": "Wrong currency: " + str(params["currency"])} ) params["currency"] = v tid, mid = params["tariff_id"], params["metric_id"] del params["tariff_id"], params["metric_id"] rates.modify(tid, mid, params) except Exception, e: LOG.error(e) return jsonrpc.result_error("ServerError", {"status": "error", "message": "Unable to modify rate"})
def test_rate_modification(self): """ Check modification attributes""" rat = rates.Rate( { 'id': str(uuid.uuid4()), 'description': str(uuid.uuid4()), 'metric_id': str(uuid.uuid4()), 'tariff_id': str(uuid.uuid4()), 'rate': long(random.randint(10**3, 10**10)), 'currency': rates.constants.CURRENCY_RUB, 'state': rates.constants.STATE_ACTIVE, 'time_create': int(time.time()), 'time_destroy': 0 } ) tariffs.add(tariffs.Tariff({'id':rat.tariff_id})) metrics.add(metrics.Metric({'id':rat.metric_id})) rates.add(rat) data = {'description': str(uuid.uuid4())} rates.modify(rat.tariff_id, rat.metric_id, data) rat.set(data) with database.DBConnect() as db: r1 = db.find_one('rates', {'id': rat.id}) self.assertEquals(rates.Rate(r1), rat)