Exemplo n.º 1
0
 def test_get_last(self):
     from core.Status import Status
     from core.Test import Test
     from core.Base import Base
     test_id = str(uuid.uuid4())
     test_status1 = 'FAILURE'
     details = {'browser': random.choice(['Firefox', 'Chrome'])}
     test_type = str(uuid.uuid4())
     status1 = Status(test_id, test_type, test_status1, details=details)
     status1.save_and_update()
     at = Base().get_all(Test.collection, {})
     assert at.count() == 1
     assert at[0]['test_id'] == test_id
     test_status2 = 'SUCCESS'
     status2 = Status(test_id, test_type, test_status2, details=details)
     status2.save_and_update()
     at = Base().get_all(Test.collection, {})
     assert at.count() == 1
     Base().upsert_by_id(Status.collection, bson.ObjectId(status1._id), {Status._on: datetime.datetime.now() - datetime.timedelta(seconds=3)})
     Base().upsert_by_id(Status.collection, bson.ObjectId(status2._id), {Status._on: datetime.datetime.now() - datetime.timedelta(seconds=3)})
     sl = Status(test_id).get_last()
     assert sl._status == 'SUCCESS'
     assert sl._test_id == test_id
     at = Base().get_all(Test.collection, {})
     assert at.count() == 1
     assert at[0]['last_seen'] > Status(base_id=status2._id).get()._on + datetime.timedelta(seconds=1)
Exemplo n.º 2
0
 def test_purge(self):
     from core.Status import Status
     from core.Base import Base
     test_id = str(uuid.uuid4())
     test_status1 = 'FAILURE'
     details = {'browser': 'Firefox'}
     test_type = str(uuid.uuid4())
     status1 = Status(test_id, test_type, test_status1, details=details)
     status1.save_and_update()
     rv = self.app_test.get('/test/tests/{0}/purge'.format(test_id))
     assert rv.status_code == 200
     res = json.loads(rv.data.decode('utf-8'))
     assert res['result'] == 'Success'
     assert res['purge'] == {'nb_removed': 0}
     status_count = Status.list({Status._test_id: test_id})
     assert len(status_count) == 1
     Base().upsert_by_id(Status.collection, ObjectId(status1._id), {Status._on: datetime.datetime.now() - datetime.timedelta(days=8)})
     status2 = Status(test_id, test_type, test_status1, details=details)
     status2.save_and_update()
     status_count = Status.list({Status._test_id: test_id})
     assert len(status_count) == 2
     rv = self.app_test.get('/test/tests/{0}/purge'.format(test_id))
     assert rv.status_code == 200
     res = json.loads(rv.data.decode('utf-8'))
     assert res['result'] == 'Success'
     assert res['purge'] == {'nb_removed': 1}
     status_count = Status.list({Status._test_id: test_id})
     assert len(status_count) == 1
Exemplo n.º 3
0
 def test_should_i_run_custom_all(self):
     from core.Status import Status
     from core.TestType import TestType
     test_type = str(uuid.uuid4())
     tt = TestType(test_type)
     tt.add_run_type('default', 'ALL', {'field': 'Status._status', 'operator': 'EQUAL', 'value': 'SUCCESS'})
     tt.save()
     test_id = str(uuid.uuid4())
     test_status1 = 'FAILURE'
     details = {'browser': random.choice(['Firefox', 'Chrome'])}
     status1 = Status(test_id, test_type, test_status1, details=details)
     status1.save_and_update()
     res = Status(test_id).should_i_run()
     assert res == False
     test_id2 = str(uuid.uuid4())
     test_status2 = 'SUCCESS'
     status2 = Status(test_id2, test_type, test_status2, details=details)
     status2.save_and_update()
     res = Status(test_id).should_i_run()
     assert res == False
     test_status3 = 'SUCCESS'
     status3 = Status(test_id, test_type, test_status3, details=details)
     status3.save_and_update()
     res = Status(test_id).should_i_run()
     assert res == False
     res = Status(test_id2).should_i_run()
     assert res == True
     status2 = Status(test_id2, test_type, test_status2, details=details)
     status2.save_and_update()
     res = Status(test_id2).should_i_run()
     assert res == True
