Пример #1
0
 def setUp(self):
     self.runner = Runner()
     self.runner.setup()
     self.compose_detail = {
         "compose_id": "awesome-product-20130203.7",
         "compose_date": "2013-02-03",
         "compose_type": "nightly",
         "compose_respin": 0,
         "release": "aifv-5802",
         "compose_label": "RC-3.0",
         "deleted": False,
         "rpm_mapping_template": "https://pdc.example.com/rest_api/v1/composes/awesome-product-20130203.7/rpm-mapping/{{package}}/",
         "sigkeys": [
             "fd431d51"
         ],
         "acceptance_testing": "untested",
         "linked_releases": [
             "sap-7.0-awesome-product"
         ],
         "rtt_tested_architectures": {
             "Workstation": {
                 "x86_64": "untested"
             }
         }
     }
Пример #2
0
 def setUp(self):
     self.runner = Runner()
     self.runner.setup()
     self.detail = {
         "id": "1",
         "component": {"name": "Test Release Component", "release": "test-release"},
         "role": "pm",
         "contact": {"username": "******", "email": "*****@*****.**"},
     }
Пример #3
0
class BuildImageTestCase(CLITestCase):
    def setUp(self):
        self.runner = Runner()
        self.runner.setup()

    def _setup_list_1(self, api):
        api.add_endpoint('build-images', 'GET', [
            {'image_id': 'build-image-{}'.format(x),
             'md5': '111122223333444455556666777788{:02}'.format(x)}
            for x in range(30)
        ])

    def _setup_detail(self, api):
        obj = {'image_id': 'test_image_1',
               'url': 'http://127.0.0.1:8000/rest_api/v1/build-images/1/',
               'image_format': 'docker',
               'md5': '11112222333344445555666677778899',
               'rpms': [],
               'archives': [],
               'releases': []}
        api.add_endpoint('build-images/1', 'PATCH', obj)
        api.add_endpoint('build-images/1', 'GET', obj)
        api.add_endpoint('build-images', 'POST', obj)

    def _setup_list_2(self, api):
        filter_result = {
            "count": 1,
            "next": None,
            "previous": None,
            "results": [
                {
                    "archives": [],
                    "image_format": "docker",
                    "image_id": "test_image_1",
                    "md5": "11112222333344445555666677778899",
                    "releases": [],
                    "rpms": [],
                    "url": "http://127.0.0.1:8000/rest_api/v1/build-images/1/"
                }
            ]
        }

        api.add_endpoint('build-images', 'GET', filter_result)

    def test_list(self, api):
        self._setup_list_1(api)
        with self.expect_output('list_multi_page.txt'):
            self.runner.run(['build-image', 'list'])
        self.assertEqual(api.calls['build-images'],
                         [('GET', {'page': 1}),
                          ('GET', {'page': 2})])

    def test_info(self, api):
        self._setup_detail(api)
        self._setup_list_2(api)
        with self.expect_output('detail.json', parse_json=True):
            self.runner.run(['--json', 'build-image', 'info', 'test_image_1'])
        self.assertEqual(api.calls['build-images'], [('GET', {'image_id': 'test_image_1'})])
Пример #4
0
 def setUp(self):
     self.runner = Runner()
     self.runner.setup()
     self.detail = {
         'id': '1',
         'name': 'Test Global Component',
         'dist_git_path': None,
         'dist_git_web_url': 'http://pkgs.example.com/test_global_component',
         'contacts': [
             {
                 'url': 'http://example.com/global-components/1/contacts/1/',
                 'contact_role': 'test_role_a',
                 'contact': {
                     'mail_name': 'Test Maillist',
                     'email': '*****@*****.**'
                 }
             },
             {
                 'url': 'http://example.com/global-components/1/contacts/2/',
                 'contact_role': 'test_role_b',
                 'contact': {
                     'username': '******',
                     'email': '*****@*****.**'
                 }
             }
         ],
         'labels': [
             {
                 'url': 'http://example.com/lable/1',
                 'name': 'test label',
                 'description': 'test label description'
             }
         ],
         'upstream': {
             'homepage': 'http://test_global_component.org',
             'scm_type': 'git',
             'scm_url': 'http://test_global_component.org/git'
         }
     }
