Exemple #1
0
	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)
Exemple #2
0
def rateAdd(params):
    """ Adds new rate """

    try:
        srv = zones.write_zone(params["tariff_id"])
        if not srv["local"]:
            return jsonrpc.result({"status": "redirect", "server": srv["server"]})

        if "currency" in params:
            v = rates.constants.import_currency(params["currency"])
            w = rates.constants.import_state(params["state"])
            if v == None:
                return jsonrpc.result_error(
                    "InvalidRequest", {"status": "error", "message": "Wrong currency: " + str(params["currency"])}
                )
            if w == None:
                return jsonrpc.result_error(
                    "InvalidRequest", {"status": "error", "message": "Wrong state: " + str(params["state"])}
                )
            params["currency"] = v
            params["state"] = w

        o = rates.Rate(params)
        rates.add(o)

    except Exception, e:
        LOG.error(e)
        return jsonrpc.result_error("ServerError", {"status": "error", "message": "Unable to add new rate"})
Exemple #3
0
	def test_rate_delete(self):
		"""Check state changing"""

		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)

		rat.set({'state': rates.constants.STATE_DELETED,
			'time_destroy': int(time.time())})

		with self.assertRaises(ValueError):
			rates.remove('','')

		rates.remove(rat.tariff_id, rat.metric_id)

		with database.DBConnect() as db:
			r1 = db.find_one('rates', {'id': rat.id})

		self.assertEquals(rates.Rate(r1), rat)