コード例 #1
0
ファイル: test_test.py プロジェクト: ab9-er/TestSheriff
 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
コード例 #2
0
 def test_list(self):
     from core.Status import Status
     from core import Base
     test_id1 = str(uuid.uuid4())
     test_status = 'FAILURE'
     details = {'browser': random.choice(['Firefox', 'Chrome'])}
     test_type = str(uuid.uuid4())
     status1 = Status(test_id1, test_type, test_status, details=details)
     status1.save()
     Base.Base().upsert_by_id(Status.collection, bson.ObjectId(status1._id), {Status._on: datetime.datetime.now() - datetime.timedelta(seconds=1)})
     test_id2 = str(uuid.uuid4())
     status2 = Status(test_id2, test_type, test_status, details=details)
     status2.save()
     ast = Status.list(sort=[('on', Base.DESC)])
     assert len(ast) == 2
     assert ast[0].to_dict() == Status(base_id=status2._id).get().to_dict()
     assert ast[1].to_dict() == Status(base_id=status1._id).get().to_dict()
     ast = Status.list(sort=[('on', Base.ASC)])
     assert len(ast) == 2
     assert ast[0].to_dict() == Status(base_id=status1._id).get().to_dict()
     assert ast[1].to_dict() == Status(base_id=status2._id).get().to_dict()
コード例 #3
0
ファイル: test.py プロジェクト: ab9-er/TestSheriff
def test_get(test_id):
    test = TestCore.get_one({TestCore._test_id:test_id})
    if test is None:
        abort(404)
    statuses = {}
    lastStatuses = StatusCore.list(query_filter={StatusCore._test_id: test._test_id,
                                                 StatusCore._last: True},
                                   sort=[(StatusCore._on, Base.DESC)])
    if len(lastStatuses) != 0:
        statuses['last_status'] = lastStatuses[0]
    lastSuccess = StatusCore.list(query_filter={StatusCore._test_id: test._test_id,
                                                StatusCore._status: 'SUCCESS'},
                                  sort=[(StatusCore._on, Base.DESC)])
    if len(lastSuccess) != 0:
        statuses['last_status_success'] = lastSuccess[0]
    lastFailure = StatusCore.list(query_filter={StatusCore._test_id: test._test_id,
                                                StatusCore._status: 'FAILURE'},
                                  sort=[(StatusCore._on, Base.DESC)])
    if len(lastFailure) != 0:
        statuses['last_status_failure'] = lastFailure[0]
    test = prep_test(test, statuses)
    return test
コード例 #4
0
 def test_list_page(self):
     from core.Status import Status
     from core import Base
     test_id1 = str(uuid.uuid4())
     test_status = 'FAILURE'
     details = {'browser': random.choice(['Firefox', 'Chrome'])}
     test_type = str(uuid.uuid4())
     nb = 10
     statuses = {}
     for i in range(nb):
         status = Status(test_id1, test_type, test_status, details=details)
         status.save()
         Base.Base().upsert_by_id(Status.collection, bson.ObjectId(status._id), {Status._on: datetime.datetime.now() - datetime.timedelta(seconds=nb - i + 1)})
         statuses[i] = status
     ast = Status.list(sort=[('on', Base.ASC)], page=1, nb_item=2)
     assert len(ast) == 2
     assert ast[0].to_dict() == Status(base_id=statuses[2]._id).get().to_dict()
     assert ast[1].to_dict() == Status(base_id=statuses[3]._id).get().to_dict()
     ast = Status.list(sort=[('on', Base.DESC)], page=2, nb_item=3)
     assert len(ast) == 3
     assert ast[0].to_dict() == Status(base_id=statuses[3]._id).get().to_dict()
     assert ast[1].to_dict() == Status(base_id=statuses[2]._id).get().to_dict()
     assert ast[2].to_dict() == Status(base_id=statuses[1]._id).get().to_dict()
