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
def test_post_purge(self): from core.Status import Status from core.TestType import TestType from core.Base import Base test_type = str(uuid.uuid4()) tt = TestType(test_type) tt.save() my_run = str(uuid.uuid4()) data = {'action': 'REMOVE', 'condition': {'operator': 'EQUAL', 'field': str(uuid.uuid4()), 'value': str(uuid.uuid4())}} json_query = prepare_json_query(data) rv = self.app_test_type.post('/test/test_types/{0}/purge'.format(str(uuid.uuid4())), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 404 data = {'action': str(uuid.uuid4()), 'condition': {'operator': 'EQUAL', 'field': str(uuid.uuid4()), 'value': str(uuid.uuid4())}} json_query = prepare_json_query(data) rv = self.app_test_type.post('/test/test_types/{0}/purge'.format(test_type), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 400 data = {'action': 'REMOVE', 'condition': {'operator': str(uuid.uuid4()), 'field': str(uuid.uuid4()), 'value': str(uuid.uuid4())}} json_query = prepare_json_query(data) rv = self.app_test_type.post('/test/test_types/{0}/purge'.format(test_type), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 400 data = {'action': 'REMOVE', 'condition': {'operator': 'EQUAL', 'field': str(uuid.uuid4()), 'value': str(uuid.uuid4())}} json_query = prepare_json_query(data) rv = self.app_test_type.post('/test/test_types/{0}/purge'.format(test_type), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 200 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'] == data['action'] assert res['purge']['condition'] == data['condition'] 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 res['test_type']['purge'] == '/test/test_types/{0}/purge'.format(test_type)
def test_save(self): from core.TestType import TestType from core.Base import Base my_type = str(uuid.uuid4()) doc = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] test_type = TestType(my_type, doc) test_type.save() ast = Base().get_all(TestType.collection, {}) assert ast.count() == 1 assert ast[0]['type'] == my_type assert ast[0]['doc_fields'] == doc
def test_get_collection(self): from core.TestType import TestType my_type1 = str(uuid.uuid4()) doc1 = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] test_type1 = TestType(my_type1, doc1) test_type1.save() my_type2 = str(uuid.uuid4()) doc2 = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] test_type2 = TestType(my_type2, doc2) test_type2.save() rv = self.app_test_type.get('/test/test_types') assert rv.status_code == 200 res = json.loads(rv.data.decode('utf-8')) assert res['count'] == 2 assert [tt['type'] for tt in res['test_types']] == [my_type1, my_type2]
def test_get(self): from core.TestType import TestType my_type1 = str(uuid.uuid4()) doc1 = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] test_type1 = TestType(my_type1, doc1) test_type1.save() my_type2 = str(uuid.uuid4()) doc2 = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] test_type2 = TestType(my_type2, doc2) test_type2.save() rv = self.app_test_type.get('/test/test_types/{0}'.format(my_type1)) assert rv.status_code == 200 res = json.loads(rv.data.decode('utf-8')) assert res['test_type']['type'] == my_type1 rv = self.app_test_type.get('/test/test_types/{0}'.format(str(uuid.uuid4()))) assert rv.status_code == 404
def test_get_one(self): from core.TestType import TestType from core.Base import Base my_type1 = str(uuid.uuid4()) doc1 = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] test_type1 = TestType(my_type1, doc1) test_type1.save() my_type2 = str(uuid.uuid4()) doc2 = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] test_type2 = TestType(my_type2, doc2) test_type2.save() type2 = TestType.get_one({TestType._test_type: my_type2}) assert type2._doc_fields == doc2 assert type2._test_type == my_type2 type1 = TestType.get_one({TestType._test_type: my_type1}) assert type1._doc_fields == doc1 assert type1._test_type == my_type1
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
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_get_all(self): from core.TestType import TestType from core.Base import Base my_type1 = str(uuid.uuid4()) doc1 = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] test_type1 = TestType(my_type1, doc1) test_type1.save() my_type2 = str(uuid.uuid4()) doc2 = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] test_type2 = TestType(my_type2, doc2) test_type2.save() types = TestType.get_all() assert len(types) == 2 types = TestType.get_all({TestType._test_type: my_type2}) assert len(types) == 1 assert types[0]._doc_fields == doc2 types = TestType.get_all(query_filter={TestType._test_type: my_type1}) assert len(types) == 1 assert types[0]._doc_fields == doc1
def test_patch_testtype(self): from core.TestType import TestType my_type1 = str(uuid.uuid4()) doc1 = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] test_type1 = TestType(my_type1, doc1) test_type1.save() my_type2 = str(uuid.uuid4()) doc2 = [str(uuid.uuid4()), str(uuid.uuid4()), str(uuid.uuid4())] test_type2 = TestType(my_type2, doc2) test_type2.save() my_id1 = str(uuid.uuid4()) data1 = {'doc_fields_to_index': [str(uuid.uuid4()), str(uuid.uuid4())]} json_query = prepare_json_query(data1) rv = self.app_test_type.patch('/test/test_types/{0}'.format(my_type1), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 200 res = json.loads(rv.data.decode('utf-8')) assert res['test_type']['type'] == my_type1 assert res['test_type']['doc_fields_to_index'] == data1['doc_fields_to_index'] rv = self.app_test_type.patch('/test/test_types/{0}'.format(str(uuid.uuid4())), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 404
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_post_run(self): from core.Status import Status from core.TestType import TestType from core.Base import Base test_type = str(uuid.uuid4()) # field1 = 'browser' # field2 = 'environment' tt = TestType(test_type)#, doc_fields_to_index=[field1, field2]) tt.save() my_run = str(uuid.uuid4()) data = {'run_type': my_run, 'modifier': 'ANY', 'condition': {'operator': 'EQUAL', 'field': str(uuid.uuid4()), 'value': str(uuid.uuid4())}} json_query = prepare_json_query(data) rv = self.app_test_type.post('/test/test_types/{0}/runs'.format(str(uuid.uuid4())), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 404 data = {'run_type': my_run, 'modifier': str(uuid.uuid4()), 'condition': {'operator': 'EQUAL', 'field': str(uuid.uuid4()), 'value': str(uuid.uuid4())}} json_query = prepare_json_query(data) rv = self.app_test_type.post('/test/test_types/{0}/runs'.format(test_type), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 400 data = {'run_type': my_run, 'modifier': 'ANY', 'condition': {'operator': str(uuid.uuid4()), 'field': str(uuid.uuid4()), 'value': str(uuid.uuid4())}} json_query = prepare_json_query(data) rv = self.app_test_type.post('/test/test_types/{0}/runs'.format(test_type), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 400 data = {'run_type': my_run, 'modifier': 'ANY', 'condition': {'operator': 'OR', 'field': str(uuid.uuid4()), 'value': str(uuid.uuid4())}} json_query = prepare_json_query(data) rv = self.app_test_type.post('/test/test_types/{0}/runs'.format(test_type), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 400 data = {'run_type': my_run, 'modifier': 'ANY', 'condition': {'operator': 'OR', 'part1': str(uuid.uuid4()), 'part2': {'operator': 'EQUAL', 'field': str(uuid.uuid4()), 'value': str(uuid.uuid4())}}} json_query = prepare_json_query(data) rv = self.app_test_type.post('/test/test_types/{0}/runs'.format(test_type), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 400 data = {'run_type': my_run, 'modifier': 'ANY', 'condition': {'operator': 'OR', 'part1': {'operator': 'EQUAL', 'field': str(uuid.uuid4()), 'value': str(uuid.uuid4())}, 'part2': str(uuid.uuid4())}} json_query = prepare_json_query(data) rv = self.app_test_type.post('/test/test_types/{0}/runs'.format(test_type), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 400 data = {'run_type': my_run, 'modifier': 'ALL', 'condition': {'operator': 'EQUAL', 'field': str(uuid.uuid4()), 'value': str(uuid.uuid4())}} json_query = prepare_json_query(data) rv = self.app_test_type.post('/test/test_types/{0}/runs'.format(test_type), headers=json_query['headers'], data=json_query['json']) assert rv.status_code == 200