Example #1
0
def customerAdd(params):
	""" Adds new customer account """

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

		wallet_mode = customers.constants.import_wallet_mode(params['wallet_mode'])

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

		params['wallet_mode'] = wallet_mode

		c = customers.Customer(params)
		customers.add(c)

	except Exception, e:
		LOG.error(e)
		return jsonrpc.result_error('ServerError',
			{ 'status': 'error', 'message': 'Unable to add new customer' })
Example #2
0
	def test_customer_creation(self):
		"""Check the creating of customer"""

		cus = customers.Customer({
			'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_MAXVALUE,
			'time_create': int(time.time()),
			'time_destroy': 0,
			'wallet': 10,
			'wallet_mode': customers.constants.WALLET_MODE_LIMITED
		}
		)

		with self.assertRaises(TypeError):
			customers.add(cus)

		cus.set({'state': customers.constants.STATE_ENABLED,
			'wallet_mode': customers.constants.WALLET_MODE_MAXVALUE})
		with self.assertRaises(TypeError):
			customers.add(cus)

		cus.set({'wallet_mode': customers.constants.WALLET_MODE_LIMITED})
		customers.add(cus)

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

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