1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565
|
# Copyright (c) 2016 Mirantis, Inc.
#
# 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 mock
import testtools
from glareclient.osc.v1 import artifacts as osc_art
from glareclient.tests.unit.osc.v1 import fakes
from glareclient.v1 import artifacts as api_art
from osc_lib.tests.utils import ParserException
class TestArtifacts(fakes.TestArtifacts):
def setUp(self):
super(TestArtifacts, self).setUp()
self.artifact_mock = \
self.app.client_manager.artifact.artifacts
self.http = mock.MagicMock()
self.COLUMNS = set(['id', 'name', 'owner',
'status', 'version', 'visibility'])
class TestListArtifacts(TestArtifacts):
def setUp(self):
super(TestListArtifacts, self).setUp()
self.artifact_mock.call.return_value = \
api_art.Controller(self.http, type_name='images')
# Command to test
self.cmd = osc_art.ListArtifacts(self.app, None)
self.COLUMNS = ['Id', 'Name', 'Version',
'Owner', 'Visibility', 'Status']
def test_artifact_list(self):
arglist = ['images']
verify = [('type_name', 'images')]
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
# Check that columns are correct
self.assertEqual(self.COLUMNS, columns)
self.check_parser(self.cmd, arglist, verify)
def test_artifact_list_all(self):
arglist = ['all']
verify = [('type_name', 'all')]
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
# Check that columns are correct
self.assertEqual(['Id', 'Name', 'Version', 'Type name',
'Owner', 'Visibility', 'Status'], columns)
self.check_parser(self.cmd, arglist, verify)
def test_artifact_list_with_multifilters(self):
arglist = ['images',
'--filter', 'spam:spam',
'--filter', 'maps:maps']
verify = [('type_name', 'images'),
('filter', ['spam:spam', 'maps:maps'])]
self.check_parser(self.cmd, arglist, verify)
def test_artifact_list_with_sort(self):
arglist = ['sample_artifact', '--sort', 'name:asc']
verify = [('type_name', 'sample_artifact'),
('sort', 'name:asc')]
self.check_parser(self.cmd, arglist, verify)
def test_artifact_list_with_multisort(self):
arglist = ['images',
'--sort', 'name:desc',
'--sort', 'name:asc']
verify = [('type_name', 'images'),
('sort', 'name:asc')]
self.check_parser(self.cmd, arglist, verify)
def test_artifact_list_page_size(self):
arglist = ['images', '--page-size', '1']
verify = [('type_name', 'images'),
('page_size', 1)]
self.check_parser(self.cmd, arglist, verify)
def test_artifact_list_limit(self):
arglist = ['images', '--limit', '2']
verify = [('type_name', 'images'),
('limit', 2)]
self.check_parser(self.cmd, arglist, verify)
def test_artifact_list_multilimit(self):
arglist = ['images', '--limit', '2', '--limit', '1']
verify = [('type_name', 'images'),
('limit', 1)]
self.check_parser(self.cmd, arglist, verify)
class TestShowArtifacts(TestArtifacts):
def setUp(self):
super(TestShowArtifacts, self).setUp()
self.artifact_mock.call.return_value = \
api_art.Controller(self.http, type_name='images')
# Command to test
self.cmd = osc_art.ShowArtifact(self.app, None)
def test_artifact_show(self):
arglist = ['images', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba']
verify = [('type_name', 'images')]
COLUMNS = set(['blob', 'environment', 'id', 'image',
'name', 'owner', 'package', 'status',
'template', 'version', 'visibility'])
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
name_fields = set([column[0] for column in data])
# Check that columns are correct
self.assertEqual(COLUMNS, name_fields)
def test_artifact_show_without_id(self):
arglist = ['images']
verify = [('type_name', 'images')]
with testtools.ExpectedException(ParserException):
self.check_parser(self.cmd, arglist, verify)
def test_artifact_show_without_type_id(self):
arglist = ['fc15c365-d4f9-4b8b-a090-d9e230f1f6ba']
verify = [('type_name', 'images')]
with testtools.ExpectedException(ParserException):
self.check_parser(self.cmd, arglist, verify)
def test_artifact_show_by_name(self):
arglist = ['images', 'name1']
verify = [('type_name', 'images'), ('id', False)]
COLUMNS = set(['blob', 'environment', 'id', 'image',
'name', 'owner', 'package', 'status',
'template', 'version', 'visibility'])
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
name_fields = set([column[0] for column in data])
# Check that columns are correct
self.assertEqual(COLUMNS, name_fields)
class TestCreateArtifacts(TestArtifacts):
def setUp(self):
super(TestCreateArtifacts, self).setUp()
self.artifact_mock.call.return_value = \
api_art.Controller(self.http, type_name='images')
# Command to test
self.cmd = osc_art.CreateArtifact(self.app, None)
def test_create_artifact(self):
arglist = ['images', 'art',
'--artifact-version', '0.2.4',
'--property', 'blah=10']
verify = [('type_name', 'images'),
('property', ['blah=10']),
('artifact_version', '0.2.4')]
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
name_fields = set([column[0] for column in data])
# Check that columns are correct
self.assertEqual(self.COLUMNS, name_fields)
def test_create_artifact_list_prop(self):
arglist = ['images', 'art',
'--artifact-version', '0.2.4',
'--list', 'l=10,11,12']
verify = [('type_name', 'images'),
('list', ['l=10,11,12']),
('artifact_version', '0.2.4')]
parsed_args = self.check_parser(self.cmd, arglist, verify)
with mock.patch.object(
self.app.client_manager.artifact.artifacts,
'create') as patched_create:
self.cmd.take_action(parsed_args)
patched_create.assert_called_once_with(
'art',
l=['10', '11', '12'],
type_name='images',
version='0.2.4')
def test_create_artifact_dict_prop(self):
arglist = ['images', 'art',
'--artifact-version', '0.2.4',
'--dict', 'd=a:10,b:11,c:12']
verify = [('type_name', 'images'),
('dict', ['d=a:10,b:11,c:12']),
('artifact_version', '0.2.4')]
parsed_args = self.check_parser(self.cmd, arglist, verify)
with mock.patch.object(
self.app.client_manager.artifact.artifacts,
'create') as patched_create:
self.cmd.take_action(parsed_args)
patched_create.assert_called_once_with(
'art',
d={'a': '10', 'c': '12', 'b': '11'},
type_name='images',
version='0.2.4')
def test_create_artifact_multiproperty(self):
arglist = ['images', 'art',
'--artifact-version', '0.2.4',
'--property', 'blah=1',
'--property', 'blag=2']
verify = [('type_name', 'images'),
('property', ['blah=1', 'blag=2']),
('artifact_version', '0.2.4')]
self.check_parser(self.cmd, arglist, verify)
def test_create_artifact_multiversion(self):
arglist = ['images', 'art',
'--artifact-version', '0.2.4',
'--artifact-version', '0.2.5']
verify = [('type_name', 'images'),
('artifact_version', '0.2.5')]
self.check_parser(self.cmd, arglist, verify)
class TestUpdateArtifacts(TestArtifacts):
def setUp(self):
super(TestUpdateArtifacts, self).setUp()
self.artifact_mock.call.return_value = \
api_art.Controller(self.http, type_name='images')
# Command to test
self.cmd = osc_art.UpdateArtifact(self.app, None)
def test_artifact_update(self):
arglist = ['images',
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba',
'--property', 'blah=1',
'--property', 'blag=2']
verify = [('type_name', 'images'),
('property', ['blah=1', 'blag=2'])]
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
name_fields = set([column[0] for column in data])
# Check that columns are correct
self.assertEqual(self.COLUMNS, name_fields)
def test_update_artifact_list_prop(self):
arglist = ['images',
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba',
'--list', 'l=10,11,12']
verify = [('type_name', 'images'),
('list', ['l=10,11,12'])]
parsed_args = self.check_parser(self.cmd, arglist, verify)
with mock.patch.object(
self.app.client_manager.artifact.artifacts,
'update') as patched_update:
self.cmd.take_action(parsed_args)
patched_update.assert_called_once_with(
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba',
l=['10', '11', '12'],
remove_props=[],
type_name='images')
def test_update_artifact_dict_prop(self):
arglist = ['images',
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba',
'--dict', 'd=a:10,b:11,c:12']
verify = [('type_name', 'images'),
('dict', ['d=a:10,b:11,c:12'])]
parsed_args = self.check_parser(self.cmd, arglist, verify)
with mock.patch.object(
self.app.client_manager.artifact.artifacts,
'update') as patched_update:
self.cmd.take_action(parsed_args)
patched_update.assert_called_once_with(
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba',
d={'a': '10', 'c': '12', 'b': '11'},
remove_props=[],
type_name='images')
def test_artifact_update_bad(self):
arglist = ['images',
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba',
'--property', 'blah',
'--property', 'blah'
]
verify = [('type_name', 'images')]
parsed_args = self.check_parser(self.cmd, arglist, verify)
with testtools.ExpectedException(ValueError):
self.cmd.take_action(parsed_args)
def test_artifact_update_multiremove_prop(self):
arglist = ['images',
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba',
'--remove-property', 'prop1',
'--remove-property', 'prop2']
verify = [('type_name', 'images'),
('remove_property', ['prop1', 'prop2'])]
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
name_fields = set([column[0] for column in data])
# Check that columns are correct
self.assertEqual(self.COLUMNS, name_fields)
class TestDeleteArtifacts(TestArtifacts):
def setUp(self):
super(TestDeleteArtifacts, self).setUp()
self.artifact_mock.call.return_value = \
api_art.Controller(self.http, type_name='images')
# Command to test
self.cmd = osc_art.DeleteArtifact(self.app, None)
def test_artifact_delete(self):
arglist = ['images',
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba', '--id']
verify = [('type_name', 'images'),
('name', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba'),
('id', True)]
parsed_args = self.check_parser(self.cmd, arglist, verify)
self.assertIsNone(self.cmd.take_action(parsed_args))
class TestActivateArtifacts(TestArtifacts):
def setUp(self):
super(TestActivateArtifacts, self).setUp()
self.artifact_mock.call.return_value = \
api_art.Controller(self.http, type_name='images')
# Command to test
self.cmd = osc_art.ActivateArtifact(self.app, None)
def test_artifact_activate(self):
arglist = ['images',
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba',
'--id']
verify = [('type_name', 'images'),
('name', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba'),
('id', True)]
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
name_fields = set([column[0] for column in data])
# Check that columns are correct
self.assertEqual(self.COLUMNS, name_fields)
class TestDeactivateArtifacts(TestArtifacts):
def setUp(self):
super(TestDeactivateArtifacts, self).setUp()
self.artifact_mock.call.return_value = \
api_art.Controller(self.http, type_name='images')
# Command to test
self.cmd = osc_art.DeactivateArtifact(self.app, None)
def test_artifact_deactivate(self):
arglist = ['images',
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba', '--id']
verify = [('type_name', 'images'),
('name', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba'),
('id', True)]
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
name_fields = set([column[0] for column in data])
# Check that columns are correct
self.assertEqual(self.COLUMNS, name_fields)
class TestReactivateArtifacts(TestArtifacts):
def setUp(self):
super(TestReactivateArtifacts, self).setUp()
self.artifact_mock.call.return_value = \
api_art.Controller(self.http, type_name='images')
# Command to test
self.cmd = osc_art.ReactivateArtifact(self.app, None)
def test_artifact_rectivate(self):
arglist = ['images',
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba', '--id']
verify = [('type_name', 'images'),
('name', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba'),
('id', True)]
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
name_fields = set([column[0] for column in data])
# Check that columns are correct
self.assertEqual(self.COLUMNS, name_fields)
class TestAddTag(TestArtifacts):
def setUp(self):
super(TestAddTag, self).setUp()
self.artifact_mock.call.return_value = \
api_art.Controller(self.http, type_name='images')
# Command to test
self.cmd = osc_art.AddTag(self.app, None)
def test_artifact_add_tag(self):
arglist = ['images',
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba', '--id',
'123']
verify = [('type_name', 'images'),
('name', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba'),
('id', True),
('tag', '123')]
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
name_fields = set([column[0] for column in data])
# Check that columns are correct
self.assertEqual(self.COLUMNS, name_fields)
class TestRemoveTag(TestArtifacts):
def setUp(self):
super(TestRemoveTag, self).setUp()
self.artifact_mock.call.return_value = \
api_art.Controller(self.http, type_name='images')
# Command to test
self.cmd = osc_art.RemoveTag(self.app, None)
def test_artifact_add_tag(self):
arglist = ['images',
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba', '--id',
'123']
verify = [('type_name', 'images'),
('name', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba'),
('id', True),
('tag', '123')]
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
name_fields = set([column[0] for column in data])
# Check that columns are correct
self.assertEqual(self.COLUMNS, name_fields)
class TestPublishArtifacts(TestArtifacts):
def setUp(self):
super(TestPublishArtifacts, self).setUp()
self.artifact_mock.call.return_value = \
api_art.Controller(self.http, type_name='images')
# Command to test
self.cmd = osc_art.PublishArtifact(self.app, None)
def test_publish_delete(self):
arglist = ['images',
'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba', '--id']
verify = [('type_name', 'images'),
('name', 'fc15c365-d4f9-4b8b-a090-d9e230f1f6ba'),
('id', True)]
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
name_fields = set([column[0] for column in data])
# Check that columns are correct
self.assertEqual(self.COLUMNS, name_fields)
class TypeSchema(TestArtifacts):
def setUp(self):
super(TypeSchema, self).setUp()
self.artifact_mock.call.return_value = \
api_art.Controller(self.http, type_name='images')
# Command to test
self.cmd = osc_art.TypeSchema(self.app, None)
def test_get_schema(self):
arglist = ['images']
verify = [('type_name', 'images')]
parsed_args = self.check_parser(self.cmd, arglist, verify)
columns, data = self.cmd.take_action(parsed_args)
exp_columns = ['Name', 'Glare_type', 'Mutable', 'Required',
'Sortable', 'Filters', 'Available_values']
exp_data = [
(u'image', u'Blob', False, False, False, [], ''),
(u'updated_at', u'DateTime', False, True, True,
[u'eq', u'neq', u'in', u'gt', u'gte', u'lt', u'lte'], ''),
(u'owner', u'String', False, False, True,
[u'eq', u'neq', u'in'], ''),
(u'provided_by', u'StringDict', False, False, False,
[u'eq', u'neq', u'in'], ''),
(u'id', u'String', False, True, True, [u'eq', u'neq', u'in'], ''),
(u'environment', u'Blob', False, True, False, [], ''),
(u'version', u'String', False, False, True,
[u'eq', u'neq', u'in', u'gt', u'gte', u'lt', u'lte'], ''),
(u'blob', u'Blob', True, False, False, [], ''),
(u'template', u'Blob', False, True, False, [], ''),
(u'metadata', u'StringDict', False, False, False,
[u'eq', u'neq'], ''),
(u'status', u'String', False, True, True, [u'eq', u'neq', u'in'],
[u'drafted', u'active', u'deactivated', u'deleted']),
(u'description', u'String', True, False, False,
[u'eq', u'neq', u'in'], ''),
(u'tags', u'StringList', True, False, False,
[u'eq', u'neq', u'in'], ''),
(u'activated_at', u'DateTime', False, False, True,
[u'eq', u'neq', u'in', u'gt', u'gte', u'lt', u'lte'], ''),
(u'supported_by', u'StringDict', False, False, False,
[u'eq', u'neq', u'in'], ''),
(u'visibility', u'String', False, True, True, [u'eq'], ''),
(u'icon', u'Blob', False, False, False, [], ''),
(u'name', u'String', False, False, True,
[u'eq', u'neq', u'in'], ''),
(u'license', u'String', False, False, False,
[u'eq', u'neq', u'in'], ''),
(u'package', u'Blob', False, False, False, [], ''),
(u'created_at', u'DateTime', False, True, True,
[u'eq', u'neq', u'in', u'gt', u'gte', u'lt', u'lte'], ''),
(u'license_url', u'String', False, False, False,
[u'eq', u'neq', u'in'], ''),
(u'release', u'StringList', False, False, False,
[u'eq', u'neq', u'in'], '')]
data.sort(key=lambda x: x[0])
exp_data.sort(key=lambda x: x[0])
# Check that columns are correct
self.assertEqual(exp_columns, columns)
self.assertEqual(exp_data, data)
|