Exemplo n.º 4
0
 def post(self):
     purge_result = None
     parser = reqparse.RequestParser()
     parser.add_argument('purge', help='Do we purge ?', required=False, location='args')
     args = parser.parse_args()
     purge = True
     if args['purge'] is not None:
         if args['purge'].lower() == 'false':
             purge = False
         elif args['purge'].lower() == 'true':
             purge = True
         else:
             abort(400)
     data = request.get_json()
     status = StatusCore(test_id=data['test_id'], test_type=data['type'],
                         status=data['status'], details=data['details'])
     if purge:
         purge_result = status.purge()
     status.save_and_update()
     status = prep_status(status)
     return jsonify(result='Success', status=status, purge=purge_result)
Exemplo n.º 5
0
 def test_save_and_update(self):
     from core.Status import Status
     from core.Base import Base
     test_id = str(uuid.uuid4())
     test_status1 = 'FAILURE'
     test_type = str(uuid.uuid4())
     details = {'browser': random.choice(['Firefox', 'Chrome'])}
     status1 = Status(test_id, test_type, test_status1, details=details)
     status1.save_and_update()
     st = Base().get_one(Status.collection, {})
     assert st['last'] == True
     test_status2 = 'SUCCESS'
     status2 = Status(test_id, test_type, test_status2, details=details)
     status2.save_and_update()
     ast = Base().get_all(Status.collection, {})
     assert ast.count() == 2
     ast = Base().get_all(Status.collection, {'last': False})
     assert ast.count() == 1
     assert ast[0]['status'] == 'FAILURE'
     ast = Base().get_all(Status.collection, {'last': True})
     assert ast.count() == 1
     assert ast[0]['status'] == 'SUCCESS'
Exemplo n.º 6
0
 def test_should_i_run_custom(self):
     from core.Status import Status
     from core.TestType import TestType
     test_type = str(uuid.uuid4())
     tt = TestType(test_type)
     tt.add_run_type('ALLOK', 'ALL', {'field': 'Status._status', 'operator': 'EQUAL', 'value': 'SUCCESS'})
     tt.save()
     test_id = str(uuid.uuid4())
     details = {'browser': 'Firefox'}
     test_type = str(uuid.uuid4())
     test_status1 = 'SUCCESS'
     status1 = Status(test_id, test_type, test_status1, details=details)
     status1.save_and_update()
     rv = self.app_test.get('/test/tests/{0}/run/ALLOK'.format(test_id))
     assert rv.status_code == 200
     res = json.loads(rv.data.decode('utf-8'))
     assert res['result'] == 'Success'
     assert res['run'] == True
     test_status2 = 'FAILURE'
     status2 = Status(test_id, test_type, test_status2, details=details)
     status2.save_and_update()
     rv = self.app_test.get('/test/tests/{0}/run/ALLOK'.format(test_id))
     assert rv.status_code == 200
     res = json.loads(rv.data.decode('utf-8'))
     assert res['result'] == 'Success'
     assert res['run'] == False
     rv = self.app_test.get('/test/tests/{0}/run'.format(test_id))
     assert rv.status_code == 200
     res = json.loads(rv.data.decode('utf-8'))
     assert res['result'] == 'Success'
     assert res['run'] == False
     test_status2 = 'SUCCESS'
     status2 = Status(test_id, test_type, test_status2, details=details)
     status2.save_and_update()
     rv = self.app_test.get('/test/tests/{0}/run/ALLOK'.format(test_id))
     assert rv.status_code == 200
     res = json.loads(rv.data.decode('utf-8'))
     assert res['result'] == 'Success'
     assert res['run'] == False
     rv = self.app_test.get('/test/tests/{0}/run'.format(test_id))
     assert rv.status_code == 200
     res = json.loads(rv.data.decode('utf-8'))
     assert res['result'] == 'Success'
     assert res['run'] == True
     rv = self.app_test.get('/test/tests/{0}/run/{1}'.format(test_id, str(uuid.uuid4())))
     assert rv.status_code == 404
