Skip to content

Commit

Permalink
Add tests for compose plugin.
Browse files Browse the repository at this point in the history
Fixing review comments as well.
  • Loading branch information
simozhan committed Sep 28, 2015
1 parent 9a8050e commit 49c136f
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pdc_client/plugins/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
# http://opensource.org/licenses/MIT
#
import json
import sys

from pdc_client.plugins import PDCClientPlugin, get_paged, add_parser_arguments, extract_arguments
from pdc_client.plugin_helpers import PDCClientPlugin, get_paged, add_parser_arguments, extract_arguments


class ComposePlugin(PDCClientPlugin):
Expand All @@ -22,18 +21,19 @@ def register(self):
subcmd.set_defaults(func=self.compose_info)

subcmd = self.add_admin_command('compose-update',
help='partial update an existing compose.\
only some compose fields can be modified by this call.\
these are acceptance_testing, linked_releases and rtt_tested_architectures.')
help='partial update an existing compose.',
description='only some compose fields can be modified by this call.\
these are acceptance_testing, linked_releases and rtt_tested_architectures.')
subcmd.add_argument('compose_id', metavar='COMPOSE_ID')
self.add_compose_arguments(subcmd)
subcmd.set_defaults(func=self.compose_update)
self.compose_update = subcmd

def add_compose_arguments(self, parser):
add_parser_arguments(parser, {
'acceptance_testing': {},
'acceptance_testing': {'choices': ['passed', 'failed', 'untested']},
'linked_releases': {'nargs': '*', 'metavar': 'RELEASE_ID'},
'rtt_tested_architectures': {'nargs': '*', 'help': 'input format VARIANT:ARCHES:TESTING_STATUS'}})
'rtt_tested_architectures': {'nargs': '*', 'default': [], 'help': 'input format VARIANT:ARCHES:TESTING_STATUS'}})

def list_composes(self, args):
filters = {}
Expand Down Expand Up @@ -104,9 +104,9 @@ def get_compose_data(self, args):
dic = {}
for rtt in rtts:
parts = rtt.split(':')
if len(parts) < 3:
sys.stderr.write('Please input rtt-tested-architectures in format VARIANT:ARCHES:TESTING_STATUS.\n')
sys.exit(1)
if not len(parts) == 3:
self.compose_update.error('Please input rtt-tested-architectures in format VARIANT:ARCHES:TESTING_STATUS.\n')

variant = parts[0]
arches = parts[1]
status = parts[2]
Expand Down
Empty file.
Empty file.
22 changes: 22 additions & 0 deletions pdc_client/tests/compose/data/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compose_id": "RHEL-7.0-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-dt.app.qa.eng.nay.redhat.com/rest_api/v1/composes/RHEL-7.0-20130203.7/rpm-mapping/{{package}}/",
"sigkeys": [
"fd431d51"
],
"acceptance_testing": "untested",
"linked_releases": [
"sap-7.0-rhel-7"
],
"rtt_tested_architectures": {
"Workstation": {
"x86_64": "untested"
}
}
}
19 changes: 19 additions & 0 deletions pdc_client/tests/compose/data/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Compose ID RHEL-7.0-20130203.7
Compose Label RC-3.0
Compose Date 2013-02-03
Compose Respin 0
Compose Type nightly
Acceptance Testing untested
Deleted False
Release aifv-5802
Rpm Mapping Template https://pdc-dt.app.qa.eng.nay.redhat.com/rest_api/v1/composes/RHEL-7.0-20130203.7/rpm-mapping/{{package}}/

Linked Releases
Release sap-7.0-rhel-7

Sigkeys
Sigkey fd431d51

Rtt Tested Architectures
Variant Arches Testing Status
Workstation x86_64 untested
23 changes: 23 additions & 0 deletions pdc_client/tests/compose/data/list_multi_page.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
RHEL-7.1-20150924.0
RHEL-7.1-20150924.1
RHEL-7.1-20150924.2
RHEL-7.1-20150924.3
RHEL-7.1-20150924.4
RHEL-7.1-20150924.5
RHEL-7.1-20150924.6
RHEL-7.1-20150924.7
RHEL-7.1-20150924.8
RHEL-7.1-20150924.9
RHEL-7.1-20150924.10
RHEL-7.1-20150924.11
RHEL-7.1-20150924.12
RHEL-7.1-20150924.13
RHEL-7.1-20150924.14
RHEL-7.1-20150924.15
RHEL-7.1-20150924.16
RHEL-7.1-20150924.17
RHEL-7.1-20150924.18
RHEL-7.1-20150924.19
RHEL-7.1-20150924.20
RHEL-7.1-20150924.21
RHEL-7.1-20150924.22
98 changes: 98 additions & 0 deletions pdc_client/tests/compose/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2015 Red Hat
# Licensed under The MIT License (MIT)
# http://opensource.org/licenses/MIT
#
from pdc_client.test_helpers import CLITestCase
from pdc_client.runner import Runner


class ComposeTestCase(CLITestCase):
def setUp(self):
self.runner = Runner()
self.runner.setup()
self.compose_detail = {
"compose_id": "RHEL-7.0-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-dt.app.qa.eng.nay.redhat.com/rest_api/v1/composes/RHEL-7.0-20130203.7/rpm-mapping/{{package}}/",
"sigkeys": [
"fd431d51"
],
"acceptance_testing": "untested",
"linked_releases": [
"sap-7.0-rhel-7"
],
"rtt_tested_architectures": {
"Workstation": {
"x86_64": "untested"
}
}
}

def test_list_multi_page(self, api):
api.add_endpoint('composes', 'GET', [
{'compose_id': 'RHEL-7.1-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/RHEL-7.0-20130203.7', 'GET', self.compose_detail)
with self.expect_output('info.txt'):
self.runner.run(['compose-info', 'RHEL-7.0-20130203.7'])
self.assertDictEqual(api.calls,
{'composes/RHEL-7.0-20130203.7': [('GET', {})]})

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

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

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

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

0 comments on commit 49c136f

Please sign in to comment.