Exemple #1
0
	def test_rates_creation(self):
		"""Check the creating of the rates"""

		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
			}
		)

		with self.assertRaises(ValueError):
			rates.add(rat)

		tariffs.add(tariffs.Tariff({'id':rat.tariff_id}))

		with self.assertRaises(ValueError):
			rates.add(rat)

		metrics.add(metrics.Metric({'id':rat.metric_id}))

		rates.add(rat)

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

		self.assertEquals(rates.Rate(r1), rat)
Exemple #2
0
	def test_rate_add(self):
		"""Check the creating rate with rateAdd"""

		data={
				'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':     'RUB',
				'state':        'ACTIVE',
				'time_create':  int(time.time()),
				'time_destroy': 0,
				'sync':         0,
		}
		
		tariffs.add(tariffs.Tariff({'id':data['tariff_id']}))

		metrics.add(metrics.Metric({'id':data['metric_id']}))

		self.assertEquals(wapi_rates.rateAdd(data.copy()), requestor({'id':data['id']}, 'ok'))

		data['currency'] = rates.constants.CURRENCY_RUB
		data['state'] = rates.constants.STATE_ACTIVE
		with database.DBConnect() as db:
			t1 = db.find('rates').one()
		self.assertEquals(hashable_dict(data), hashable_dict(t1))

		with mocker([('bc.rates.add', mocker.exception),
					('bc_wapi.wapi_rates.LOG.error', mocker.passs)]):
			self.assertEquals(wapi_rates.rateAdd({'id':''}),
				requestor({'message': 'Unable to add new rate' }, 'servererror'))
Exemple #3
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 #4
0
def metricAdd(request):
	""" Adds new billing metric """

	try:
		m = metrics.Metric(request)
		metrics.add(m)
	except Exception, e:
		LOG.error(e)
		return jsonrpc.result_error('ServerError',
			{ 'status': 'error', 'message': 'Unable to add new metric' })
Exemple #5
0
	def test_metric_creation(self):
		"""Check the creating of the metric"""

		met = metrics.Metric(
			data={
				'id':         str(uuid.uuid4()),
				'type':       str(uuid.uuid4())[:10],
				'formula':    metrics.constants.FORMULA_SPEED,
				'aggregate':  0L,
			}
		)
		metrics.add(met)

		with database.DBConnect() as db:
			m1 = db.find_one('metrics', {'id':met.id})

		self.assertEquals(metrics.Metric(m1), met)