def test_index(self): from core.Index import Index from core.Status import Status from core.TestType import TestType from core.Base import Base test_id = str(uuid.uuid4()) test_status = 'SUCCESS' test_type = str(uuid.uuid4()) field1 = 'browser' field2 = 'environment' TestType(test_type, doc_fields_to_index=[field1, field2]).save() details1 = {field1: 'Firefox', field2: 'master'} status1 = Status(test_id, test_type, test_status, details=details1) status1.save() details2 = {field1: 'Chrome', field2: 'master'} status2 = Status(test_id, test_type, test_status, details=details2) status2.save() rv = self.app_test_type.get('/test/test_types/{0}/indexes/{1}'.format(str(uuid.uuid4()), field1)) assert rv.status_code == 404 rv = self.app_test_type.get('/test/test_types/{0}/indexes/{1}'.format(test_type, str(uuid.uuid4()))) assert rv.status_code == 404 rv = self.app_test_type.get('/test/test_types/{0}/indexes/{1}'.format(test_type, field1)) assert rv.status_code == 200 res = json.loads(rv.data.decode('utf-8')) assert res['index']['field'] == field1 assert res['index']['type'] == test_type assert sorted(res['index']['values']) == sorted(['Firefox', 'Chrome'])
def test_get(self): from core.Status import Status test_id = str(uuid.uuid4()) test_status = 'FAILURE' details = {'browser': random.choice(['Firefox', 'Chrome'])} test_type = str(uuid.uuid4()) status = Status(test_id, test_type, test_status, details=details) status.save() status_jid = Status(base_id=status._id) status_get = status_jid.get() assert status_get.to_dict() == status.to_dict()
def test_remove(self): from core.Status import Status from core.Base import Base test_id1 = str(uuid.uuid4()) test_status1 = random.choice(['SUCCESS', 'FAILURE']) test_type = str(uuid.uuid4()) details = {'browser': random.choice(['Firefox', 'Chrome'])} status1 = Status(test_id1, test_type, test_status1, details=details, last=True) status1.save() test_id2 = str(uuid.uuid4()) test_status2 = random.choice(['SUCCESS', 'FAILURE']) status2 = Status(test_id2, test_type, test_status2, details=details, last=True) status2.save() status2.remove() ast = Base().get_all(Status.collection, {}) assert ast.count() == 1 assert ast[0]['test_id'] == test_id1
def test_get_run(self): from core.Status import Status from core.TestType import TestType from core.Base import Base test_id = str(uuid.uuid4()) test_status = 'SUCCESS' test_type = str(uuid.uuid4()) field1 = 'browser' field2 = 'environment' tt = TestType(test_type, doc_fields_to_index=[field1, field2]) tt.add_run_type('new', 'ANY', {'operator': 'EQUAL', 'field': 1, 'value': 1}) tt.save() details1 = {field1: 'Firefox', field2: 'master'} status1 = Status(test_id, test_type, test_status, details=details1) status1.save() rv = self.app_test_type.get('/test/test_types/{0}/runs/{1}'.format(str(uuid.uuid4()), 'default')) assert rv.status_code == 404 rv = self.app_test_type.get('/test/test_types/{0}/runs/{1}'.format(test_type, str(uuid.uuid4()))) assert rv.status_code == 404 rv = self.app_test_type.get('/test/test_types/{0}/runs/{1}'.format(test_type, 'default')) assert rv.status_code == 200 res = json.loads(rv.data.decode('utf-8')) assert res['result'] == 'Success' assert res['run']['modifier'] == TestType._default_run['modifier'] assert res['run']['condition'] == TestType._default_run['condition'].to_dict() rv = self.app_test_type.get('/test/test_types/{0}/runs/{1}'.format(test_type, 'new')) assert rv.status_code == 200 res = json.loads(rv.data.decode('utf-8')) assert res['result'] == 'Success' assert res['run']['modifier'] == 'ANY' assert res['run']['condition'] == {'operator': 'EQUAL', 'field': 1, 'value': 1} rv = self.app_test_type.get('/test/test_types/{0}/runs'.format(str(uuid.uuid4()))) assert rv.status_code == 404 rv = self.app_test_type.get('/test/test_types/{0}/runs'.format(test_type)) assert rv.status_code == 200 res = json.loads(rv.data.decode('utf-8')) assert res['result'] == 'Success' assert res['count'] == 2 rv = self.app_test_type.get('/test/test_types/{0}'.format(test_type)) assert rv.status_code == 200 res = json.loads(rv.data.decode('utf-8')) assert res['result'] == 'Success' assert 'run' not in res['test_type']
def test_save(self): from core.Status import Status from core.Test import Test from core.Index import Index from core.TestType import TestType from core.Base import Base test_id = str(uuid.uuid4()) test_status = random.choice(['SUCCESS', 'FAILURE']) test_type = str(uuid.uuid4()) details = {'browser': random.choice(['Firefox', 'Chrome'])} status = Status(test_id, test_type, test_status, details=details) TestType(test_type, doc_fields_to_index=['browser']).save() now = datetime.datetime.now() status.save() ast = Base().get_all(Status.collection, {}) assert ast.count() == 1 assert ast[0]['test_id'] == test_id assert ast[0]['status'] == test_status assert ast[0]['details'] == details assert ast[0]['type'] == test_type assert ast[0]['on'] < now + datetime.timedelta(seconds=1) at = Base().get_all(Test.collection, {}) assert at.count() == 1 assert at[0]['test_id'] == test_id assert at[0]['type'] == test_type assert at[0]['last_seen'] < ast[0]['on'] + datetime.timedelta(seconds=1) st = Base().get_one(Index.collection, {}) assert st['type'] == test_type assert st['field'] == 'browser' assert st['values'] == [details['browser']] st = Base().get_one(TestType.collection, {}) assert st['type'] == test_type assert st['doc_fields'] == ['browser'] test_id = str(uuid.uuid4()) test_status = 'TO_RERUN' test_type = str(uuid.uuid4()) status = Status(test_id, test_type, test_status) now = datetime.datetime.now() status.save() st = Base().get_one(Status.collection, {'test_id': test_id}) assert st['status'] == 'CUSTOM' assert st['details']['original_status'] == test_status
def test_update_last(self): from core.Status import Status from core.Base import Base test_id1 = str(uuid.uuid4()) test_status1 = random.choice(['SUCCESS', 'FAILURE']) test_type = str(uuid.uuid4()) details = {'browser': random.choice(['Firefox', 'Chrome'])} status1 = Status(test_id1, test_type, test_status1, details=details, last=True) status1.save() test_id2 = str(uuid.uuid4()) test_status2 = random.choice(['SUCCESS', 'FAILURE']) status2 = Status(test_id2, test_type, test_status2, details=details, last=True) status2.save() st = Base().get_one(Status.collection, {}) assert st['last'] == True status2.update_last() ast = Base().get_all(Status.collection, {'last': True}) assert ast.count() == 1 st = Base().get_one(Status.collection, {'test_id': test_id2}) assert st['last'] == False
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()
def test_get_purge(self): from core.Status import Status from core.TestType import TestType from core.Base import Base test_id = str(uuid.uuid4()) test_status = 'SUCCESS' test_type = str(uuid.uuid4()) field1 = 'browser' field2 = 'environment' tt = TestType(test_type, doc_fields_to_index=[field1, field2]) tt.save() details1 = {field1: 'Firefox', field2: 'master'} status1 = Status(test_id, test_type, test_status, details=details1) status1.save() rv = self.app_test_type.get('/test/test_types/{0}/purge'.format(str(uuid.uuid4()))) assert rv.status_code == 404 rv = self.app_test_type.get('/test/test_types/{0}/purge'.format(test_type)) assert rv.status_code == 200 res = json.loads(rv.data.decode('utf-8')) assert res['result'] == 'Success' assert res['purge']['action'] == TestType._default_purge['action'] assert res['purge']['condition'] == TestType._default_purge['condition'].to_dict()
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()
def test_index_large_status(self): from core.Index import Index from core.Status import Status from core.TestType import TestType from core.Base import Base test_id = str(uuid.uuid4()) test_status = random.choice(['SUCCESS', 'FAILURE']) test_type = str(uuid.uuid4()) field1 = 'browser' field2 = 'environment' TestType(test_type, doc_fields_to_index=[field1, field2]).save() details1 = {field1: 'Firefox', field2: 'master'} status1 = Status(test_id, test_type, test_status, details=details1) status1.save() details2 = {field1: 'Chrome', field2: 'master'} status2 = Status(test_id, test_type, test_status, details=details2) status2.save() ast = Base().get_all(Index.collection, {'field': 'browser'}) assert ast.count() == 1 assert sorted(ast[0]['values']) == sorted(['Chrome', 'Firefox']) ast = Base().get_all(Index.collection, {'field': 'environment'}) assert ast.count() == 1 assert ast[0]['values'] == ['master']