Пример #5
0
 def setUp(self):
     self.runner = Runner()
     self.runner.setup()
     self.detail = {
         'id': '1',
         'release': {
             'release_id': 'test_release',
             'active': True
         },
         'bugzilla_component': None,
         'brew_package': None,
         'global_component': 'test_global_component',
         'name': 'Test Release Component',
         'dist_git_branch': 'test_branch',
         'dist_git_web_url': 'http://pkgs.example.com/test_release_component',
         'active': True,
         'type': 'rpm',
         'srpm': None,
         'contacts': [
             {
                 'url': 'http://example.com/release-components/1/contacts/1/',
                 'contact_role': 'test_role_a',
                 'contact': {
                     'mail_name': 'Test Maillist',
                     'email': '*****@*****.**'
                 }
             },
             {
                 'url': 'http://example.com/release-components/1/contacts/2/',
                 'contact_role': 'test_role_b',
                 'contact': {
                     'username': '******',
                     'email': '*****@*****.**'
                 }
             }
         ]
     }
Пример #6
0
class ReleaseComponentTestCase(CLITestCase):
    def setUp(self):
        self.runner = Runner()
        self.runner.setup()
        self.detail = {
            'id': '1',
            'release': {
                'release_id': 'test_release',
                'active': True
            },
            'bugzilla_component': None,
            'brew_package': None,
            'global_component': 'test_global_component',
            'name': 'Test Release Component',
            'dist_git_branch': 'test_branch',
            'dist_git_web_url': 'http://pkgs.example.com/test_release_component',
            'active': True,
            'type': 'rpm',
            'srpm': None,
            'contacts': [
                {
                    'url': 'http://example.com/release-components/1/contacts/1/',
                    'contact_role': 'test_role_a',
                    'contact': {
                        'mail_name': 'Test Maillist',
                        'email': '*****@*****.**'
                    }
                },
                {
                    'url': 'http://example.com/release-components/1/contacts/2/',
                    'contact_role': 'test_role_b',
                    'contact': {
                        'username': '******',
                        'email': '*****@*****.**'
                    }
                }
            ]
        }

    def _setup_detail(self, api):
        api.add_endpoint('release-components/1', 'GET', self.detail)

    def _setup_list_filter(self, api):
        filter_result = {
            "count": 1,
            "next": None,
            "previous": None,
            "results": [
                {
                    'id': '1',
                    'release': {
                        'release_id': 'test_release',
                        'active': True
                    },
                    'bugzilla_component': None,
                    'brew_package': None,
                    'global_component': 'test_global_component',
                    'name': 'Test Release Component',
                    'dist_git_branch': 'test_branch',
                    'dist_git_web_url': 'http://pkgs.example.com/test_release_component',
                    'active': True,
                    'type': 'rpm',
                    'srpm': None,
                    'contacts': [
                        {
                            'url': 'http://example.com/release-components/1/contacts/1/',
                            'contact_role': 'test_role_a',
                            'contact': {
                                'mail_name': 'Test Maillist',
                                'email': '*****@*****.**'
                            }
                        },
                        {
                            'url': 'http://example.com/release-components/1/contacts/2/',
                            'contact_role': 'test_role_b',
                            'contact': {
                                'username': '******',
                                'email': '*****@*****.**'
                            }
                        }
                    ]
                }
            ]
        }

        api.add_endpoint('release-components', 'GET', filter_result)

    def test_list_without_filters(self, api):
        with self.expect_failure():
            self.runner.run(['release-component', 'list'])

    def test_list_multi_page(self, api):
        api.add_endpoint('release-components', 'GET', [
            {'id': x,
             'release': {'active': True,
                         'release_id': 'Test Release'},
             'name': 'Test Release Component %s' % x}
            for x in range(1, 26)
        ])
        with self.expect_output('release_component/list_multi_page.txt'):
            self.runner.run(['release-component', 'list',
                             '--release', 'Test Release'])
        self.assertEqual(api.calls['release-components'],
                         [('GET', {'page': 1, 'release': 'Test Release'}),
                          ('GET', {'page': 2, 'release': 'Test Release'})])

    def test_detail(self, api):
        api.add_endpoint('release-component-contacts',
                         'GET',
                         {'count': 1,
                          'next': None,
                          'previous': None,
                          'results': [
                              {
                                  'id': 1,
                                  'component': {
                                      'release': 'test_release',
                                      'id': 1,
                                      'name': 'Test Release Component'
                                  },
                                  'role': 'pm',
                                  'contact': {
                                      'id': 1,
                                      'mail_name': 'maillist1',
                                      'email': '*****@*****.**'
                                  }
                              }
                          ]})
        self._setup_detail(api)
        with self.expect_output('release_component/detail.txt'):
            self.runner.run(['release-component', 'info', '1'])
        self.assertDictEqual(api.calls,
                             {'release-components/1': [('GET', {})],
                              'release-component-contacts':
                                  [('GET',
                                    {'component': 'Test Release Component',
                                     'page': 1,
                                     'release': 'test_release'})
                                   ]
                              })

    def test_update(self, api):
        api.add_endpoint('release-component-contacts',
                         'GET',
                         {'count': 1,
                          'next': None,
                          'previous': None,
                          'results': [
                              {
                                  'id': 1,
                                  'component': {
                                      'release': 'test_release',
                                      'id': 1,
                                      'name': 'Test Release Component'
                                  },
                                  'role': 'pm',
                                  'contact': {
                                      'id': 1,
                                      'mail_name': 'maillist1',
                                      'email': '*****@*****.**'
                                  }
                              }
                          ]})
        self._setup_detail(api)
        self._setup_list_filter(api)
        api.add_endpoint('release-components/1', 'PATCH', {})
        with self.expect_output('release_component/detail.txt'):
            self.runner.run(['release-component', 'update', 'test_release', 'Test Release Component',
                             '--name', 'new test name'])
        self.assertDictEqual(api.calls,
                             {'release-components': [
                                 ('GET', {'name': 'Test Release Component', 'release': 'test_release'})],
                              'release-components/1': [('PATCH', {'name': 'new test name'}),
                                                       ('GET', {})],
                              'release-component-contacts':
                                  [('GET',
                                    {'component': 'Test Release Component', 'page': 1, 'release': 'test_release'})]})

    def test_create(self, api):
        api.add_endpoint('release-component-contacts',
                         'GET',
                         {'count': 1,
                          'next': None,
                          'previous': None,
                          'results': [
                              {
                                  'id': 1,
                                  'component': {
                                      'release': 'test_release',
                                      'id': 1,
                                      'name': 'Test Release Component'
                                  },
                                  'role': 'pm',
                                  'contact': {
                                      'id': 1,
                                      'mail_name': 'maillist1',
                                      'email': '*****@*****.**'
                                  }
                              }
                          ]})
        api.add_endpoint('release-components', 'POST', self.detail)
        self._setup_detail(api)
        with self.expect_output('release_component/detail.txt'):
            self.runner.run(['release-component', 'create',
                             '--name', 'Test Release Component',
                             '--release', 'test_release',
                             '--global-component', 'test_global_component'])
        self.assertDictEqual(api.calls,
                             {'release-components': [('POST',
                                                     {'name': 'Test Release Component',
                                                      'release': 'test_release',
                                                      'global_component': 'test_global_component'})],
                              'release-components/1': [('GET', {})],
                              'release-component-contacts':
                                  [('GET',
                                    {'component': 'Test Release Component',
                                     'page': 1,
                                     'release': 'test_release'})
                                   ]
                              })

    def test_info_json(self, api):
        api.add_endpoint('release-component-contacts', 'GET', {'count': 0,
                                                               'next': None,
                                                               'previous': None,
                                                               'results': []})
        self._setup_detail(api)
        with self.expect_output('release_component/detail.json', parse_json=True):
            self.runner.run(['--json', 'release-component', 'info', '1'])
        self.assertDictEqual(api.calls,
                             {'release-components/1': [('GET', {})],
                              'release-component-contacts':
                                  [('GET',
                                    {'component': 'Test Release Component',
                                     'page': 1,
                                     'release': 'test_release'})
                                   ]
                              })

    def test_list_json(self, api):
        api.add_endpoint('release-components', 'GET', [self.detail])
        with self.expect_output('release_component/list.json', parse_json=True):
            self.runner.run(['--json', 'release-component', 'list',
                             '--release', 'test_release'])
