Пример #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)
Пример #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'))
Пример #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)
Пример #4
0
def tariffAdd(params):
	try:
		srv = zones.write_zone(params['id'])
		if not srv['local']:
			return jsonrpc.result({ 'status':'redirect', 'server': srv['server'] })

		c = tariffs.Tariff(params)
		tariffs.add(c)

	except Exception, e:
		LOG.error(e)
		return jsonrpc.result_error('ServerError',
			{ 'status': 'error', 'message': 'Unable to add new tariff' })
Пример #5
0
	def test_tariff_creation(self):
		"""Check the creating of the tariff"""

		tar = tariffs.Tariff(
			data={
				"name": str(uuid.uuid4()),
				"description": str(uuid.uuid4()),
			}
		)
		tariffs.add(tar)

		with database.DBConnect() as db:
			t1 = db.find_one('tariffs', {'id':tar.id})
		self.assertEquals(tariffs.Tariff(t1), tar)