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)
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])
def get(self, test_id): status = StatusCore(test_id=test_id) status.add_unknown_if_none_exist() result = status.purge() return jsonify(result='Success', purge=result)