Пример #7
0
class GlobalComponentTestCase(CLITestCase):
    def setUp(self):
        self.runner = Runner()
        self.runner.setup()
        self.detail = {
            'id': '1',
            'name': 'Test Global Component',
            'dist_git_path': None,
            'dist_git_web_url': 'http://pkgs.example.com/test_global_component',
            'contacts': [
                {
                    'url': 'http://example.com/global-components/1/contacts/1/',
                    'contact_role': 'test_role_a',
                    'contact': {
                        'mail_name': 'Test Maillist',
                        'email': '*****@*****.**'
                    }
                },
                {
                    'url': 'http://example.com/global-components/1/contacts/2/',
                    'contact_role': 'test_role_b',
                    'contact': {
                        'username': '******',
                        'email': '*****@*****.**'
                    }
                }
            ],
            'labels': [
                {
                    'url': 'http://example.com/lable/1',
                    'name': 'test label',
                    'description': 'test label description'
                }
            ],
            'upstream': {
                'homepage': 'http://test_global_component.org',
                'scm_type': 'git',
                'scm_url': 'http://test_global_component.org/git'
            }
        }

    def _setup_detail(self, api):
        api.add_endpoint('global-components/1', 'GET', self.detail)

    def test_list_without_filters(self, api):
        with self.expect_failure():
            self.runner.run(['global-component', 'list'])

    def test_list_multi_page(self, api):
        api.add_endpoint('global-components', 'GET', [
            {'id': x,
             'name': 'Test Global Component %s' % x}
            for x in range(1, 26)
        ])
        with self.expect_output('global_component/list_multi_page.txt'):
            self.runner.run(['global-component', 'list',
                             '--label', 'test label'])
        self.assertEqual(api.calls['global-components'],
                         [('GET', {'page': 1, 'label': 'test label'}),
                          ('GET', {'page': 2, 'label': 'test label'})])

    def test_detail(self, api):
        self._setup_detail(api)
        api.add_endpoint('global-component-contacts',
                         'GET',
                         {'count': 1,
                          'next': None,
                          'previous': None,
                          'results': [
                              {
                                  'id': 1,
                                  'component': 'Test Global Component',
                                  'role': 'pm',
                                  'contact': {
                                      'id': 1,
                                      'mail_name': 'maillist1',
                                      'email': '*****@*****.**'
                                  }
                              }
                          ]})
        with self.expect_output('global_component/detail.txt'):
            self.runner.run(['global-component', 'info', '1'])
        self.assertDictEqual(api.calls,
                             {'global-components/1': [('GET', {})],
                              'global-component-contacts':
                                  [('GET',
                                    {'component': 'Test Global Component',
                                     'page': 1})
                                   ]
                              })

    def test_update(self, api):
        self._setup_detail(api)
        api.add_endpoint('global-component-contacts',
                         'GET',
                         {'count': 1,
                          'next': None,
                          'previous': None,
                          'results': [
                              {
                                  'id': 1,
                                  'component': 'Test Global Component',
                                  'role': 'pm',
                                  'contact': {
                                      'id': 1,
                                      'mail_name': 'maillist1',
                                      'email': '*****@*****.**'
                                  }
                              }
                          ]})
        api.add_endpoint('global-components/1', 'PATCH', {})
        with self.expect_output('global_component/detail.txt'):
            self.runner.run(['global-component', 'update', '1', '--name', 'new test name'])
        self.assertDictEqual(api.calls,
                             {'global-components/1': [('PATCH', {'name': 'new test name'}),
                                                      ('GET', {})],
                              'global-component-contacts':
                                  [('GET',
                                    {'component': 'Test Global Component',
                                     'page': 1})
                                   ]
                              })

    def test_create(self, api):
        api.add_endpoint('global-component-contacts',
                         'GET',
                         {'count': 1,
                          'next': None,
                          'previous': None,
                          'results': [
                              {
                                  'id': 1,
                                  'component': 'Test Global Component',
                                  'role': 'pm',
                                  'contact': {
                                      'id': 1,
                                      'mail_name': 'maillist1',
                                      'email': '*****@*****.**'
                                  }
                              }
                          ]})
        api.add_endpoint('global-components', 'POST', self.detail)
        self._setup_detail(api)
        with self.expect_output('global_component/detail.txt'):
            self.runner.run(['global-component', 'create',
                             '--name', 'Test Global Component',
                             '--dist-git-path', 'test_global_component'])
        self.assertDictEqual(api.calls,
                             {'global-components': [('POST', {'name': 'Test Global Component',
                                                     'dist_git_path': 'test_global_component'})],
                              'global-components/1': [('GET', {})],
                              'global-component-contacts':
                                  [('GET',
                                    {'component': 'Test Global Component',
                                     'page': 1})
                                   ]
                              })

    def test_info_json(self, api):
        api.add_endpoint('global-component-contacts', 'GET', {'count': 0,
                                                              'next': None,
                                                              'previous': None,
                                                              'results': []})
        self._setup_detail(api)
        with self.expect_output('global_component/detail.json', parse_json=True):
            self.runner.run(['--json', 'global-component', 'info', '1'])
        self.assertDictEqual(api.calls,
                             {'global-components/1': [('GET', {})],
                              'global-component-contacts':
                                  [('GET',
                                    {'component': 'Test Global Component',
                                     'page': 1})
                                   ]
                              })

    def test_list_json(self, api):
        api.add_endpoint('global-components', 'GET', [self.detail])
        with self.expect_output('global_component/list.json', parse_json=True):
            self.runner.run(['--json', 'global-component', 'list',
                             '--label', 'test label'])
