Exemple #1
0
	def test_task_creation(self):
		"""Check add new task to database"""

		o = tasks.Task({
			"name":     str(uuid.uuid4()),
			"customer": str(uuid.uuid4()),
			"rate_id":  str(uuid.uuid4()),
			"queue_id": str(uuid.uuid4()),
		})

		tasks.add(o)

		with database.DBConnect(primarykey=o.base_id) as db:
			n = db.find_one('tasks', {'base_id':o.base_id, 'record_id': '0' })
			o1 = tasks.Task(n)

		self.assertEquals(o1.values, o.values)
Exemple #2
0
def taskAdd(request):
	""" Open new billing task """

	if request['time-create'] == 0:
		request['time-create'] = int(time.time())

	try:
		rid, rate = ('', 0)
		customer = customers.get(request['customer'], typ='id')

		if customer:
			rid, rate  = rates.resolve(request['type'], customer.tariff_id)

			if not rid:
				LOG.error("task(%s): Unable to find rate for metric",
					request['uuid'])
		else:
			LOG.error("task(%s): Unknown customer (%s)",
				request['uuid'], request['customer'])

		t = tasks.Task({
				'group_id':     GROUPID.next(),
				'base_id':      request['uuid'],
				'customer':     request['customer'],

				'metric_id':    request['type'],
				'rate_id':      rid,
				'rate':         rate,

				'value':        request['value'],

				'time_create':  request['time-create'],
				'time_check':   request['time-create'],
				'time_destroy': request['time-destroy'],

				'target_user':  request['user'],
				'target_uuid':  request['uuid'],
				'target_descr': request['descr'],
			})
		tasks.add(t)

	except Exception, e:
		LOG.exception("Unable to add new task: %s", e)
		return jsonrpc.result_error('ServerError',
			{ 'status': 'error', 'message': 'Unable to add new task' })
Exemple #3
0
	def test_task_remove(self):
		"""Check state changing"""

		o = tasks.Task({
			"name":     str(uuid.uuid4()),
			"customer": str(uuid.uuid4()),
			"rate_id":  str(uuid.uuid4()),
			"queue_id": str(uuid.uuid4()),
		})

		tasks.add(o)
		ts = int(time.time()+10)
		tasks.remove('id', o.base_id, ts)
		o.set({'state': tasks.constants.STATE_DELETED, 'time_destroy':ts})

		with database.DBConnect(primarykey=o.base_id) as db:
			o1 = tasks.Task(db.find_one('tasks', {'base_id':o.base_id, 'record_id': '0' }))
		self.assertEquals(o1.values, o.values)
Exemple #4
0
	def test_task_update(self):
		"""Check task recreating"""

		o = tasks.Task({
			"name":        str(uuid.uuid4()),
			"customer":    str(uuid.uuid4()),
			"rate_id":     str(uuid.uuid4()),
			"queue_id":    str(uuid.uuid4()),
			"time_create": int(time.time())-60
		})

		tasks.add(o)

		data = {'value': 29}
		ts = int(time.time() + 10)
		tasks.update(o.base_id, data, ts)
		with database.DBConnect(primarykey=o.base_id) as db:
			o1 = tasks.Task(db.find_one('tasks', {'base_id':o.base_id, 'record_id': '0' }))

		#Getting queues
		with database.DBConnect(primarykey=o.base_id) as db:
			nq = db.find_one('queue', {'id':o1.queue_id})
			oq = db.find_one('queue', {'id':o.queue_id})

		self.assertTrue(oq is not None)

		#Time_create is equal with time_check in new task
		self.assertEquals(o1.time_create, nq['time_check'])

		#New id's and time_create
		self.assertNotEquals(o1.queue_id, o.queue_id)
		self.assertNotEquals(o1.task_id, o.task_id)
		self.assertNotEquals(o1.time_create, o.time_create)

		#Updated data
		o.set(data)
		o1.queue_id = o.queue_id
		o1.task_id = o.task_id
		o1.time_create = o.time_create
		self.assertEquals(o1.values, o.values)
Exemple #5
0
	def test_task_modify(self):
		"""Testing task modification"""

		o = tasks.Task({
			"name":     str(uuid.uuid4()),
			"customer": str(uuid.uuid4()),
			"rate_id":  str(uuid.uuid4()),
			"queue_id": str(uuid.uuid4()),
		})

		tasks.add(o)
		with self.assertRaises(ValueError):
			tasks.modify('abracadabra', '', {})

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

		data = {'value': 29}
		tasks.modify('id', o.base_id, data)
		with database.DBConnect(primarykey=o.base_id) as db:
			o1 = tasks.Task(db.find_one('tasks', {'base_id':o.base_id, 'record_id': '0' }))
		o.set(data)
		self.assertEquals(o1.values, o.values)