openSUSE-release-tools/tests/select_tests.py

65 lines
2.8 KiB
Python
Raw Normal View History

2014-03-04 12:45:44 +01:00
import unittest
from obs import APIURL
2014-03-04 12:45:44 +01:00
from obs import OBS
from osc import oscerr
from osclib.comments import CommentAPI
from osclib.conf import Config
2014-03-04 15:00:25 +01:00
from osclib.select_command import SelectCommand
2014-06-23 15:03:16 +02:00
from osclib.stagingapi import StagingAPI
2014-03-04 12:45:44 +01:00
2014-06-23 15:03:16 +02:00
2014-03-04 12:45:44 +01:00
class TestSelect(unittest.TestCase):
2014-03-04 15:00:25 +01:00
2014-03-04 12:45:44 +01:00
def setUp(self):
"""
Initialize the configuration
"""
self.obs = OBS()
Config(APIURL, 'openSUSE:Factory')
self.api = StagingAPI(APIURL, 'openSUSE:Factory')
2014-03-04 12:45:44 +01:00
2014-03-04 15:00:25 +01:00
def test_old_frozen(self):
self.assertEqual(self.api.prj_frozen_enough('openSUSE:Factory:Staging:A'), False)
# check it won't allow selecting
2015-07-18 13:48:15 +02:00
self.assertEqual(False, SelectCommand(self.api, 'openSUSE:Factory:Staging:A').perform(['gcc']))
2014-07-01 09:29:03 +02:00
def test_select_comments(self):
c_api = CommentAPI(self.api.apiurl)
staging_b = 'openSUSE:Factory:Staging:B'
comments = c_api.get_comments(project_name=staging_b)
# First select
2015-07-18 13:48:15 +02:00
self.assertEqual(True, SelectCommand(self.api, staging_b).perform(['gcc', 'wine']))
first_select_comments = c_api.get_comments(project_name=staging_b)
last_id = sorted(first_select_comments.keys())[-1]
first_select_comment = first_select_comments[last_id]
# Only one comment is added
self.assertEqual(len(first_select_comments), len(comments) + 1)
# With the right content
self.assertTrue('request#123 for package gcc submitted by @Admin' in first_select_comment['comment'])
# Second select
2015-07-18 13:48:15 +02:00
self.assertEqual(True, SelectCommand(self.api, staging_b).perform(['puppet']))
second_select_comments = c_api.get_comments(project_name=staging_b)
last_id = sorted(second_select_comments.keys())[-1]
second_select_comment = second_select_comments[last_id]
# The number of comments increased by one
self.assertEqual(len(second_select_comments) - 1, len(first_select_comments))
self.assertNotEqual(second_select_comment['comment'], first_select_comment['comment'])
# The new comments contains new, but not old
self.assertFalse('request#123 for package gcc submitted by @Admin' in second_select_comment['comment'])
self.assertTrue('added request#321 for package puppet submitted by @Admin' in second_select_comment['comment'])
2014-03-04 15:00:25 +01:00
def test_no_matches(self):
2014-03-04 12:45:44 +01:00
# search for requests
with self.assertRaises(oscerr.WrongArgs) as cm:
2015-07-18 13:48:15 +02:00
SelectCommand(self.api, 'openSUSE:Factory:Staging:B').perform(['bash'])
2014-03-04 12:45:44 +01:00
self.assertEqual(str(cm.exception), "No SR# found for: bash")
2014-03-04 15:00:25 +01:00
def test_selected(self):
# make sure the project is frozen recently for other tests
2015-07-18 13:48:15 +02:00
ret = SelectCommand(self.api, 'openSUSE:Factory:Staging:B').perform(['wine'])
2014-03-04 15:00:25 +01:00
self.assertEqual(True, ret)