Fix API tests

This commit is contained in:
Joseph Schorr 2015-04-29 17:30:24 -04:00
parent d5c70878c5
commit 5a8093bbea

View file

@ -7,8 +7,9 @@ from urllib import urlencode
from urlparse import urlparse, urlunparse, parse_qs
from endpoints.api import api_bp, api
from endpoints.building import PreparedBuild
from endpoints.webhooks import webhooks
from endpoints.trigger import BuildTrigger as BuildTriggerBase
from endpoints.trigger import BuildTriggerHandler
from app import app
from initdb import setup_database_for_testing, finished_database_for_testing
from data import model, database
@ -2425,44 +2426,58 @@ class TestOrganizationApplicationResetClientSecret(ApiTestCase):
class FakeBuildTrigger(BuildTriggerBase):
class FakeBuildTrigger(BuildTriggerHandler):
@classmethod
def service_name(cls):
return 'fakeservice'
def list_build_sources(self, auth_token):
return [{'first': 'source'}, {'second': auth_token}]
def list_build_sources(self):
return [{'first': 'source'}, {'second': self.auth_token}]
def list_build_subdirs(self, auth_token, config):
return [auth_token, 'foo', 'bar', config['somevalue']]
def list_build_subdirs(self):
return [self.auth_token, 'foo', 'bar', self.config['somevalue']]
def handle_trigger_request(self, request, auth_token, config):
return ('foo', ['bar'], 'build-name', 'subdir', {'foo': 'bar'})
def handle_trigger_request(self, request):
prepared = PreparedBuild(self.trigger)
prepared.build_name = 'build-name'
prepared.tags = ['bar']
prepared.dockerfile_id = 'foo'
prepared.subdirectory = 'subdir'
prepared.metadata = {'foo': 'bar'}
prepared.is_manual = False
return prepared
def is_active(self, config):
return 'active' in config and config['active']
def is_active(self):
return 'active' in self.config and self.config['active']
def activate(self, trigger_uuid, standard_webhook_url, auth_token, config):
config['active'] = True
return config, {}
def activate(self, standard_webhook_url):
self.config['active'] = True
return self.config, {}
def deactivate(self, auth_token, config):
config['active'] = False
return config
def deactivate(self):
self.config['active'] = False
return self.config
def manual_start(self, trigger, run_parameters=None):
return ('foo', ['bar'], 'build-name', 'subdir', {'foo': 'bar'})
def manual_start(self, run_parameters=None):
prepared = PreparedBuild(self.trigger)
prepared.build_name = 'build-name'
prepared.tags = ['bar']
prepared.dockerfile_id = 'foo'
prepared.subdirectory = 'subdir'
prepared.metadata = {'foo': 'bar'}
prepared.is_manual = True
return prepared
def dockerfile_url(self, auth_token, config):
def dockerfile_url(self):
return 'http://some/url'
def load_dockerfile_contents(self, auth_token, config):
if not 'dockerfile' in config:
def load_dockerfile_contents(self):
if not 'dockerfile' in self.config:
return None
return config['dockerfile']
return self.config['dockerfile']
def list_field_values(self, auth_token, config, field_name):
def list_field_values(self, field_name):
if field_name == 'test_field':
return [1, 2, 3]