integrations-db: don't use default contructor to be consisten with other modules

usage.
This commit is contained in:
Marcin Kuzminski 2016-07-14 11:23:46 +02:00
parent efc1db0e2e
commit 169a7c5cf1
4 changed files with 16 additions and 25 deletions

View file

@ -179,7 +179,7 @@ class IntegrationSettingsViewBase(object):
try:
valid_data = schema.deserialize(params)
except colander.Invalid, e:
except colander.Invalid as e:
# Display error message and display form again.
self.request.session.flash(
_('Errors exist when saving plugin settings. '
@ -188,17 +188,17 @@ class IntegrationSettingsViewBase(object):
return self.settings_get(errors=e.asdict(), defaults=params)
if not self.integration:
self.integration = Integration(
integration_type=self.IntegrationType.key)
self.integration = Integration()
self.integration.integration_type = self.IntegrationType.key
if self.repo:
self.integration.repo = self.repo
Session.add(self.integration)
Session().add(self.integration)
self.integration.enabled = valid_data.pop('enabled', False)
self.integration.name = valid_data.pop('name')
self.integration.settings = valid_data
Session.commit()
Session().commit()
# Display success message and redirect.
self.request.session.flash(

View file

@ -3500,11 +3500,6 @@ class Integration(Base, BaseModel):
nullable=True, unique=None, default=None)
repo = relationship('Repository', lazy='joined')
def __init__(self, **kw):
settings = kw.pop('settings', {})
self.settings = settings
super(Integration, self).__init__(**kw)
def __repr__(self):
if self.repo:
scope = 'repo=%r' % self.repo
@ -3512,6 +3507,3 @@ class Integration(Base, BaseModel):
scope = 'global'
return '<Integration(%r, %r)>' % (self.integration_type, scope)
def settings_as_dict(self):
return json.loads(self.settings_json)

View file

@ -63,13 +63,13 @@ class IntegrationModel(BaseModel):
def create(self, IntegrationType, enabled, name, settings, repo=None):
""" Create an IntegrationType integration """
integration = Integration(
integration_type=IntegrationType.key,
settings={},
repo=repo,
enabled=enabled,
name=name
)
integration = Integration()
integration.integration_type = IntegrationType.key
integration.settings = {}
integration.repo = repo
integration.enabled = enabled
integration.name = name
self.sa.add(integration)
self.sa.commit()
return integration

View file

@ -71,11 +71,10 @@ def slack_settings():
@pytest.fixture
def slack_integration(request, app, slack_settings):
integration = Integration(
name='test slack integration',
enabled=True,
integration_type=SlackIntegrationType.key
)
integration = Integration()
integration.name = 'test slack integration'
integration.enabled = True
integration.integration_type = SlackIntegrationType.key
integration.settings = slack_settings
Session().add(integration)
Session().commit()