コード例 #5
0
ファイル: status.py プロジェクト: mockersf/TestSheriff
 def get(self):
     parser = reqparse.RequestParser()
     parser.add_argument('test_id', type=str, help='test ID', required=False, location='args')
     parser.add_argument('status', type=str, help='status', required=False, location='args')
     parser.add_argument('type', type=str, help='test type', required=False, location='args')
     parser.add_argument('field', type=str, help='details field name', required=False, location='args')
     parser.add_argument('value', type=str, help='details field value', required=False, location='args')
     for i_field in range(10):
         parser.add_argument('field{0}'.format(i_field), type=str, help='details field name', required=False, location='args')
         parser.add_argument('value{0}'.format(i_field), type=str, help='details field value', required=False, location='args')
     parser.add_argument('nb_status', type=int, help='number of status to return, by default 100', required=False, location='args', default=100)
     parser.add_argument('page', type=int, help='page to return', required=False, location='args', default=0)
     args = parser.parse_args()
     query_filter = {}
     query = {'page': args['page'], 'nb_status': args['nb_status']}
     if args['test_id'] is not None:
         if args['test_id'][0] == '!':
             query_filter[StatusCore._test_id] = {'$ne': args['test_id'][1:]}
         else:
             query_filter[StatusCore._test_id] = args['test_id']
         query['test_id'] = args['test_id']
     if args['status'] is not None:
         if args['status'][0] == '!':
             query_filter[StatusCore._status] = {'$ne': args['status'][1:]}
         else:
             query_filter[StatusCore._status] = args['status']
         query['status'] = args['status']
     if args['type'] is not None:
         if args['type'][0] == '!':
             query_filter[StatusCore._type] = {'$ne': args['type'][1:]}
         else:
             query_filter[StatusCore._type] = args['type']
         query['type'] = args['type']
     if args['field'] is not None and args['value'] is not None:
         if args['value'][0] == '!':
             query_filter[StatusCore._details + '.' + args['field']] = {'$ne': args['value'][1:]}
         else:
             query_filter[StatusCore._details + '.' + args['field']] = args['value']
         query['field'] = args['field']
         query['value'] = args['value']
     i_field = 1
     next_field = True
     while next_field:
         if args['field{0}'.format(i_field)] is not None and args['value{0}'.format(i_field)] is not None:
             if args['value{0}'.format(i_field)][0] == '!':
                 query_filter[StatusCore._details + '.' + args['field{0}'.format(i_field)]] = {'$ne': args['value{0}'.format(i_field)][1:]}
             else:
                 query_filter[StatusCore._details + '.' + args['field{0}'.format(i_field)]] = args['value{0}'.format(i_field)]
             query['field{0}'.format(i_field)] = args['field{0}'.format(i_field)]
             query['value{0}'.format(i_field)] = args['value{0}'.format(i_field)]
             i_field += 1
         else:
             next_field = False
     statuses = StatusCore.list(query_filter=query_filter, sort=[(StatusCore._on, Base.DESC)], page=args['page'], nb_item=args['nb_status'])
     statuses_preped = [prep_status(status) for status in statuses]
     pagination = {'_links': {}}
     if statuses.count() > len(statuses):
         add_link_or_expand(pagination, 'self', 'statuses', **query)
         if args['page'] < statuses.count() // args['nb_status']:
             query['page'] = args['page'] + 1
             add_link_or_expand(pagination, 'next', 'statuses', **query)
         if args['page'] > 0:
             query['page'] = args['page'] - 1
             add_link_or_expand(pagination, 'prev', 'statuses', **query)
         query['page'] = 0
         add_link_or_expand(pagination, 'first', 'statuses', **query)
         query['page'] = statuses.count() // args['nb_status']
         add_link_or_expand(pagination, 'last', 'statuses', **query)
     return jsonify(result='Success', statuses=statuses_preped, count=len(statuses), total=statuses.count(), pagination=pagination['_links'])