From 08259725e3d112c2803e319f1ee300f2347f03a1 Mon Sep 17 00:00:00 2001 From: amercader Date: Thu, 1 Dec 2016 10:14:36 +0000 Subject: [PATCH] Rename plugin field to plugin_name --- goodtablesio/helpers/create.py | 4 ++-- goodtablesio/models.py | 4 ++-- goodtablesio/plugins/github/tasks.py | 8 +++++--- goodtablesio/services.py | 4 ---- goodtablesio/tests/factories.py | 7 ++++--- goodtablesio/tests/helpers/test_create.py | 4 ++-- 6 files changed, 15 insertions(+), 16 deletions(-) diff --git a/goodtablesio/helpers/create.py b/goodtablesio/helpers/create.py index a9b990d1..773d0f26 100644 --- a/goodtablesio/helpers/create.py +++ b/goodtablesio/helpers/create.py @@ -46,10 +46,10 @@ def create_job(validation_conf, job_id=None): return job_id -def insert_job_row(job_id, plugin='api', plugin_conf=None): +def insert_job_row(job_id, plugin_name='api', plugin_conf=None): row = { 'job_id': job_id, - 'plugin': plugin, + 'plugin_name': plugin_name, 'plugin_conf': plugin_conf, 'created': datetime.datetime.utcnow(), 'status': 'created', diff --git a/goodtablesio/models.py b/goodtablesio/models.py index 24039109..abd5cc25 100644 --- a/goodtablesio/models.py +++ b/goodtablesio/models.py @@ -6,7 +6,7 @@ class Job(): job_id = None status = 'created' - plugin = 'api' + plugin_name = 'api' plugin_conf = None created = None finished = None @@ -15,7 +15,7 @@ class Job(): def __init__(self, *args, **kwargs): self.job_id = kwargs.get('job_id') self.status = kwargs.get('status', 'created') - self.plugin = kwargs.get('plugin', 'api') + self.plugin_name = kwargs.get('plugin_name', 'api') self.plugin_conf = kwargs.get('plugin_conf') self.created = kwargs.get('created') self.finished = kwargs.get('finished') diff --git a/goodtablesio/plugins/github/tasks.py b/goodtablesio/plugins/github/tasks.py index 8f03ee78..851b90be 100644 --- a/goodtablesio/plugins/github/tasks.py +++ b/goodtablesio/plugins/github/tasks.py @@ -46,7 +46,7 @@ def post_task_handler(**kwargs): job = kwargs['retval'] - if job.get('plugin') != 'github': + if job.get('plugin_name') != 'github': return task_state = kwargs['state'] @@ -93,8 +93,10 @@ def _get_job_conf_url(clone_url, branch='master'): match = re.search(pattern, clone_url) user = match.group('user') repo = match.group('repo') - template = 'https://raw.githubusercontent.com/{user}/{repo}/{branch}/goodtables.yml' - job_conf = template.format(user=user, repo=repo, branch=branch) + template = '/{user}/{repo}/{branch}/goodtables.yml' + job_conf = template.format( + base='https://raw.githubusercontent.com', + user=user, repo=repo, branch=branch) return job_conf diff --git a/goodtablesio/services.py b/goodtablesio/services.py index 281596ad..e21c8504 100644 --- a/goodtablesio/services.py +++ b/goodtablesio/services.py @@ -1,5 +1,4 @@ import dataset -from sqlalchemy.dialects.postgresql import JSONB from . import config @@ -8,6 +7,3 @@ database = dataset.connect(config.DATABASE_URL) database.get_table('jobs', primary_id='job_id', primary_type='String') - -# TODO: get rid of this after #33 -database['jobs'].create_column('plugin_conf', JSONB) diff --git a/goodtablesio/tests/factories.py b/goodtablesio/tests/factories.py index c422b437..959df70f 100644 --- a/goodtablesio/tests/factories.py +++ b/goodtablesio/tests/factories.py @@ -18,7 +18,7 @@ class Meta: job_id = factory.Sequence(lambda n: str(uuid.uuid4())) created = factory.LazyAttribute(lambda o: datetime.datetime.utcnow()) - plugin = 'api' + plugin_name = 'api' plugin_conf = None status = 'created' finished = None @@ -28,14 +28,15 @@ class Meta: def _create(cls, model_class, *args, **kwargs): row = {} - for field in ('job_id', 'plugin', 'plugin_conf', + for field in ('job_id', 'plugin_name', 'plugin_conf', 'created', 'finished', 'report', 'status'): row[field] = kwargs.get(field) services.database['jobs'].insert(row, types={'created': DateTime, 'finished': DateTime, - 'report': JSONB}, + 'report': JSONB, + 'plugin_conf': JSONB}, ensure=True) return model_class(*args, **kwargs) diff --git a/goodtablesio/tests/helpers/test_create.py b/goodtablesio/tests/helpers/test_create.py index 30ad762e..0a8b82af 100644 --- a/goodtablesio/tests/helpers/test_create.py +++ b/goodtablesio/tests/helpers/test_create.py @@ -19,7 +19,7 @@ def test_insert_job_row(): assert job['job_id'] == 'my-id' assert job['status'] == 'created' - assert job['plugin'] == 'api' + assert job['plugin_name'] == 'api' assert job['plugin_conf'] is None assert job['created'] @@ -37,7 +37,7 @@ def test_insert_job_row_plugin_conf(): assert job['job_id'] == 'my-id' assert job['status'] == 'created' - assert job['plugin'] == 'my-plugin' + assert job['plugin_name'] == 'my-plugin' assert job['plugin_conf'] == {'some': 'conf'} assert job['created']