Пример #8
0
 def setUp(self):
     self.runner = Runner()
     self.runner.setup()
Пример #9
0
class RpmTestCase(CLITestCase):
    def setUp(self):
        self.runner = Runner()
        self.runner.setup()

    def test_list_without_filters(self, api):
        with self.expect_failure():
            self.runner.run(['rpm', 'list'])

    def _setup_list(self, api):
        api.add_endpoint('rpms', 'GET', [
            {'id': x,
             'name': 'bash',
             'epoch': 0,
             'version': '4.3.42',
             'release': x,
             'arch': 'x86_64'}
            for x in range(1, 30)
        ])

    def test_list(self, api):
        self._setup_list(api)
        with self.expect_output('list.txt'):
            self.runner.run(['rpm', 'list', '--name', 'bash'])
        self.assertEqual(api.calls['rpms'],
                         [('GET', {'page': 1, 'name': 'bash'}),
                          ('GET', {'page': 2, 'name': 'bash'})])

    def test_list_json(self, api):
        self._setup_list(api)
        with self.expect_output('list.json', parse_json=True):
            self.runner.run(['--json', 'rpm', 'list', '--name', 'bash'])
        self.assertEqual(api.calls['rpms'],
                         [('GET', {'page': 1, 'name': 'bash'}),
                          ('GET', {'page': 2, 'name': 'bash'})])

    def _setup_detail(self, api):
        obj = {
            'id': 1,
            'name': 'bash',
            'epoch': 0,
            'version': '4.3.42',
            'release': 1,
            'arch': 'x86_64',
            'srpm_name': 'bash',
            'srpm_nevra': 'bash-4.3.42-1.src',
            'filename': 'bash-0:4.3.42-1.x86_64.rpm',
            'linked_composes': ['compose-1'],
            'linked_releases': ['release-1'],
            'dependencies': {
                'requires': ['glibc > 0'],
                'obsoletes': [],
                'recommends': [],
                'suggests': [],
                'conflicts': [],
                'provides': [],
            }
        }
        api.add_endpoint('rpms/1', 'GET', obj)
        api.add_endpoint('rpms/1', 'PATCH', obj)
        api.add_endpoint('rpms', 'POST', obj)

    def test_info(self, api):
        self._setup_detail(api)
        with self.expect_output('info.txt'):
            self.runner.run(['rpm', 'info', '1'])
        self.assertEqual(api.calls['rpms/1'], [('GET', {})])

    def test_info_json(self, api):
        self._setup_detail(api)
        with self.expect_output('info.json', parse_json=True):
            self.runner.run(['--json', 'rpm', 'info', '1'])
        self.assertEqual(api.calls['rpms/1'], [('GET', {})])

    def test_create(self, api):
        self._setup_detail(api)
        with self.expect_output('info.txt'):
            self.runner.run(['rpm', 'create',
                             '--name', 'bash',
                             '--srpm-name', 'bash',
                             '--epoch', '0',
                             '--version', '4.3.42',
                             '--arch', 'x86_64',
                             '--release', '1'])
        self.assertEqual(api.calls['rpms'],
                         [('POST', {'name': 'bash', 'srpm_name': 'bash', 'arch': 'x86_64',
                                    'epoch': 0, 'version': '4.3.42', 'release': '1'})])
        self.assertEqual(api.calls['rpms/1'],
                         [('GET', {})])

    def test_update(self, api):
        self._setup_detail(api)
        with self.expect_output('info.txt'):
            self.runner.run(['rpm', 'update', '1',
                             '--name', 'bash',
                             '--srpm-name', 'bash',
                             '--epoch', '0',
                             '--version', '4.3.42',
                             '--release', '1'])
        self.assertEqual(api.calls['rpms/1'],
                         [('PATCH', {'name': 'bash', 'srpm_name': 'bash',
                                     'epoch': 0, 'version': '4.3.42', 'release': '1'}),
                          ('GET', {})])
