| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
import testtools |
| 17 |
|
| 18 |
from glanceclient.tests.unit.v2 import base |
| 19 |
from glanceclient.tests import utils |
| 20 |
from glanceclient.v2 import metadefs |
| 21 |
|
| 22 |
DEFAULT_PAGE_SIZE = 20 |
| 23 |
NAMESPACE1 = 'Namespace1' |
| 24 |
NAMESPACE2 = 'Namespace2' |
| 25 |
NAMESPACE3 = 'Namespace3' |
| 26 |
NAMESPACE4 = 'Namespace4' |
| 27 |
NAMESPACE5 = 'Namespace5' |
| 28 |
NAMESPACE6 = 'Namespace6' |
| 29 |
NAMESPACE7 = 'Namespace7' |
| 30 |
NAMESPACE8 = 'Namespace8' |
| 31 |
NAMESPACENEW = 'NamespaceNew' |
| 32 |
RESOURCE_TYPE1 = 'ResourceType1' |
| 33 |
RESOURCE_TYPE2 = 'ResourceType2' |
| 34 |
OBJECT1 = 'Object1' |
| 35 |
PROPERTY1 = 'Property1' |
| 36 |
PROPERTY2 = 'Property2' |
| 37 |
|
| 38 |
|
| 39 |
def _get_namespace_fixture(ns_name, rt_name=RESOURCE_TYPE1, **kwargs): |
| 40 |
ns = { |
| 41 |
"display_name": "Flavor Quota", |
| 42 |
"description": "DESCRIPTION1", |
| 43 |
"self": "/v2/metadefs/namespaces/%s" % ns_name, |
| 44 |
"namespace": ns_name, |
| 45 |
"visibility": "public", |
| 46 |
"protected": True, |
| 47 |
"owner": "admin", |
| 48 |
"resource_types": [ |
| 49 |
{ |
| 50 |
"name": rt_name |
| 51 |
} |
| 52 |
], |
| 53 |
"schema": "/v2/schemas/metadefs/namespace", |
| 54 |
"created_at": "2014-08-14T09:07:06Z", |
| 55 |
"updated_at": "2014-08-14T09:07:06Z", |
| 56 |
} |
| 57 |
|
| 58 |
ns.update(kwargs) |
| 59 |
|
| 60 |
return ns |
| 61 |
|
| 62 |
|
| 63 |
data_fixtures = { |
| 64 |
f"/v2/metadefs/namespaces?limit={DEFAULT_PAGE_SIZE}": { |
| 65 |
"GET": ( |
| 66 |
{}, |
| 67 |
{ |
| 68 |
"first": "/v2/metadefs/namespaces?limit=20", |
| 69 |
"namespaces": [ |
| 70 |
_get_namespace_fixture(NAMESPACE1), |
| 71 |
_get_namespace_fixture(NAMESPACE2), |
| 72 |
], |
| 73 |
"schema": "/v2/schemas/metadefs/namespaces" |
| 74 |
} |
| 75 |
) |
| 76 |
}, |
| 77 |
"/v2/metadefs/namespaces?limit=1": { |
| 78 |
"GET": ( |
| 79 |
{}, |
| 80 |
{ |
| 81 |
"first": "/v2/metadefs/namespaces?limit=1", |
| 82 |
"namespaces": [ |
| 83 |
_get_namespace_fixture(NAMESPACE7), |
| 84 |
], |
| 85 |
"schema": "/v2/schemas/metadefs/namespaces", |
| 86 |
"next": "/v2/metadefs/namespaces?marker=%s&limit=1" |
| 87 |
% NAMESPACE7, |
| 88 |
} |
| 89 |
) |
| 90 |
}, |
| 91 |
"/v2/metadefs/namespaces?limit=1&marker=%s" % NAMESPACE7: { |
| 92 |
"GET": ( |
| 93 |
{}, |
| 94 |
{ |
| 95 |
"first": "/v2/metadefs/namespaces?limit=2", |
| 96 |
"namespaces": [ |
| 97 |
_get_namespace_fixture(NAMESPACE8), |
| 98 |
], |
| 99 |
"schema": "/v2/schemas/metadefs/namespaces" |
| 100 |
} |
| 101 |
) |
| 102 |
}, |
| 103 |
"/v2/metadefs/namespaces?limit=2&marker=%s" % NAMESPACE6: { |
| 104 |
"GET": ( |
| 105 |
{}, |
| 106 |
{ |
| 107 |
"first": "/v2/metadefs/namespaces?limit=2", |
| 108 |
"namespaces": [ |
| 109 |
_get_namespace_fixture(NAMESPACE7), |
| 110 |
_get_namespace_fixture(NAMESPACE8), |
| 111 |
], |
| 112 |
"schema": "/v2/schemas/metadefs/namespaces" |
| 113 |
} |
| 114 |
) |
| 115 |
}, |
| 116 |
f"/v2/metadefs/namespaces?limit={DEFAULT_PAGE_SIZE}&sort_dir=asc": { |
| 117 |
"GET": ( |
| 118 |
{}, |
| 119 |
{ |
| 120 |
"first": "/v2/metadefs/namespaces?limit=1", |
| 121 |
"namespaces": [ |
| 122 |
_get_namespace_fixture(NAMESPACE1), |
| 123 |
], |
| 124 |
"schema": "/v2/schemas/metadefs/namespaces" |
| 125 |
} |
| 126 |
) |
| 127 |
}, |
| 128 |
f"/v2/metadefs/namespaces?limit={DEFAULT_PAGE_SIZE}&sort_key=created_at": { |
| 129 |
"GET": ( |
| 130 |
{}, |
| 131 |
{ |
| 132 |
"first": "/v2/metadefs/namespaces?limit=1", |
| 133 |
"namespaces": [ |
| 134 |
_get_namespace_fixture(NAMESPACE1), |
| 135 |
], |
| 136 |
"schema": "/v2/schemas/metadefs/namespaces" |
| 137 |
} |
| 138 |
) |
| 139 |
}, |
| 140 |
"/v2/metadefs/namespaces?limit=%d&resource_types=%s" % ( |
| 141 |
DEFAULT_PAGE_SIZE, RESOURCE_TYPE1): { |
| 142 |
"GET": ( |
| 143 |
{}, |
| 144 |
{ |
| 145 |
"first": "/v2/metadefs/namespaces?limit=20", |
| 146 |
"namespaces": [ |
| 147 |
_get_namespace_fixture(NAMESPACE3), |
| 148 |
], |
| 149 |
"schema": "/v2/schemas/metadefs/namespaces" |
| 150 |
} |
| 151 |
) |
| 152 |
}, |
| 153 |
"/v2/metadefs/namespaces?limit=%d&resource_types=" |
| 154 |
"%s%%2C%s" % (DEFAULT_PAGE_SIZE, RESOURCE_TYPE1, RESOURCE_TYPE2): { |
| 155 |
"GET": ( |
| 156 |
{}, |
| 157 |
{ |
| 158 |
"first": "/v2/metadefs/namespaces?limit=20", |
| 159 |
"namespaces": [ |
| 160 |
_get_namespace_fixture(NAMESPACE4), |
| 161 |
], |
| 162 |
"schema": "/v2/schemas/metadefs/namespaces" |
| 163 |
} |
| 164 |
) |
| 165 |
}, |
| 166 |
f"/v2/metadefs/namespaces?limit={DEFAULT_PAGE_SIZE}&visibility=private": { |
| 167 |
"GET": ( |
| 168 |
{}, |
| 169 |
{ |
| 170 |
"first": "/v2/metadefs/namespaces?limit=20", |
| 171 |
"namespaces": [ |
| 172 |
_get_namespace_fixture(NAMESPACE5), |
| 173 |
], |
| 174 |
"schema": "/v2/schemas/metadefs/namespaces" |
| 175 |
} |
| 176 |
) |
| 177 |
}, |
| 178 |
"/v2/metadefs/namespaces": { |
| 179 |
"POST": ( |
| 180 |
{}, |
| 181 |
{ |
| 182 |
"display_name": "Flavor Quota", |
| 183 |
"description": "DESCRIPTION1", |
| 184 |
"self": "/v2/metadefs/namespaces/%s" % 'NamespaceNew', |
| 185 |
"namespace": 'NamespaceNew', |
| 186 |
"visibility": "public", |
| 187 |
"protected": True, |
| 188 |
"owner": "admin", |
| 189 |
"schema": "/v2/schemas/metadefs/namespace", |
| 190 |
"created_at": "2014-08-14T09:07:06Z", |
| 191 |
"updated_at": "2014-08-14T09:07:06Z", |
| 192 |
} |
| 193 |
) |
| 194 |
}, |
| 195 |
"/v2/metadefs/namespaces/%s" % NAMESPACE1: { |
| 196 |
"GET": ( |
| 197 |
{}, |
| 198 |
{ |
| 199 |
"display_name": "Flavor Quota", |
| 200 |
"description": "DESCRIPTION1", |
| 201 |
"objects": [ |
| 202 |
{ |
| 203 |
"description": "DESCRIPTION2", |
| 204 |
"name": "OBJECT1", |
| 205 |
"self": "/v2/metadefs/namespaces/%s/objects/" % |
| 206 |
OBJECT1, |
| 207 |
"required": [], |
| 208 |
"properties": { |
| 209 |
PROPERTY1: { |
| 210 |
"type": "integer", |
| 211 |
"description": "DESCRIPTION3", |
| 212 |
"title": "Quota: CPU Shares" |
| 213 |
}, |
| 214 |
PROPERTY2: { |
| 215 |
"minimum": 1000, |
| 216 |
"type": "integer", |
| 217 |
"description": "DESCRIPTION4", |
| 218 |
"maximum": 1000000, |
| 219 |
"title": "Quota: CPU Period" |
| 220 |
}, |
| 221 |
}, |
| 222 |
"schema": "/v2/schemas/metadefs/object" |
| 223 |
} |
| 224 |
], |
| 225 |
"self": "/v2/metadefs/namespaces/%s" % NAMESPACE1, |
| 226 |
"namespace": NAMESPACE1, |
| 227 |
"visibility": "public", |
| 228 |
"protected": True, |
| 229 |
"owner": "admin", |
| 230 |
"resource_types": [ |
| 231 |
{ |
| 232 |
"name": RESOURCE_TYPE1 |
| 233 |
} |
| 234 |
], |
| 235 |
"schema": "/v2/schemas/metadefs/namespace", |
| 236 |
"created_at": "2014-08-14T09:07:06Z", |
| 237 |
"updated_at": "2014-08-14T09:07:06Z", |
| 238 |
} |
| 239 |
), |
| 240 |
"PUT": ( |
| 241 |
{}, |
| 242 |
{ |
| 243 |
"display_name": "Flavor Quota", |
| 244 |
"description": "DESCRIPTION1", |
| 245 |
"objects": [ |
| 246 |
{ |
| 247 |
"description": "DESCRIPTION2", |
| 248 |
"name": "OBJECT1", |
| 249 |
"self": "/v2/metadefs/namespaces/%s/objects/" % |
| 250 |
OBJECT1, |
| 251 |
"required": [], |
| 252 |
"properties": { |
| 253 |
PROPERTY1: { |
| 254 |
"type": "integer", |
| 255 |
"description": "DESCRIPTION3", |
| 256 |
"title": "Quota: CPU Shares" |
| 257 |
}, |
| 258 |
PROPERTY2: { |
| 259 |
"minimum": 1000, |
| 260 |
"type": "integer", |
| 261 |
"description": "DESCRIPTION4", |
| 262 |
"maximum": 1000000, |
| 263 |
"title": "Quota: CPU Period" |
| 264 |
}, |
| 265 |
}, |
| 266 |
"schema": "/v2/schemas/metadefs/object" |
| 267 |
} |
| 268 |
], |
| 269 |
"self": "/v2/metadefs/namespaces/%s" % NAMESPACENEW, |
| 270 |
"namespace": NAMESPACENEW, |
| 271 |
"visibility": "public", |
| 272 |
"protected": True, |
| 273 |
"owner": "admin", |
| 274 |
"resource_types": [ |
| 275 |
{ |
| 276 |
"name": RESOURCE_TYPE1 |
| 277 |
} |
| 278 |
], |
| 279 |
"schema": "/v2/schemas/metadefs/namespace", |
| 280 |
"created_at": "2014-08-14T09:07:06Z", |
| 281 |
"updated_at": "2014-08-14T09:07:06Z", |
| 282 |
} |
| 283 |
), |
| 284 |
"DELETE": ( |
| 285 |
{}, |
| 286 |
{} |
| 287 |
) |
| 288 |
}, |
| 289 |
"/v2/metadefs/namespaces/%s?resource_type=%s" % (NAMESPACE6, |
| 290 |
RESOURCE_TYPE1): |
| 291 |
{ |
| 292 |
"GET": ( |
| 293 |
{}, |
| 294 |
{ |
| 295 |
"display_name": "Flavor Quota", |
| 296 |
"description": "DESCRIPTION1", |
| 297 |
"objects": [], |
| 298 |
"self": "/v2/metadefs/namespaces/%s" % NAMESPACE1, |
| 299 |
"namespace": NAMESPACE6, |
| 300 |
"visibility": "public", |
| 301 |
"protected": True, |
| 302 |
"owner": "admin", |
| 303 |
"resource_types": [ |
| 304 |
{ |
| 305 |
"name": RESOURCE_TYPE1 |
| 306 |
} |
| 307 |
], |
| 308 |
"schema": "/v2/schemas/metadefs/namespace", |
| 309 |
"created_at": "2014-08-14T09:07:06Z", |
| 310 |
"updated_at": "2014-08-14T09:07:06Z", |
| 311 |
} |
| 312 |
), |
| 313 |
}, |
| 314 |
} |
| 315 |
|
| 316 |
schema_fixtures = { |
| 317 |
"metadefs/namespace": |
| 318 |
{ |
| 319 |
"GET": ( |
| 320 |
{}, |
| 321 |
{ |
| 322 |
"additionalProperties": False, |
| 323 |
"definitions": { |
| 324 |
"property": { |
| 325 |
"additionalProperties": { |
| 326 |
"required": [ |
| 327 |
"title", |
| 328 |
"type" |
| 329 |
], |
| 330 |
"type": "object", |
| 331 |
"properties": { |
| 332 |
"additionalItems": { |
| 333 |
"type": "boolean" |
| 334 |
}, |
| 335 |
"enum": { |
| 336 |
"type": "array" |
| 337 |
}, |
| 338 |
"description": { |
| 339 |
"type": "string" |
| 340 |
}, |
| 341 |
"title": { |
| 342 |
"type": "string" |
| 343 |
}, |
| 344 |
"default": {}, |
| 345 |
"minLength": { |
| 346 |
"$ref": "#/definitions/" |
| 347 |
"positiveIntegerDefault0" |
| 348 |
}, |
| 349 |
"required": { |
| 350 |
"$ref": "#/definitions/stringArray" |
| 351 |
}, |
| 352 |
"maximum": { |
| 353 |
"type": "number" |
| 354 |
}, |
| 355 |
"minItems": { |
| 356 |
"$ref": "#/definitions/" |
| 357 |
"positiveIntegerDefault0" |
| 358 |
}, |
| 359 |
"readonly": { |
| 360 |
"type": "boolean" |
| 361 |
}, |
| 362 |
"minimum": { |
| 363 |
"type": "number" |
| 364 |
}, |
| 365 |
"maxItems": { |
| 366 |
"$ref": "#/definitions/" |
| 367 |
"positiveInteger" |
| 368 |
}, |
| 369 |
"maxLength": { |
| 370 |
"$ref": "#/definitions/positiveInteger" |
| 371 |
}, |
| 372 |
"uniqueItems": { |
| 373 |
"default": False, |
| 374 |
"type": "boolean" |
| 375 |
}, |
| 376 |
"pattern": { |
| 377 |
"type": "string", |
| 378 |
"format": "regex" |
| 379 |
}, |
| 380 |
"items": { |
| 381 |
"type": "object", |
| 382 |
"properties": { |
| 383 |
"enum": { |
| 384 |
"type": "array" |
| 385 |
}, |
| 386 |
"type": { |
| 387 |
"enum": [ |
| 388 |
"array", |
| 389 |
"boolean", |
| 390 |
"integer", |
| 391 |
"number", |
| 392 |
"object", |
| 393 |
"string", |
| 394 |
"null" |
| 395 |
], |
| 396 |
"type": "string" |
| 397 |
} |
| 398 |
} |
| 399 |
}, |
| 400 |
"type": { |
| 401 |
"enum": [ |
| 402 |
"array", |
| 403 |
"boolean", |
| 404 |
"integer", |
| 405 |
"number", |
| 406 |
"object", |
| 407 |
"string", |
| 408 |
"null" |
| 409 |
], |
| 410 |
"type": "string" |
| 411 |
} |
| 412 |
} |
| 413 |
}, |
| 414 |
"type": "object" |
| 415 |
}, |
| 416 |
"positiveIntegerDefault0": { |
| 417 |
"allOf": [ |
| 418 |
{ |
| 419 |
"$ref": "#/definitions/positiveInteger" |
| 420 |
}, |
| 421 |
{ |
| 422 |
"default": 0 |
| 423 |
} |
| 424 |
] |
| 425 |
}, |
| 426 |
"stringArray": { |
| 427 |
"uniqueItems": True, |
| 428 |
"items": { |
| 429 |
"type": "string" |
| 430 |
}, |
| 431 |
"type": "array" |
| 432 |
}, |
| 433 |
"positiveInteger": { |
| 434 |
"minimum": 0, |
| 435 |
"type": "integer" |
| 436 |
} |
| 437 |
}, |
| 438 |
"required": [ |
| 439 |
"namespace" |
| 440 |
], |
| 441 |
"name": "namespace", |
| 442 |
"properties": { |
| 443 |
"description": { |
| 444 |
"type": "string", |
| 445 |
"description": "Provides a user friendly description " |
| 446 |
"of the namespace.", |
| 447 |
"maxLength": 500 |
| 448 |
}, |
| 449 |
"updated_at": { |
| 450 |
"type": "string", |
| 451 |
"readOnly": True, |
| 452 |
"description": "Date and time of the last namespace " |
| 453 |
"modification", |
| 454 |
"format": "date-time" |
| 455 |
}, |
| 456 |
"visibility": { |
| 457 |
"enum": [ |
| 458 |
"public", |
| 459 |
"private" |
| 460 |
], |
| 461 |
"type": "string", |
| 462 |
"description": "Scope of namespace accessibility." |
| 463 |
}, |
| 464 |
"self": { |
| 465 |
"type": "string" |
| 466 |
}, |
| 467 |
"objects": { |
| 468 |
"items": { |
| 469 |
"type": "object", |
| 470 |
"properties": { |
| 471 |
"properties": { |
| 472 |
"$ref": "#/definitions/property" |
| 473 |
}, |
| 474 |
"required": { |
| 475 |
"$ref": "#/definitions/stringArray" |
| 476 |
}, |
| 477 |
"name": { |
| 478 |
"type": "string" |
| 479 |
}, |
| 480 |
"description": { |
| 481 |
"type": "string" |
| 482 |
} |
| 483 |
} |
| 484 |
}, |
| 485 |
"type": "array" |
| 486 |
}, |
| 487 |
"owner": { |
| 488 |
"type": "string", |
| 489 |
"description": "Owner of the namespace.", |
| 490 |
"maxLength": 255 |
| 491 |
}, |
| 492 |
"resource_types": { |
| 493 |
"items": { |
| 494 |
"type": "object", |
| 495 |
"properties": { |
| 496 |
"prefix": { |
| 497 |
"type": "string" |
| 498 |
}, |
| 499 |
"name": { |
| 500 |
"type": "string" |
| 501 |
}, |
| 502 |
"metadata_type": { |
| 503 |
"type": "string" |
| 504 |
} |
| 505 |
} |
| 506 |
}, |
| 507 |
"type": "array" |
| 508 |
}, |
| 509 |
"properties": { |
| 510 |
"$ref": "#/definitions/property" |
| 511 |
}, |
| 512 |
"display_name": { |
| 513 |
"type": "string", |
| 514 |
"description": "The user friendly name for the " |
| 515 |
"namespace. Used by UI if available.", |
| 516 |
"maxLength": 80 |
| 517 |
}, |
| 518 |
"created_at": { |
| 519 |
"type": "string", |
| 520 |
"readOnly": True, |
| 521 |
"description": "Date and time of namespace creation ", |
| 522 |
"format": "date-time" |
| 523 |
}, |
| 524 |
"namespace": { |
| 525 |
"type": "string", |
| 526 |
"description": "The unique namespace text.", |
| 527 |
"maxLength": 80 |
| 528 |
}, |
| 529 |
"protected": { |
| 530 |
"type": "boolean", |
| 531 |
"description": "If true, namespace will not be " |
| 532 |
"deletable." |
| 533 |
}, |
| 534 |
"schema": { |
| 535 |
"type": "string" |
| 536 |
} |
| 537 |
} |
| 538 |
} |
| 539 |
), |
| 540 |
} |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
class TestNamespaceController(testtools.TestCase): |
| 545 |
def setUp(self): |
| 546 |
super(TestNamespaceController, self).setUp() |
| 547 |
self.api = utils.FakeAPI(data_fixtures) |
| 548 |
self.schema_api = utils.FakeSchemaAPI(schema_fixtures) |
| 549 |
self.controller = base.BaseController(self.api, self.schema_api, |
| 550 |
metadefs.NamespaceController) |
| 551 |
|
| 552 |
def test_list_namespaces(self): |
| 553 |
namespaces = self.controller.list() |
| 554 |
self.assertEqual(2, len(namespaces)) |
| 555 |
self.assertEqual(NAMESPACE1, namespaces[0]['namespace']) |
| 556 |
self.assertEqual(NAMESPACE2, namespaces[1]['namespace']) |
| 557 |
|
| 558 |
def test_list_namespaces_paginate(self): |
| 559 |
namespaces = self.controller.list(page_size=1) |
| 560 |
self.assertEqual(2, len(namespaces)) |
| 561 |
self.assertEqual(NAMESPACE7, namespaces[0]['namespace']) |
| 562 |
self.assertEqual(NAMESPACE8, namespaces[1]['namespace']) |
| 563 |
|
| 564 |
def test_list_with_limit_greater_than_page_size(self): |
| 565 |
namespaces = self.controller.list(page_size=1, limit=2) |
| 566 |
self.assertEqual(2, len(namespaces)) |
| 567 |
self.assertEqual(NAMESPACE7, namespaces[0]['namespace']) |
| 568 |
self.assertEqual(NAMESPACE8, namespaces[1]['namespace']) |
| 569 |
|
| 570 |
def test_list_with_marker(self): |
| 571 |
namespaces = self.controller.list(marker=NAMESPACE6, page_size=2) |
| 572 |
self.assertEqual(2, len(namespaces)) |
| 573 |
self.assertEqual(NAMESPACE7, namespaces[0]['namespace']) |
| 574 |
self.assertEqual(NAMESPACE8, namespaces[1]['namespace']) |
| 575 |
|
| 576 |
def test_list_with_sort_dir(self): |
| 577 |
namespaces = self.controller.list(sort_dir='asc', limit=1) |
| 578 |
self.assertEqual(1, len(namespaces)) |
| 579 |
self.assertEqual(NAMESPACE1, namespaces[0]['namespace']) |
| 580 |
|
| 581 |
def test_list_with_sort_dir_invalid(self): |
| 582 |
|
| 583 |
|
| 584 |
self.assertRaises(ValueError, self.controller.list, sort_dir='foo') |
| 585 |
|
| 586 |
def test_list_with_sort_key(self): |
| 587 |
namespaces = self.controller.list(sort_key='created_at', limit=1) |
| 588 |
self.assertEqual(1, len(namespaces)) |
| 589 |
self.assertEqual(NAMESPACE1, namespaces[0]['namespace']) |
| 590 |
|
| 591 |
def test_list_with_sort_key_invalid(self): |
| 592 |
|
| 593 |
|
| 594 |
self.assertRaises(ValueError, self.controller.list, sort_key='foo') |
| 595 |
|
| 596 |
def test_list_namespaces_with_one_resource_type_filter(self): |
| 597 |
namespaces = self.controller.list( |
| 598 |
filters={ |
| 599 |
'resource_types': [RESOURCE_TYPE1] |
| 600 |
} |
| 601 |
) |
| 602 |
|
| 603 |
self.assertEqual(1, len(namespaces)) |
| 604 |
self.assertEqual(NAMESPACE3, namespaces[0]['namespace']) |
| 605 |
|
| 606 |
def test_list_namespaces_with_multiple_resource_types_filter(self): |
| 607 |
namespaces = self.controller.list( |
| 608 |
filters={ |
| 609 |
'resource_types': [RESOURCE_TYPE1, RESOURCE_TYPE2] |
| 610 |
} |
| 611 |
) |
| 612 |
|
| 613 |
self.assertEqual(1, len(namespaces)) |
| 614 |
self.assertEqual(NAMESPACE4, namespaces[0]['namespace']) |
| 615 |
|
| 616 |
def test_list_namespaces_with_visibility_filter(self): |
| 617 |
namespaces = self.controller.list( |
| 618 |
filters={ |
| 619 |
'visibility': 'private' |
| 620 |
} |
| 621 |
) |
| 622 |
|
| 623 |
self.assertEqual(1, len(namespaces)) |
| 624 |
self.assertEqual(NAMESPACE5, namespaces[0]['namespace']) |
| 625 |
|
| 626 |
def test_get_namespace(self): |
| 627 |
namespace = self.controller.get(NAMESPACE1) |
| 628 |
self.assertEqual(NAMESPACE1, namespace.namespace) |
| 629 |
self.assertTrue(namespace.protected) |
| 630 |
|
| 631 |
def test_get_namespace_with_resource_type(self): |
| 632 |
namespace = self.controller.get(NAMESPACE6, |
| 633 |
resource_type=RESOURCE_TYPE1) |
| 634 |
self.assertEqual(NAMESPACE6, namespace.namespace) |
| 635 |
self.assertTrue(namespace.protected) |
| 636 |
|
| 637 |
def test_create_namespace(self): |
| 638 |
properties = { |
| 639 |
'namespace': NAMESPACENEW |
| 640 |
} |
| 641 |
namespace = self.controller.create(**properties) |
| 642 |
|
| 643 |
self.assertEqual(NAMESPACENEW, namespace.namespace) |
| 644 |
self.assertTrue(namespace.protected) |
| 645 |
|
| 646 |
def test_create_namespace_invalid_data(self): |
| 647 |
properties = {} |
| 648 |
|
| 649 |
self.assertRaises(TypeError, self.controller.create, **properties) |
| 650 |
|
| 651 |
def test_create_namespace_invalid_property(self): |
| 652 |
properties = {'namespace': 'NewNamespace', 'protected': '123'} |
| 653 |
|
| 654 |
self.assertRaises(TypeError, self.controller.create, **properties) |
| 655 |
|
| 656 |
def test_update_namespace(self): |
| 657 |
properties = {'display_name': 'My Updated Name'} |
| 658 |
namespace = self.controller.update(NAMESPACE1, **properties) |
| 659 |
|
| 660 |
self.assertEqual(NAMESPACE1, namespace.namespace) |
| 661 |
|
| 662 |
def test_update_namespace_invalid_property(self): |
| 663 |
properties = {'protected': '123'} |
| 664 |
|
| 665 |
self.assertRaises(TypeError, self.controller.update, NAMESPACE1, |
| 666 |
**properties) |
| 667 |
|
| 668 |
def test_update_namespace_disallowed_fields(self): |
| 669 |
properties = {'display_name': 'My Updated Name'} |
| 670 |
self.controller.update(NAMESPACE1, **properties) |
| 671 |
actual = self.api.calls |
| 672 |
_disallowed_fields = ['self', 'schema', 'created_at', 'updated_at'] |
| 673 |
for key in actual[1][3]: |
| 674 |
self.assertNotIn(key, _disallowed_fields) |
| 675 |
|
| 676 |
def test_delete_namespace(self): |
| 677 |
self.controller.delete(NAMESPACE1) |
| 678 |
expect = [ |
| 679 |
('DELETE', |
| 680 |
'/v2/metadefs/namespaces/%s' % NAMESPACE1, |
| 681 |
{}, |
| 682 |
None)] |
| 683 |
self.assertEqual(expect, self.api.calls) |