2014-03-04 12:45:44 +01:00
|
|
|
import unittest
|
|
|
|
|
2019-04-30 11:44:37 +02:00
|
|
|
from . import obs
|
2014-03-04 12:45:44 +01:00
|
|
|
from osc import oscerr
|
2015-02-19 10:57:55 +01:00
|
|
|
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
|
|
|
|
"""
|
2019-04-30 11:44:37 +02:00
|
|
|
self.obs = obs.OBS()
|
|
|
|
Config(obs.APIURL, 'openSUSE:Factory')
|
|
|
|
self.api = StagingAPI(obs.APIURL, 'openSUSE:Factory')
|
2014-03-04 12:45:44 +01:00
|
|
|
|
2014-03-04 15:00:25 +01:00
|
|
|
def test_old_frozen(self):
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual(self.api.prj_frozen_enough('openSUSE:Factory:Staging:A'), False)
|
2014-06-17 14:39:51 +02:00
|
|
|
# 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
|
|
|
|
2014-06-04 16:54:21 +02:00
|
|
|
def test_select_comments(self):
|
|
|
|
c_api = CommentAPI(self.api.apiurl)
|
2014-06-17 14:39:51 +02:00
|
|
|
staging_b = 'openSUSE:Factory:Staging:B'
|
|
|
|
comments = c_api.get_comments(project_name=staging_b)
|
2014-06-04 16:54:21 +02:00
|
|
|
|
|
|
|
# First select
|
2015-07-18 13:48:15 +02:00
|
|
|
self.assertEqual(True, SelectCommand(self.api, staging_b).perform(['gcc', 'wine']))
|
2014-06-17 14:39:51 +02:00
|
|
|
first_select_comments = c_api.get_comments(project_name=staging_b)
|
2014-06-04 16:54:21 +02:00
|
|
|
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
|
2018-10-04 09:52:49 +02:00
|
|
|
self.assertTrue('request#123 for package gcc submitted by Admin' in first_select_comment['comment'])
|
2014-06-04 16:54:21 +02:00
|
|
|
|
|
|
|
# Second select
|
2015-07-18 13:48:15 +02:00
|
|
|
self.assertEqual(True, SelectCommand(self.api, staging_b).perform(['puppet']))
|
2014-06-17 14:39:51 +02:00
|
|
|
second_select_comments = c_api.get_comments(project_name=staging_b)
|
2014-06-04 16:54:21 +02:00
|
|
|
last_id = sorted(second_select_comments.keys())[-1]
|
|
|
|
second_select_comment = second_select_comments[last_id]
|
2017-06-01 10:04:52 +02:00
|
|
|
# The number of comments increased by one
|
|
|
|
self.assertEqual(len(second_select_comments) - 1, len(first_select_comments))
|
2014-06-04 16:54:21 +02:00
|
|
|
self.assertNotEqual(second_select_comment['comment'], first_select_comment['comment'])
|
2017-06-01 10:04:52 +02:00
|
|
|
# The new comments contains new, but not old
|
2018-10-04 09:52:49 +02:00
|
|
|
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-06-04 16:54:21 +02:00
|
|
|
|
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)
|