Пример #10
0
class ComposeTestCase(CLITestCase):
    def setUp(self):
        self.runner = Runner()
        self.runner.setup()
        self.compose_detail = {
            "compose_id": "awesome-product-20130203.7",
            "compose_date": "2013-02-03",
            "compose_type": "nightly",
            "compose_respin": 0,
            "release": "aifv-5802",
            "compose_label": "RC-3.0",
            "deleted": False,
            "rpm_mapping_template": "https://pdc.example.com/rest_api/v1/composes/awesome-product-20130203.7/rpm-mapping/{{package}}/",
            "sigkeys": [
                "fd431d51"
            ],
            "acceptance_testing": "untested",
            "linked_releases": [
                "sap-7.0-awesome-product"
            ],
            "rtt_tested_architectures": {
                "Workstation": {
                    "x86_64": "untested"
                }
            }
        }

    def test_list_multi_page(self, api):
        api.add_endpoint('composes', 'GET', [
            {'compose_id': 'awesome-product-20150924.{}'.format(x)}
            for x in range(23)
        ])
        with self.expect_output('list_multi_page.txt'):
            self.runner.run(['compose', 'list'])
        self.assertEqual(api.calls['composes'],
                         [('GET', {'page': 1, 'deleted': False}),
                          ('GET', {'page': 2, 'deleted': False})])

    def test_list_deleted(self, api):
        api.add_endpoint('composes', 'GET', [])
        with self.expect_output('empty.txt'):
            self.runner.run(['compose', 'list', '--deleted'])
        self.assertEqual(api.calls['composes'],
                         [('GET', {'page': 1, 'deleted': True})])

    def test_info(self, api):
        api.add_endpoint('composes/awesome-product-20130203.7', 'GET', self.compose_detail)
        with self.expect_output('info.txt'):
            self.runner.run(['compose', 'info', 'awesome-product-20130203.7'])
        self.assertDictEqual(api.calls,
                             {'composes/awesome-product-20130203.7': [('GET', {})]})

    def test_info_json(self, api):
        api.add_endpoint('composes/awesome-product-20130203.7', 'GET', self.compose_detail)
        with self.expect_output('info.json', parse_json=True):
            self.runner.run(['--json', 'compose', 'info', 'awesome-product-20130203.7'])
        self.assertDictEqual(api.calls,
                             {'composes/awesome-product-20130203.7': [('GET', {})]})

    def test_update(self, api):
        api.add_endpoint('composes/awesome-product-20130203.7', 'GET', self.compose_detail)
        api.add_endpoint('composes/awesome-product-20130203.7', 'PATCH', {})
        with self.expect_output('info.txt'):
            self.runner.run(['compose', 'update', 'awesome-product-20130203.7',
                             '--acceptance-testing', 'passed',
                             '--linked-releases', 'sap-7.0-awesome-product',
                             '--rtt-tested-architectures', 'Workstation:x86_64:passed'
                             ])
        self.assertDictEqual(api.calls, {'composes/awesome-product-20130203.7':
                                         [('PATCH', {'acceptance_testing': 'passed',
                                                     'linked_releases': ['sap-7.0-awesome-product'],
                                                     'rtt_tested_architectures': {'Workstation': {'x86_64': 'passed'}}}),
                                          ('GET', {})]})

    def test_update_wrong_input1(self, api):
        with self.expect_failure():
            self.runner.run(['compose', 'update', 'awesome-product-20130203.7',
                             '--acceptance-testing', 'passed',
                             '--linked-releases', 'sap-7.0-awesome-product',
                             '--rtt-tested-architectures', 'Workstation:x86_64:passed:wronginput'
                             ])

    def test_update_wrong_input2(self, api):
        with self.expect_failure():
            self.runner.run(['compose', 'update', 'awesome-product-20130203.7',
                             '--acceptance-testing', 'wronginput',
                             '--linked-releases', 'sap-7.0-awesome-product',
                             '--rtt-tested-architectures', 'Workstation:x86_64:passed'
                             ])
