| 1 |
# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 |
# not use this file except in compliance with the License. You may obtain |
| 3 |
# a copy of the License at |
| 4 |
# |
| 5 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 |
# |
| 7 |
# Unless required by applicable law or agreed to in writing, software |
| 8 |
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 |
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 |
# License for the specific language governing permissions and limitations |
| 11 |
# under the License. |
| 12 |
|
| 13 |
import sqlalchemy as sa |
| 14 |
|
| 15 |
from neutron_lib import context |
| 16 |
from neutron_lib.db import model_base |
| 17 |
|
| 18 |
from neutron_lib.tests.unit.db import _base as db_base |
| 19 |
|
| 20 |
|
| 21 |
class TestTable(model_base.BASEV2, model_base.HasProject, |
| 22 |
model_base.HasId, model_base.HasStatusDescription): |
| 23 |
|
| 24 |
name = sa.Column(sa.String(8), primary_key=True) |
| 25 |
|
| 26 |
|
| 27 |
class TestModelBase(db_base.SqlTestCase): |
| 28 |
|
| 29 |
def setUp(self): |
| 30 |
super().setUp() |
| 31 |
self.ctx = context.Context('user', 'project') |
| 32 |
self.session = self.ctx.session |
| 33 |
|
| 34 |
def test_model_base(self): |
| 35 |
table = TestTable(name='meh') |
| 36 |
self.assertEqual('meh', table.name) |
| 37 |
self.assertIn('meh', str(table)) # test table.__repr__ |
| 38 |
cols = [k for k, _v in table] # test table.__iter__ and table.next |
| 39 |
self.assertIn('name', cols) |
| 40 |
|
| 41 |
def test_get_set_tenant_id_tenant(self): |
| 42 |
table = TestTable(tenant_id='tenant') |
| 43 |
self.assertEqual('tenant', table.get_tenant_id()) |
| 44 |
table.set_tenant_id('project') |
| 45 |
self.assertEqual('project', table.get_tenant_id()) |
| 46 |
|
| 47 |
def test_get_set_tenant_id_project(self): |
| 48 |
table = TestTable(project_id='project') |
| 49 |
self.assertEqual('project', table.get_tenant_id()) |
| 50 |
table.set_tenant_id('tenant') |
| 51 |
self.assertEqual('tenant', table.get_tenant_id()) |
| 52 |
|
| 53 |
def test_project_id_attribute(self): |
| 54 |
table = TestTable(project_id='project') |
| 55 |
self.assertEqual('project', table.project_id) |
| 56 |
self.assertEqual('project', table.tenant_id) |
| 57 |
|
| 58 |
def test_tenant_id_attribute(self): |
| 59 |
table = TestTable(tenant_id='tenant') |
| 60 |
self.assertEqual('tenant', table.project_id) |
| 61 |
self.assertEqual('tenant', table.tenant_id) |