コード例 #1
0
ファイル: test_tariffs.py プロジェクト: legionus/billing
	def test_tariff_modification(self):
		""" Check modification attributes"""

		data = {
			'id':           unicode(uuid.uuid4()),
			'name':         str(uuid.uuid4()),
			'description':  str(uuid.uuid4()),
			'state':        tariffs.constants.STATE_ENABLED,
			'time_create':  int(time.time()),
			'time_destroy': 0,
		}

		tar = tariffs.Tariff(data)

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

		data = {
			'name':         str(uuid.uuid4()),
			'description':  str(uuid.uuid4()),
			'state':        tariffs.constants.STATE_DISABLED,
				}
		tariffs.modify('id', tar.id, data)
		tar.set(data)

		with self.assertRaises(TypeError):
			tariffs.modify('id', tar.id, {'state':tariffs.constants.STATE_MAXVALUE+1})

		with self.assertRaises(ValueError):
			tariffs.modify('name', tar.id, {})

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

		self.assertEquals(tariffs.Tariff(t1), tar)
コード例 #2
0
ファイル: wapi_tariffs.py プロジェクト: legionus/billing
def tariffModify(params):
	try:
		srv = zones.write_zone(params['id'])
		if not srv['local']:
			return jsonrpc.result({ 'status':'redirect', 'server': srv['server'] })

		if len(params) == 1:
			return jsonrpc.result({ 'status':'ok' })

		if 'state' in params:
			v = tariffs.constants.import_state(params['state'])
			if v == None or v == tariffs.constants.STATE_DELETED:
				return jsonrpc.result_error('InvalidRequest',
					{ 'status':'error',
						'message':'Wrong state: ' + str(params['state'])})
			params['state'] = v

		tariffs.modify('id', params['id'], params)

	except Exception, e:
		LOG.error(e)
		return jsonrpc.result_error('ServerError',
			{ 'status': 'error', 'message': 'Unable to modify tariff' })