Пример #11
0
class ReleaseComponentContactTestCase(CLITestCase):
    def setUp(self):
        self.runner = Runner()
        self.runner.setup()
        self.detail = {
            "id": "1",
            "component": {"name": "Test Release Component", "release": "test-release"},
            "role": "pm",
            "contact": {"username": "******", "email": "*****@*****.**"},
        }

    def _setup_detail(self, api):
        api.add_endpoint("release-component-contacts/1", "GET", self.detail)

    def test_list_without_filters(self, api):
        with self.expect_failure():
            self.runner.run(["release-component-contact", "list"])

    def test_list_multi_page(self, api):
        api.add_endpoint(
            "release-component-contacts",
            "GET",
            [
                {
                    "id": x,
                    "component": {"name": "Test Release Component %s" % x, "release": "test-release"},
                    "role": "watcher",
                    "contact": {"username": "******", "email": "*****@*****.**"},
                }
                for x in range(1, 26)
            ],
        )
        with self.expect_output("release_component_contact/list_multi_page.txt"):
            self.runner.run(["release-component-contact", "list", "--role", "watcher"])
        self.assertEqual(
            api.calls["release-component-contacts"],
            [("GET", {"page": 1, "role": "watcher"}), ("GET", {"page": 2, "role": "watcher"})],
        )

    def test_detail(self, api):
        self._setup_detail(api)
        with self.expect_output("release_component_contact/detail.txt"):
            self.runner.run(["release-component-contact", "info", "1"])
        self.assertDictEqual(api.calls, {"release-component-contacts/1": [("GET", {})]})

    def test_delete(self, api):
        api.add_endpoint("release-component-contacts/1", "DELETE", None)
        with self.expect_output("release_component_contact/empty.txt"):
            self.runner.run(["release-component-contact", "delete", "1"])
        self.assertDictEqual(api.calls, {"release-component-contacts/1": [("DELETE", {})]})

    def test_delete_matched(self, api):
        api.add_endpoint("release-component-contacts", "GET", [self.detail])
        api.add_endpoint("release-component-contacts/1", "DELETE", None)
        with self.expect_output("release_component_contact/empty.txt"):
            self.runner.run(["release-component-contact", "delete-match", "--role", "pm"])
        self.assertDictEqual(
            api.calls,
            {
                "release-component-contacts": [("GET", {"page": 1, "role": "pm"})],
                "release-component-contacts/1": [("DELETE", {})],
            },
        )

    def test_delete_multi_matches(self, api):
        api.add_endpoint("release-component-contacts", "GET", [self.detail] * 2)
        with self.expect_output("release_component_contact/multi_matches.txt"):
            self.runner.run(["release-component-contact", "delete-match", "--role", "pm"])
        self.assertDictEqual(api.calls, {"release-component-contacts": [("GET", {"page": 1, "role": "pm"})]})

    def test_create(self, api):
        api.add_endpoint("release-component-contacts", "POST", self.detail)
        self._setup_detail(api)
        with self.expect_output("release_component_contact/detail.txt"):
            self.runner.run(
                [
                    "release-component-contact",
                    "create",
                    "--release",
                    "test-release",
                    "--component",
                    "Test Release Component",
                    "--role",
                    "pm",
                    "--username",
                    "Test Contact",
                    "--email",
                    "*****@*****.**",
                ]
            )
        self.assertDictEqual(
            api.calls,
            {
                "release-component-contacts": [
                    (
                        "POST",
                        {
                            "component": {"name": "Test Release Component", "release": "test-release"},
                            "role": "pm",
                            "contact": {"username": "******", "email": "*****@*****.**"},
                        },
                    )
                ],
                "release-component-contacts/1": [("GET", {})],
            },
        )

    def test_info_json(self, api):
        self._setup_detail(api)
        with self.expect_output("release_component_contact/detail.json", parse_json=True):
            self.runner.run(["--json", "release-component-contact", "info", "1"])
        self.assertDictEqual(api.calls, {"release-component-contacts/1": [("GET", {})]})

    def test_list_json(self, api):
        api.add_endpoint("release-component-contacts", "GET", [self.detail])
        with self.expect_output("release_component_contact/list.json", parse_json=True):
            self.runner.run(["--json", "release-component-contact", "list", "--role", "pm"])
