From 42b107e4844732cdb9207bcf7dc2788cec1ef694 Mon Sep 17 00:00:00 2001 From: Yong Sheng Gong Date: Fri, 23 Aug 2013 15:51:47 +0800 Subject: [PATCH] change oauth.consumer description into nullable Change-Id: I158e916f1f422882b83f648d7720f8f87a4c5813 Fixes: Bug #1215482 --- keystone/contrib/oauth1/backends/sql.py | 2 +- .../003_consumer_description_nullalbe.py | 31 +++++++++++++++++++ keystone/tests/test_v3_oauth1.py | 20 +++++++++--- 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 keystone/contrib/oauth1/migrate_repo/versions/003_consumer_description_nullalbe.py diff --git a/keystone/contrib/oauth1/backends/sql.py b/keystone/contrib/oauth1/backends/sql.py index eb18927b34..4c52aba1b7 100644 --- a/keystone/contrib/oauth1/backends/sql.py +++ b/keystone/contrib/oauth1/backends/sql.py @@ -29,7 +29,7 @@ class Consumer(sql.ModelBase, sql.DictBase): __tablename__ = 'consumer' attributes = ['id', 'description', 'secret'] id = sql.Column(sql.String(64), primary_key=True, nullable=False) - description = sql.Column(sql.String(64), nullable=False) + description = sql.Column(sql.String(64), nullable=True) secret = sql.Column(sql.String(64), nullable=False) extra = sql.Column(sql.JsonBlob(), nullable=False) diff --git a/keystone/contrib/oauth1/migrate_repo/versions/003_consumer_description_nullalbe.py b/keystone/contrib/oauth1/migrate_repo/versions/003_consumer_description_nullalbe.py new file mode 100644 index 0000000000..3cfc547651 --- /dev/null +++ b/keystone/contrib/oauth1/migrate_repo/versions/003_consumer_description_nullalbe.py @@ -0,0 +1,31 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 OpenStack Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import sqlalchemy as sql + + +def upgrade(migrate_engine): + meta = sql.MetaData() + meta.bind = migrate_engine + user_table = sql.Table('consumer', meta, autoload=True) + user_table.c.description.alter(nullable=True) + + +def downgrade(migrate_engine): + meta = sql.MetaData() + meta.bind = migrate_engine + user_table = sql.Table('consumer', meta, autoload=True) + user_table.c.description.alter(nullable=False) diff --git a/keystone/tests/test_v3_oauth1.py b/keystone/tests/test_v3_oauth1.py index a0ae5fc60e..742fd1abe3 100644 --- a/keystone/tests/test_v3_oauth1.py +++ b/keystone/tests/test_v3_oauth1.py @@ -121,18 +121,30 @@ def _authorize_request_token(self, request_id): class ConsumerCRUDTests(OAuth1Tests): - def test_consumer_create(self): - description = uuid.uuid4().hex - ref = {'description': description} + def _consumer_create(self, description=None, description_flag=True): + if description_flag: + ref = {'description': description} + else: + ref = {} resp = self.post( '/OS-OAUTH1/consumers', body={'consumer': ref}) consumer = resp.result.get('consumer') consumer_id = consumer.get('id') - self.assertEqual(consumer.get('description'), description) + self.assertEqual(consumer['description'], description) self.assertIsNotNone(consumer_id) self.assertIsNotNone(consumer.get('secret')) + def test_consumer_create(self): + description = uuid.uuid4().hex + self._consumer_create(description=description) + + def test_consumer_create_none_desc_1(self): + self._consumer_create() + + def test_consumer_create_none_desc_2(self): + self._consumer_create(description_flag=False) + def test_consumer_delete(self): consumer = self._create_single_consumer() consumer_id = consumer.get('id')