Пример #1
0
def customerModify(params):
	""" Modify customer's record """

	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 = customers.constants.import_state(params['state'])
			if v == None or v == customers.constants.STATE_DELETED:
				return jsonrpc.result_error('InvalidRequest', {'status':'error',
				'message':'Wrong state: ' + str(params['state'])})
			params['state'] = v

		if 'wallet_mode' in params:
			v = customers.constants.import_wallet_mode(params['wallet_mode'])
			if v == None:
				return jsonrpc.result_error('InvalidRequest', {'status':'error',
				'message':'Wrong wallet_mode: ' + str(params['wallet_mode'])})
			params['wallet_mode'] = v

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

	except Exception, e:
		LOG.error(e)
		return jsonrpc.result_error('ServerError',
			{ 'status': 'error', 'message': 'Unable to modify customer' })
Пример #2
0
	def test_customer_modification(self):
		""" Check modification attributes"""

		data = {
			'id': str(uuid.uuid4()),
			'login': str(uuid.uuid4()),
			'name_short': str(uuid.uuid4()),
			'name_full': str(uuid.uuid4()),
			'comment': str(uuid.uuid4()),
			'contract_client': str(uuid.uuid4()),
			'contract_service': str(uuid.uuid4()),
			'tariff_id': str(uuid.uuid4()),
			'contact_person': str(uuid.uuid4()),
			'contact_email': str(uuid.uuid4()),
			'contact_phone': str(uuid.uuid4())[:10],
			'state': customers.constants.STATE_ENABLED,
			'time_create': int(time.time()),
			'time_destroy': 0,
			'wallet': 10,
			'wallet_mode': customers.constants.WALLET_MODE_LIMITED
			}
		cus = customers.Customer(data)

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

		data = {'comment':  str(uuid.uuid4())}
		customers.modify('id', cus.id, data)
		cus.set(data)

		with self.assertRaises(ValueError):
			customers.modify(random.choice(list(set(data.keys())-set(['login', 'id']))), cus.id, {})
		with self.assertRaises(TypeError):
			customers.modify('id', cus.id, {'state':customers.constants.STATE_MAXVALUE})

		with self.assertRaises(TypeError):
			customers.modify('id', cus.id, {'wallet_mode':customers.constants.WALLET_MODE_MAXVALUE})

		with database.DBConnect() as db:
			c1 = db.find_one('customers', {'id': cus.id})

		self.assertEquals(customers.Customer(c1), cus)