Esempio n. 1
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('test_id', type=str, help='test ID', required=True, location='json')
     parser.add_argument('type', type=str, help='test type', required=True, location='json')
     parser.add_argument('owner', type=str, help='test owner', required=False, location='json')
     args = parser.parse_args()
     test = TestCore(test_id=args['test_id'], test_type=args['type'], owner=args['owner'])
     test.save()
     test = prep_test(test)
     return jsonify(result='Success', test=test)
Esempio n. 2
0
 def test_get_all(self):
     from core.Test import Test
     test_id1 = str(uuid.uuid4())
     test_id2 = str(uuid.uuid4())
     test_id3 = str(uuid.uuid4())
     owner = str(uuid.uuid4())
     owner2 = str(uuid.uuid4())
     test_type = str(uuid.uuid4())
     Test(test_id1, owner, test_type).save()
     Test(test_id2, owner, test_type).save()
     Test(test_id3, owner2, test_type).save()
     test = Test(owner=owner)
     atl = Test.get_all(test.to_dict())
     assert len(atl) == 2
     assert atl[0]._test_id == test_id1
     assert atl[1]._test_id == test_id2
Esempio n. 3
0
def list_get(test_type=None):
    query_filter = {}
    if test_type is not None:
        query_filter = {TestCore._type: test_type}
    tests = TestCore.get_all(query_filter)#(sort=[(StatusCore._on, Base.DESC)])
    tests = [prep_test(test) for test in tests]
    return tests
Esempio n. 4
0
 def test_save(self):
     from core.Test import Test
     from core.Base import Base
     test_id = str(uuid.uuid4())
     owner = str(uuid.uuid4())
     test_type = str(uuid.uuid4())
     test = Test(test_id, owner, test_type)
     now = datetime.datetime.now()
     res = test.save()
     assert res
     at = Base().get_all(Test.collection, {})
     assert at.count() == 1
     assert at[0]['_id'] == test_id
     assert at[0]['owner'] == owner
     assert at[0]['test_id'] == test_id
     assert at[0]['type'] == test_type
     assert at[0]['last_seen'] < now + datetime.timedelta(seconds=1)
Esempio n. 5
0
 def test_get_all_ownerless(self):
     from core.Test import Test
     test_id1 = str(uuid.uuid4())
     test_id2 = str(uuid.uuid4())
     test_id3 = str(uuid.uuid4())
     test_id4 = str(uuid.uuid4())
     owner1 = str(uuid.uuid4())
     test_type1 = str(uuid.uuid4())
     test_type2 = str(uuid.uuid4())
     Test(test_id1, owner1, test_type1).save()
     Test(test_id2, owner1, test_type2).save()
     Test(test_id3, None, test_type1).save()
     Test(test_id4, None, test_type2).save()
     test = Test(test_type=test_type1)
     ato = test.get_all_ownerless()
     assert len(ato) == 1
     assert ato[0]._test_id == test_id3
     ato = Test().get_all_ownerless()
     assert len(ato) == 2
     assert ato[0]._test_id == test_id3
     assert ato[1]._test_id == test_id4
Esempio n. 6
0
 def test_repr_getter_setter(self):
     from core.Test import Test
     test_id = str(uuid.uuid4())
     owner = str(uuid.uuid4())
     test_type = str(uuid.uuid4())
     test = Test(test_id, owner, test_type)
     assert '{0}'.format(test) == '<Test {0} ({1}) by {2}>'.format(test_id, test_type, owner)
     assert test.to_dict() == {'test_id': test_id, 'owner': owner, 'type': test_type}
     test._last_seen = datetime.datetime.now()
     assert test.to_dict()['last_seen'] == test._last_seen
     test2 = test.from_dict(test.to_dict())
     assert test2.to_dict() == test.to_dict()
Esempio n. 7
0
 def test_get_one(self):
     from core.Test import Test
     test_id1 = str(uuid.uuid4())
     test_id2 = str(uuid.uuid4())
     test_id3 = str(uuid.uuid4())
     owner1 = str(uuid.uuid4())
     owner2 = str(uuid.uuid4())
     test_type = str(uuid.uuid4())
     Test(test_id1, owner1, test_type).save()
     Test(test_id2, owner1, test_type).save()
     Test(test_id2, owner2, test_type).save()
     test = Test(test_id=test_id1)
     one = Test.get_one(test.to_dict())
     assert one is not None
     assert one._test_id == test_id1
     assert one._owner == owner1
     test = Test(test_id=test_id2)
     one = Test.get_one(test.to_dict())
     assert one._test_id == test_id2
     assert one._owner == owner2
     assert one is not None
     test = Test(test_id=test_id3)
     one = Test.get_one(test.to_dict())
     assert one is None
Esempio n. 8
0
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