Пример #12
0
class ImageTestCase(CLITestCase):
    def setUp(self):
        self.runner = Runner()
        self.runner.setup()

    def _setup_list(self, api):
        api.add_endpoint('images', 'GET', [
            {'file_name': 'image-{}'.format(x),
             'sha256': '112233445566778899{:02}'.format(x)}
            for x in range(30)
        ])

    def _setup_detail(self, api):
        api.add_endpoint('images', 'GET', [
            {'file_name': 'unique_image.iso',
             'mtime': 1442923687,
             'image_type': 'dvd',
             'image_format': 'iso',
             'arch': 'x86_64',
             'disc_number': 1,
             'disc_count': 1,
             'size': 123456789,
             'bootable': True,
             'volume_id': 'VolumeID',
             'md5': '11111111111111111111111111111111',
             'sha1': '2222222222222222222222222222222222222222',
             'sha256': '3333333333333333333333333333333333333333333333333333333333333333',
             'implant_md5': '00000000000000000000000000000000',
             'composes': ['compose-1']}])

    def _setup_duplicit_detail(self, api):
        api.add_endpoint('images', 'GET', [
            {'file_name': 'unique_image.iso',
             'mtime': 1442923687,
             'image_type': 'dvd',
             'image_format': 'iso',
             'arch': 'x86_64',
             'disc_number': 1,
             'disc_count': 1,
             'size': 123456789,
             'bootable': True,
             'volume_id': 'VolumeID',
             'md5': '11111111111111111111111111111111',
             'sha1': '2222222222222222222222222222222222222222',
             'sha256': '3333333333333333333333333333333333333333333333333333333333333333',
             'implant_md5': '00000000000000000000000000000000',
             'composes': ['compose-1']},
            {'file_name': 'unique_image.iso',
             'mtime': 1442923687,
             'image_type': 'dvd',
             'image_format': 'iso',
             'arch': 'x86_64',
             'disc_number': 1,
             'disc_count': 1,
             'size': 123456789,
             'bootable': True,
             'volume_id': 'VolumeID',
             'md5': '11111111111111111111111111111111',
             'sha1': '2222222222222222222222222222222222222222',
             'sha256': '4444444444444444444444444444444444444444444444444444444444444444',
             'implant_md5': '00000000000000000000000000000000',
             'composes': ['compose-1']}])

    def test_list(self, api):
        self._setup_list(api)
        with self.expect_output('list_multi_page.txt'):
            self.runner.run(['image', 'list'])
        self.assertEqual(api.calls['images'],
                         [('GET', {'page': 1}),
                          ('GET', {'page': 2})])

    def test_list_json(self, api):
        self._setup_list(api)
        with self.expect_output('list_multi_page.json', parse_json=True):
            self.runner.run(['--json', 'image', 'list'])
        self.assertEqual(api.calls['images'],
                         [('GET', {'page': 1}),
                          ('GET', {'page': 2})])

    def test_list_filters(self, api):
        api.add_endpoint('images', 'GET', [])
        filters = ['sha256', 'compose', 'volume-id', 'sha1', 'image-type',
                   'file-name', 'image-format', 'arch', 'md5', 'implant-md5']
        for filter in filters:
            with self.expect_output('empty.txt'):
                self.runner.run(['image', 'list', '--' + filter, filter])
        self.assertEqual(api.calls['images'],
                         [('GET', {'page': 1, filter.replace('-', '_'): filter})
                          for filter in filters])

    def test_show_sha256(self, api):
        self._setup_list(api)
        with self.expect_output('list_multi_page_with_sha256.txt'):
            self.runner.run(['image', 'list', '--show-sha256'])
        self.assertEqual(api.calls['images'],
                         [('GET', {'page': 1}),
                          ('GET', {'page': 2})])

    def test_info(self, api):
        self._setup_detail(api)
        with self.expect_output('info.txt'):
            self.runner.run(['image', 'info', 'unique_filename.iso'])
        self.assertEqual(api.calls['images'],
                         [('GET', {'file_name': 'unique_filename.iso'})])

    def test_info_json(self, api):
        self._setup_detail(api)
        with self.expect_output('info.json', parse_json=True):
            self.runner.run(['--json', 'image', 'info', 'unique_filename.iso'])
        self.assertEqual(api.calls['images'],
                         [('GET', {'file_name': 'unique_filename.iso'})])

    def test_info_ambiguous(self, api):
        self._setup_duplicit_detail(api)
        with self.expect_output('duplicit.txt'):
            with self.expect_failure():
                self.runner.run(['image', 'info', 'unique_filename.iso'])
        self.assertEqual(api.calls['images'],
                         [('GET', {'file_name': 'unique_filename.iso'})])

    def test_info_with_sha(self, api):
        self._setup_detail(api)
        with self.expect_output('info.txt'):
            self.runner.run(['image', 'info', 'unique_filename.iso',
                             '--sha256', '3333333333333333333333333333333333333333333333333333333333333333'])
        self.assertEqual(api.calls['images'],
                         [('GET', {'file_name': 'unique_filename.iso',
                                   'sha256': '3333333333333333333333333333333333333333333333333333333333333333'})])