2014-03-04 12:45:44 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# (C) 2014 tchvatal@suse.cz, openSUSE.org
|
|
|
|
# Distribute under GPLv2 or later
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import unittest
|
|
|
|
import httpretty
|
|
|
|
import time
|
|
|
|
|
2014-06-03 18:05:05 +02:00
|
|
|
from obs import APIURL
|
2014-03-04 12:45:44 +01:00
|
|
|
from obs import OBS
|
|
|
|
from osc import oscerr
|
2014-03-04 15:00:25 +01:00
|
|
|
from osclib.select_command import SelectCommand
|
2014-06-03 18:05:05 +02:00
|
|
|
from oscs import StagingAPI
|
2014-06-04 16:54:21 +02:00
|
|
|
from osclib.comments import CommentAPI
|
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()
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api = StagingAPI(APIURL)
|
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)
|
|
|
|
self.assertEqual(True, SelectCommand(self.api).perform('openSUSE:Factory:Staging:A', ['gcc']))
|
|
|
|
self.assertEqual(self.api.prj_frozen_enough('openSUSE:Factory:Staging:A'), True)
|
2014-03-04 12:45:44 +01:00
|
|
|
|
2014-06-04 16:54:21 +02:00
|
|
|
def test_select_comments(self):
|
|
|
|
c_api = CommentAPI(self.api.apiurl)
|
|
|
|
staging_a = 'openSUSE:Factory:Staging:A'
|
|
|
|
comments = c_api.get_comments(project_name=staging_a)
|
|
|
|
|
|
|
|
# First select
|
|
|
|
self.assertEqual(True, SelectCommand(self.api).perform(staging_a, ['gcc', 'wine']))
|
|
|
|
first_select_comments = c_api.get_comments(project_name=staging_a)
|
|
|
|
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
|
2014-06-17 11:39:59 +02:00
|
|
|
self.assertTrue('Request#123 for package gcc submitted by [AT]Admin' in first_select_comment['comment'])
|
2014-06-04 16:54:21 +02:00
|
|
|
|
|
|
|
# Second select
|
|
|
|
self.assertEqual(True, SelectCommand(self.api).perform(staging_a, ['puppet']))
|
|
|
|
second_select_comments = c_api.get_comments(project_name=staging_a)
|
|
|
|
last_id = sorted(second_select_comments.keys())[-1]
|
|
|
|
second_select_comment = second_select_comments[last_id]
|
|
|
|
# The number of comments remains, but they are different
|
|
|
|
self.assertEqual(len(second_select_comments), len(first_select_comments))
|
|
|
|
self.assertNotEqual(second_select_comment['comment'], first_select_comment['comment'])
|
|
|
|
# The new comments contents both old and new information
|
2014-06-17 11:39:59 +02:00
|
|
|
self.assertTrue('Request#123 for package gcc submitted by [AT]Admin' in second_select_comment['comment'])
|
|
|
|
self.assertTrue('Request#321 for package puppet submitted by [AT]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:
|
2014-06-03 18:05:05 +02:00
|
|
|
SelectCommand(self.api).perform('openSUSE:Factory:Staging:B', ['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
|
|
|
|
|
2014-06-03 18:05:05 +02:00
|
|
|
ret = SelectCommand(self.api).perform('openSUSE:Factory:Staging:B', ['wine'])
|
2014-03-04 15:00:25 +01:00
|
|
|
self.assertEqual(True, ret)
|