Exemplo n.º 7
0
 def test_should_i_run_default(self):
     from core.Status import Status
     test_id = str(uuid.uuid4())
     test_status1 = 'FAILURE'
     details = {'browser': 'Firefox'}
     test_type = str(uuid.uuid4())
     status1 = Status(test_id, test_type, test_status1, details=details)
     status1.save_and_update()
     rv = self.app_test.get('/test/tests/{0}/run'.format(test_id))
     assert rv.status_code == 200
     res = json.loads(rv.data.decode('utf-8'))
     assert res['result'] == 'Success'
     assert res['run'] == False
     test_id2 = str(uuid.uuid4())
     test_status2 = 'SUCCESS'
     status2 = Status(test_id2, test_type, test_status2, details=details)
     status2.save_and_update()
     rv = self.app_test.get('/test/tests/{0}/run'.format(test_id))
     assert rv.status_code == 200
     res = json.loads(rv.data.decode('utf-8'))
     assert res['result'] == 'Success'
     assert res['run'] == False
     test_status3 = 'SUCCESS'
     test_type = str(uuid.uuid4())
     status3 = Status(test_id, test_type, test_status3, details=details)
     status3.save_and_update()
     rv = self.app_test.get('/test/tests/{0}/run'.format(test_id))
     assert rv.status_code == 200
     res = json.loads(rv.data.decode('utf-8'))
     assert res['result'] == 'Success'
     assert res['run'] == True
     rv = self.app_test.get('/test/tests/{0}/run'.format(str(uuid.uuid4())))
     assert rv.status_code == 200
     res = json.loads(rv.data.decode('utf-8'))
     assert res['result'] == 'Success'
     assert res['run'] == True
     rv = self.app_test.get('/test/tests/{0}/run/default'.format(test_id))
     assert rv.status_code == 200
     res = json.loads(rv.data.decode('utf-8'))
     assert res['result'] == 'Success'
     assert res['run'] == True
Exemplo n.º 8
0
 def test_should_i_run_default(self):
     from core.Status import Status
     test_id = str(uuid.uuid4())
     test_status1 = 'FAILURE'
     details = {'browser': random.choice(['Firefox', 'Chrome'])}
     test_type = str(uuid.uuid4())
     status1 = Status(test_id, test_type, test_status1, details=details)
     status1.save_and_update()
     res = Status(test_id).should_i_run()
     assert res == False
     test_id2 = str(uuid.uuid4())
     test_status2 = 'SUCCESS'
     status2 = Status(test_id2, test_type, test_status2, details=details)
     status2.save_and_update()
     res = Status(test_id).should_i_run()
     assert res == False
     test_status3 = 'SUCCESS'
     status3 = Status(test_id, test_type, test_status3, details=details)
     status3.save_and_update()
     res = Status(test_id).should_i_run()
     assert res == True
Exemplo n.º 9
0
 def test_purge(self):
     from core.Status import Status
     from core.Base import Base
     test_id = str(uuid.uuid4())
     test_status1 = 'FAILURE'
     details = {'browser': random.choice(['Firefox', 'Chrome'])}
     test_type = str(uuid.uuid4())
     status1 = Status(test_id, test_type, test_status1, details=details)
     status1.save_and_update()
     ast = Base().get_all(Status.collection, {})
     Base().upsert_by_id(Status.collection, bson.ObjectId(status1._id), {Status._on: datetime.datetime.now() - datetime.timedelta(days=8)})
     ast = Base().get_all(Status.collection, {})
     test_id2 = str(uuid.uuid4())
     test_status2 = 'SUCCESS'
     status2 = Status(test_id2, test_type, test_status2, details=details)
     status2.save_and_update()
     test_status3 = 'SUCCESS'
     status3 = Status(test_id, test_type, test_status3, details=details)
     status3.save_and_update()
     res = status3.purge()
     assert res['nb_removed'] == 1
     ast = Base().get_all(Status.collection, {})
     assert ast.count() == 2
     assert sorted([str(st['_id']) for st in ast]) == sorted([status2._id, status3._id])