class TestResultGet(TestResultBase): def setUp(self): super(TestResultGet, self).setUp() self.req_10d_before = self._create_changed_date(days=-10) self.req_d_id = self._create_d() self.req_10d_later = self._create_changed_date(days=10) @executor.get(httplib.OK, 'assert_res') def test_getOne(self): return self.req_d_id @executor.query(httplib.OK, '_query_success', 3) def test_queryPod(self): return self._set_query('pod') @executor.query(httplib.OK, '_query_success', 3) def test_queryProject(self): return self._set_query('project') @executor.query(httplib.OK, '_query_success', 3) def test_queryTestcase(self): return self._set_query('case') @executor.query(httplib.OK, '_query_success', 3) def test_queryVersion(self): return self._set_query('version') @executor.query(httplib.OK, '_query_success', 3) def test_queryInstaller(self): return self._set_query('installer') @executor.query(httplib.OK, '_query_success', 3) def test_queryBuildTag(self): return self._set_query('build_tag') @executor.query(httplib.OK, '_query_success', 3) def test_queryScenario(self): return self._set_query('scenario') @executor.query(httplib.OK, '_query_success', 3) def test_queryCriteria(self): return self._set_query('criteria') @executor.query(httplib.BAD_REQUEST, message.must_int('period')) def test_queryPeriodNotInt(self): return self._set_query(period='a') @executor.query(httplib.OK, '_query_period_one', 1) def test_queryPeriodSuccess(self): return self._set_query(period=5) @executor.query(httplib.BAD_REQUEST, message.must_int('last')) def test_queryLastNotInt(self): return self._set_query(last='a') @executor.query(httplib.OK, '_query_last_one', 1) def test_queryLast(self): return self._set_query(last=1) @executor.query(httplib.OK, '_query_period_one', 1) def test_combination(self): return self._set_query('pod', 'project', 'case', 'version', 'installer', 'build_tag', 'scenario', 'criteria', period=5) @executor.query(httplib.OK, '_query_success', 0) def test_notFound(self): return self._set_query('project', 'case', 'version', 'installer', 'build_tag', 'scenario', 'criteria', pod='notExistPod', period=1) @executor.query(httplib.OK, '_query_success', 1) def test_filterErrorStartdate(self): self._create_error_start_date(None) self._create_error_start_date('None') self._create_error_start_date('null') self._create_error_start_date('') return self._set_query(period=5) def _query_success(self, body, number): self.assertEqual(number, len(body.results)) def _query_last_one(self, body, number): self.assertEqual(number, len(body.results)) self.assert_res(body.results[0], self.req_10d_later) def _query_period_one(self, body, number): self.assertEqual(number, len(body.results)) self.assert_res(body.results[0], self.req_d) def _create_error_start_date(self, start_date): req = copy.deepcopy(self.req_d) req.start_date = start_date self.create(req) return req def _create_changed_date(self, **kwargs): req = copy.deepcopy(self.req_d) req.start_date = datetime.now() + timedelta(**kwargs) req.stop_date = str(req.start_date + timedelta(minutes=10)) req.start_date = str(req.start_date) self.create(req) return req def _set_query(self, *args, **kwargs): def get_value(arg): if arg in ['pod', 'project', 'case']: return getattr(self.req_d, arg + '_name') else: return getattr(self.req_d, arg) query = [] for arg in args: query.append((arg, get_value(arg))) for k, v in kwargs.iteritems(): query.append((k, v)) return urllib.urlencode(query)
class TestResultGet(TestResultBase): def setUp(self): super(TestResultGet, self).setUp() self.req_10d_before = self._create_changed_date(days=-10) self.req_d_id = self._create_d() self.req_10d_later = self._create_changed_date(days=10) @executor.get(httplib.OK, 'assert_res') def test_getOne(self): return self.req_d_id @executor.query(httplib.OK, '_query_success', 3) def test_queryPod(self): return self._set_query('pod') @executor.query(httplib.OK, '_query_success', 3) def test_queryProject(self): return self._set_query('project') @executor.query(httplib.OK, '_query_success', 3) def test_queryTestcase(self): return self._set_query('case') @executor.query(httplib.OK, '_query_success', 3) def test_queryVersion(self): return self._set_query('version') @executor.query(httplib.OK, '_query_success', 3) def test_queryInstaller(self): return self._set_query('installer') @executor.query(httplib.OK, '_query_success', 3) def test_queryBuildTag(self): return self._set_query('build_tag') @executor.query(httplib.OK, '_query_success', 3) def test_queryScenario(self): return self._set_query('scenario') @executor.query(httplib.OK, '_query_success', 3) def test_queryTrustIndicator(self): return self._set_query('trust_indicator') @executor.query(httplib.OK, '_query_success', 3) def test_queryCriteria(self): return self._set_query('criteria') @executor.query(httplib.BAD_REQUEST, message.must_int('period')) def test_queryPeriodNotInt(self): return self._set_query('period=a') @executor.query(httplib.OK, '_query_period_one', 1) def test_queryPeriodSuccess(self): return self._set_query('period=5') @executor.query(httplib.BAD_REQUEST, message.must_int('last')) def test_queryLastNotInt(self): return self._set_query('last=a') @executor.query(httplib.OK, '_query_last_one', 1) def test_queryLast(self): return self._set_query('last=1') @executor.query(httplib.OK, '_query_success', 4) def test_queryPublic(self): self._create_public_data() return self._set_query('') @executor.query(httplib.OK, '_query_success', 1) def test_queryPrivate(self): self._create_private_data() return self._set_query('public=false') @executor.query(httplib.OK, '_query_period_one', 1) def test_combination(self): return self._set_query('pod', 'project', 'case', 'version', 'installer', 'build_tag', 'scenario', 'trust_indicator', 'criteria', 'period=5') @executor.query(httplib.OK, '_query_success', 0) def test_notFound(self): return self._set_query('pod=notExistPod', 'project', 'case', 'version', 'installer', 'build_tag', 'scenario', 'trust_indicator', 'criteria', 'period=1') @executor.query(httplib.OK, '_query_success', 1) def test_filterErrorStartdate(self): self._create_error_start_date(None) self._create_error_start_date('None') self._create_error_start_date('null') self._create_error_start_date('') return self._set_query('period=5') def _query_success(self, body, number): self.assertEqual(number, len(body.results)) def _query_last_one(self, body, number): self.assertEqual(number, len(body.results)) self.assert_res(body.results[0], self.req_10d_later) def _query_period_one(self, body, number): self.assertEqual(number, len(body.results)) self.assert_res(body.results[0], self.req_d) def _create_error_start_date(self, start_date): req = copy.deepcopy(self.req_d) req.start_date = start_date self.create(req) return req def _create_changed_date(self, **kwargs): req = copy.deepcopy(self.req_d) req.start_date = datetime.now() + timedelta(**kwargs) req.stop_date = str(req.start_date + timedelta(minutes=10)) req.start_date = str(req.start_date) self.create(req) return req def _create_public_data(self, **kwargs): req = copy.deepcopy(self.req_d) req.public = 'true' self.create(req) return req def _create_private_data(self, **kwargs): req = copy.deepcopy(self.req_d) req.public = 'false' self.create(req) return req def _set_query(self, *args): def get_value(arg): return self.__getattribute__(arg) \ if arg != 'trust_indicator' else self.trust_indicator.current uri = '' for arg in args: if arg: if '=' in arg: uri += arg + '&' else: uri += '{}={}&'.format(arg, get_value(arg)) return uri[0:-1]
def get_int(self, key, value): try: value = int(value) except Exception: raises.BadRequest(message.must_int(key)) return value
class DeployResultGet(DeployResultBase): def setUp(self): super(DeployResultGet, self).setUp() self.req_10d_before = self._create_changed_date(days=-10) self.req_d_id = self._create_d() self.req_10d_later = self._create_changed_date(days=10) @executor.query(httplib.OK, '_query_success', 3) def test_queryInstaller(self): return self._set_query('installer') @executor.query(httplib.OK, '_query_success', 3) def test_queryVersion(self): return self._set_query('version') @executor.query(httplib.OK, '_query_success', 3) def test_queryPod(self): return self._set_query('pod_name') @executor.query(httplib.OK, '_query_success', 3) def test_queryJob(self): return self._set_query('job_name') @executor.query(httplib.OK, '_query_success', 1) def test_queryBuildId(self): return self._set_query('build_id') @executor.query(httplib.OK, '_query_success', 3) def test_queryScenario(self): return self._set_query('scenario') @executor.query(httplib.OK, '_query_success', 3) def test_queryUpstreamJobName(self): return self._set_query('upstream_job_name') @executor.query(httplib.OK, '_query_success', 1) def test_queryUpstreamBuildId(self): return self._set_query('upstream_build_id') @executor.query(httplib.OK, '_query_success', 3) def test_queryCriteria(self): return self._set_query('criteria') @executor.query(httplib.BAD_REQUEST, message.must_int('period')) def test_queryPeriodNotInt(self): return self._set_query(period='a') @executor.query(httplib.OK, '_query_period_one', 1) def test_queryPeriodSuccess(self): return self._set_query(period=5) @executor.query(httplib.BAD_REQUEST, message.must_int('last')) def test_queryLastNotInt(self): return self._set_query(last='a') @executor.query(httplib.OK, '_query_last_one', 1) def test_queryLast(self): return self._set_query(last=1) @executor.query(httplib.OK, '_query_period_one', 1) def test_combination(self): return self._set_query('installer', 'version', 'pod_name', 'job_name', 'build_id', 'scenario', 'upstream_job_name', 'upstream_build_id', 'criteria', period=5) @executor.query(httplib.OK, '_query_success', 1) def test_filterErrorStartdate(self): self._create_error_start_date(None) self._create_error_start_date('None') self._create_error_start_date('null') self._create_error_start_date('') return self._set_query(period=5) def _query_success(self, body, number): self.assertEqual(number, len(body.deployresults)) def _query_last_one(self, body, number): self.assertEqual(number, len(body.deployresults)) self.assert_res(body.deployresults[0], self.req_10d_later) def _query_period_one(self, body, number): self.assertEqual(number, len(body.deployresults)) self.assert_res(body.deployresults[0], self.req_d) def _create_error_start_date(self, start_date): req = copy.deepcopy(self.req_d) req.start_date = start_date self.create(req) return req def _create_changed_date(self, **kwargs): req = copy.deepcopy(self.req_d) req.build_id = req.build_id + kwargs.get('days') req.upstream_build_id = req.upstream_build_id + kwargs.get('days') req.start_date = datetime.now() + timedelta(**kwargs) req.stop_date = str(req.start_date + timedelta(minutes=10)) req.start_date = str(req.start_date) self.create(req) return req def _set_query(self, *args, **kwargs): query = [] for arg in args: query.append((arg, getattr(self.req_d, arg))) for k, v in kwargs.iteritems(): query.append((k, v)) return urllib.urlencode(query)