2014-02-13 14:15:14 +01:00
|
|
|
import sys
|
2014-02-04 11:23:23 +01:00
|
|
|
import unittest
|
2014-02-04 14:04:46 +01:00
|
|
|
import httpretty
|
2014-02-28 11:11:10 +01:00
|
|
|
|
2019-04-30 11:44:37 +02:00
|
|
|
from . import obs
|
2015-02-19 10:57:55 +01:00
|
|
|
from osclib.conf import Config
|
2014-06-23 15:03:16 +02:00
|
|
|
from osclib.stagingapi import StagingAPI
|
2014-06-03 18:05:05 +02:00
|
|
|
|
2014-02-24 15:52:30 +01:00
|
|
|
class TestApiCalls(unittest.TestCase):
|
|
|
|
"""
|
|
|
|
Tests for various api calls to ensure we return expected content
|
|
|
|
"""
|
|
|
|
|
2014-02-04 14:04:46 +01:00
|
|
|
def setUp(self):
|
|
|
|
"""
|
2014-02-24 17:20:48 +01:00
|
|
|
Initialize the configuration
|
2014-02-04 14:04:46 +01:00
|
|
|
"""
|
|
|
|
|
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-02-04 11:23:23 +01:00
|
|
|
|
2015-08-03 13:21:12 +02:00
|
|
|
def tearDown(self):
|
|
|
|
"""Clean internal cache"""
|
2016-05-10 10:29:37 +02:00
|
|
|
if hasattr(self.api, '_invalidate_all'):
|
|
|
|
self.api._invalidate_all()
|
2015-08-03 13:21:12 +02:00
|
|
|
|
2014-02-10 13:24:49 +01:00
|
|
|
def test_ring_packages(self):
|
|
|
|
"""
|
|
|
|
Validate the creation of the rings.
|
|
|
|
"""
|
|
|
|
# our content in the XML files
|
2016-06-13 16:55:05 +08:00
|
|
|
# test content for listonly ie. list command
|
|
|
|
ring_packages = {
|
2017-05-05 17:44:15 +08:00
|
|
|
'apparmor': 'openSUSE:Factory:Rings:1-MinimalX',
|
2016-06-13 16:55:05 +08:00
|
|
|
'elem-ring-0': 'openSUSE:Factory:Rings:0-Bootstrap',
|
|
|
|
'elem-ring-1': 'openSUSE:Factory:Rings:0-Bootstrap',
|
|
|
|
'elem-ring-mini': 'openSUSE:Factory:Rings:0-Bootstrap',
|
|
|
|
'wine': 'openSUSE:Factory:Rings:1-MinimalX',
|
|
|
|
}
|
|
|
|
self.assertEqual(ring_packages, self.api.ring_packages_for_links)
|
|
|
|
|
|
|
|
# test content for real usage
|
2014-02-12 13:15:49 +01:00
|
|
|
ring_packages = {
|
2017-05-05 17:44:15 +08:00
|
|
|
'apparmor': 'openSUSE:Factory:Rings:1-MinimalX',
|
2014-02-12 13:15:49 +01:00
|
|
|
'elem-ring-0': 'openSUSE:Factory:Rings:0-Bootstrap',
|
|
|
|
'elem-ring-1': 'openSUSE:Factory:Rings:1-MinimalX',
|
2016-06-13 16:55:05 +08:00
|
|
|
'elem-ring-mini': 'openSUSE:Factory:Rings:0-Bootstrap',
|
2014-03-04 15:45:59 +01:00
|
|
|
'wine': 'openSUSE:Factory:Rings:1-MinimalX',
|
2014-02-12 13:15:49 +01:00
|
|
|
}
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual(ring_packages, self.api.ring_packages)
|
2014-02-10 13:24:49 +01:00
|
|
|
|
2015-07-16 12:21:15 +02:00
|
|
|
@unittest.skip("no longer approving non-ring packages")
|
2014-02-10 13:58:59 +01:00
|
|
|
def test_dispatch_open_requests(self):
|
|
|
|
"""
|
|
|
|
Test dispatching and closure of non-ring packages
|
|
|
|
"""
|
|
|
|
|
2014-02-24 15:52:30 +01:00
|
|
|
# Get rid of open requests
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.dispatch_open_requests()
|
2014-02-24 15:52:30 +01:00
|
|
|
# Check that we tried to close it
|
|
|
|
self.assertEqual(httpretty.last_request().method, 'POST')
|
|
|
|
self.assertEqual(httpretty.last_request().querystring[u'cmd'], [u'changereviewstate'])
|
|
|
|
# Try it again
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.dispatch_open_requests()
|
2014-02-24 15:52:30 +01:00
|
|
|
# This time there should be nothing to close
|
|
|
|
self.assertEqual(httpretty.last_request().method, 'GET')
|
2014-02-10 13:24:49 +01:00
|
|
|
|
2014-02-10 14:25:31 +01:00
|
|
|
def test_pseudometa_get_prj(self):
|
|
|
|
"""
|
|
|
|
Test getting project metadata from YAML in project description
|
|
|
|
"""
|
|
|
|
|
2014-02-25 09:28:46 +01:00
|
|
|
# Try to get data from project that has no metadata
|
2014-06-03 18:05:05 +02:00
|
|
|
data = self.api.get_prj_pseudometa('openSUSE:Factory:Staging:A')
|
2014-02-25 09:28:46 +01:00
|
|
|
# Should be empty, but contain structure to work with
|
|
|
|
self.assertEqual(data, {'requests': []})
|
|
|
|
# Add some sample data
|
2014-06-03 18:05:05 +02:00
|
|
|
rq = {'id': '123', 'package': 'test-package'}
|
2014-02-25 09:28:46 +01:00
|
|
|
data['requests'].append(rq)
|
|
|
|
# Save them and read them back
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.set_prj_pseudometa('openSUSE:Factory:Staging:A', data)
|
|
|
|
test_data = self.api.get_prj_pseudometa('openSUSE:Factory:Staging:A')
|
2014-02-25 09:28:46 +01:00
|
|
|
# Verify that we got back the same data
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual(data, test_data)
|
2014-02-13 10:44:58 +01:00
|
|
|
|
2014-02-04 11:23:23 +01:00
|
|
|
def test_list_projects(self):
|
|
|
|
"""
|
|
|
|
List projects and their content
|
|
|
|
"""
|
2014-02-10 13:58:59 +01:00
|
|
|
|
2014-02-25 13:12:10 +01:00
|
|
|
# Prepare expected results
|
|
|
|
data = []
|
2014-06-03 18:05:05 +02:00
|
|
|
for prj in self.obs.staging_project:
|
2014-02-25 13:12:10 +01:00
|
|
|
data.append('openSUSE:Factory:Staging:' + prj)
|
2014-02-10 13:24:49 +01:00
|
|
|
|
|
|
|
# Compare the results
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual(data, self.api.get_staging_projects())
|
2014-02-10 13:24:49 +01:00
|
|
|
|
|
|
|
def test_open_requests(self):
|
|
|
|
"""
|
2014-02-12 14:27:49 +01:00
|
|
|
Test searching for open requests
|
2014-02-10 13:24:49 +01:00
|
|
|
"""
|
|
|
|
|
2014-02-10 13:58:59 +01:00
|
|
|
requests = []
|
2014-02-10 13:24:49 +01:00
|
|
|
|
|
|
|
# get the open requests
|
2014-06-03 18:05:05 +02:00
|
|
|
requests = self.api.get_open_requests()
|
2014-02-10 13:24:49 +01:00
|
|
|
|
2014-02-24 17:20:48 +01:00
|
|
|
# Compare the results, we only care now that we got 1 of them not the content
|
|
|
|
self.assertEqual(1, len(requests))
|
2014-02-10 13:24:49 +01:00
|
|
|
|
2014-02-12 14:27:49 +01:00
|
|
|
def test_get_package_information(self):
|
|
|
|
"""
|
|
|
|
Test if we get proper project, name and revision from the staging informations
|
|
|
|
"""
|
|
|
|
|
2014-06-03 18:05:05 +02:00
|
|
|
package_info = {
|
2014-06-12 18:25:45 +02:00
|
|
|
'dir_srcmd5': '751efeae52d6c99de48164088a33d855',
|
2014-06-03 18:05:05 +02:00
|
|
|
'project': 'home:Admin',
|
|
|
|
'rev': '7b98ac01b8071d63a402fa99dc79331c',
|
|
|
|
'srcmd5': '7b98ac01b8071d63a402fa99dc79331c',
|
|
|
|
'package': 'wine'
|
|
|
|
}
|
2014-02-12 14:27:49 +01:00
|
|
|
|
|
|
|
# Compare the results, we only care now that we got 2 of them not the content
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual(
|
|
|
|
package_info,
|
|
|
|
self.api.get_package_information('openSUSE:Factory:Staging:B', 'wine'))
|
2014-02-12 14:27:49 +01:00
|
|
|
|
2014-02-26 10:04:21 +01:00
|
|
|
def test_request_id_package_mapping(self):
|
2014-02-26 09:51:30 +01:00
|
|
|
"""
|
|
|
|
Test whether we can get correct id for sr in staging project
|
|
|
|
"""
|
|
|
|
|
2014-02-26 10:04:21 +01:00
|
|
|
prj = 'openSUSE:Factory:Staging:B'
|
|
|
|
# Get rq
|
2014-06-03 18:05:05 +02:00
|
|
|
num = self.api.get_request_id_for_package(prj, 'wine')
|
|
|
|
self.assertEqual(333, num)
|
2014-02-26 10:04:21 +01:00
|
|
|
# Get package name
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual('wine', self.api.get_package_for_request_id(prj, num))
|
2014-02-26 09:51:30 +01:00
|
|
|
|
2014-06-03 18:05:05 +02:00
|
|
|
def test_rm_from_prj(self):
|
2014-02-26 10:59:41 +01:00
|
|
|
prj = 'openSUSE:Factory:Staging:B'
|
2014-02-26 15:24:25 +01:00
|
|
|
pkg = 'wine'
|
2014-02-26 10:59:41 +01:00
|
|
|
|
2014-06-03 18:05:05 +02:00
|
|
|
full_name = prj + '/' + pkg
|
|
|
|
|
2014-02-26 10:59:41 +01:00
|
|
|
# Verify package is there
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertTrue(full_name in self.obs.links)
|
|
|
|
|
2014-02-26 10:59:41 +01:00
|
|
|
# Get rq number
|
2014-06-03 18:05:05 +02:00
|
|
|
num = self.api.get_request_id_for_package(prj, pkg)
|
|
|
|
|
2014-02-26 10:59:41 +01:00
|
|
|
# Delete the package
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.rm_from_prj(prj, package='wine')
|
|
|
|
|
2014-02-26 10:59:41 +01:00
|
|
|
# Verify package is not there
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertTrue(full_name not in self.obs.links)
|
|
|
|
|
2014-02-26 15:24:25 +01:00
|
|
|
# RQ is gone
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual(None, self.api.get_request_id_for_package(prj, pkg))
|
|
|
|
self.assertEqual(None, self.api.get_package_for_request_id(prj, num))
|
|
|
|
|
2014-02-26 10:59:41 +01:00
|
|
|
# Verify that review is closed
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual('accepted', self.obs.requests[str(num)]['review'])
|
|
|
|
self.assertEqual('new', self.obs.requests[str(num)]['request'])
|
2014-02-26 10:59:41 +01:00
|
|
|
|
2014-06-03 18:05:05 +02:00
|
|
|
def test_rm_from_prj_2(self):
|
2014-02-27 15:54:13 +01:00
|
|
|
# Try the same with request number
|
2014-06-03 18:05:05 +02:00
|
|
|
prj = 'openSUSE:Factory:Staging:B'
|
|
|
|
pkg = 'wine'
|
|
|
|
|
|
|
|
full_name = prj + '/' + pkg
|
|
|
|
|
|
|
|
# Get rq number
|
|
|
|
num = self.api.get_request_id_for_package(prj, pkg)
|
|
|
|
|
2014-02-27 15:54:13 +01:00
|
|
|
# Delete the package
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.rm_from_prj(prj, request_id=num)
|
|
|
|
|
2014-02-27 15:54:13 +01:00
|
|
|
# Verify package is not there
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertTrue(full_name not in self.obs.links)
|
|
|
|
|
2014-02-27 15:54:13 +01:00
|
|
|
# RQ is gone
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual(None, self.api.get_request_id_for_package(prj, pkg))
|
|
|
|
self.assertEqual(None, self.api.get_package_for_request_id(prj, num))
|
|
|
|
|
2014-02-27 15:54:13 +01:00
|
|
|
# Verify that review is closed
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual('accepted', self.obs.requests[str(num)]['review'])
|
|
|
|
self.assertEqual('new', self.obs.requests[str(num)]['request'])
|
2014-02-27 15:54:13 +01:00
|
|
|
|
2014-02-26 15:24:25 +01:00
|
|
|
def test_add_sr(self):
|
|
|
|
prj = 'openSUSE:Factory:Staging:A'
|
|
|
|
rq = '123'
|
|
|
|
|
2014-02-26 16:30:03 +01:00
|
|
|
# Running it twice shouldn't change anything
|
2014-06-03 18:05:05 +02:00
|
|
|
for i in range(2):
|
2014-02-26 16:30:03 +01:00
|
|
|
# Add rq to the project
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.rq_to_prj(rq, prj)
|
2014-02-26 16:30:03 +01:00
|
|
|
# Verify that review is there
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual('new', self.obs.requests[rq]['review'])
|
|
|
|
self.assertEqual('review', self.obs.requests[rq]['request'])
|
|
|
|
self.assertEqual(self.api.get_prj_pseudometa('openSUSE:Factory:Staging:A'),
|
2017-09-26 19:03:22 +08:00
|
|
|
{'requests': [{'id': 123, 'package': 'gcc', 'author': 'Admin', 'type': 'submit'}]})
|
2014-02-26 15:24:25 +01:00
|
|
|
|
2014-02-13 14:15:14 +01:00
|
|
|
def test_create_package_container(self):
|
2014-06-03 18:05:05 +02:00
|
|
|
"""Test if the uploaded _meta is correct."""
|
2014-02-13 14:15:14 +01:00
|
|
|
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.create_package_container('openSUSE:Factory:Staging:B', 'wine')
|
2014-02-13 14:15:14 +01:00
|
|
|
self.assertEqual(httpretty.last_request().method, 'PUT')
|
|
|
|
self.assertEqual(httpretty.last_request().body, '<package name="wine"><title/><description/></package>')
|
|
|
|
self.assertEqual(httpretty.last_request().path, '/source/openSUSE:Factory:Staging:B/wine/_meta')
|
2014-02-10 13:24:49 +01:00
|
|
|
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.create_package_container('openSUSE:Factory:Staging:B', 'wine', disable_build=True)
|
2014-02-13 14:18:16 +01:00
|
|
|
self.assertEqual(httpretty.last_request().method, 'PUT')
|
2017-01-18 18:39:58 -06:00
|
|
|
self.assertEqual(httpretty.last_request().body, '<package name="wine"><title/><description/><build><disable/></build></package>')
|
2014-02-13 14:18:16 +01:00
|
|
|
self.assertEqual(httpretty.last_request().path, '/source/openSUSE:Factory:Staging:B/wine/_meta')
|
|
|
|
|
2014-02-18 23:35:45 +01:00
|
|
|
def test_review_handling(self):
|
2014-06-03 18:05:05 +02:00
|
|
|
"""Test whether accepting/creating reviews behaves correctly."""
|
2014-02-17 15:12:18 +01:00
|
|
|
|
2014-02-18 23:35:45 +01:00
|
|
|
# Add review
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.add_review('123', by_project='openSUSE:Factory:Staging:A')
|
2014-02-17 15:12:18 +01:00
|
|
|
self.assertEqual(httpretty.last_request().method, 'POST')
|
2014-02-18 23:35:45 +01:00
|
|
|
self.assertEqual(httpretty.last_request().querystring[u'cmd'], [u'addreview'])
|
|
|
|
# Try to readd, should do anything
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.add_review('123', by_project='openSUSE:Factory:Staging:A')
|
2014-02-18 23:35:45 +01:00
|
|
|
self.assertEqual(httpretty.last_request().method, 'GET')
|
|
|
|
# Accept review
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.set_review('123', 'openSUSE:Factory:Staging:A')
|
2014-02-18 23:35:45 +01:00
|
|
|
self.assertEqual(httpretty.last_request().method, 'POST')
|
|
|
|
self.assertEqual(httpretty.last_request().querystring[u'cmd'], [u'changereviewstate'])
|
|
|
|
# Try to accept it again should do anything
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.set_review('123', 'openSUSE:Factory:Staging:A')
|
2014-02-17 15:12:18 +01:00
|
|
|
self.assertEqual(httpretty.last_request().method, 'GET')
|
2014-02-18 23:35:45 +01:00
|
|
|
# But we should be able to reopen it
|
2014-06-03 18:05:05 +02:00
|
|
|
self.api.add_review('123', by_project='openSUSE:Factory:Staging:A')
|
2014-02-18 23:35:45 +01:00
|
|
|
self.assertEqual(httpretty.last_request().method, 'POST')
|
|
|
|
self.assertEqual(httpretty.last_request().querystring[u'cmd'], [u'addreview'])
|
|
|
|
|
2014-02-26 16:11:32 +01:00
|
|
|
def test_prj_from_letter(self):
|
|
|
|
|
|
|
|
# Verify it works
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual(self.api.prj_from_letter('openSUSE:Factory'), 'openSUSE:Factory')
|
|
|
|
self.assertEqual(self.api.prj_from_letter('A'), 'openSUSE:Factory:Staging:A')
|
2014-02-17 15:12:18 +01:00
|
|
|
|
2014-03-04 12:43:58 +01:00
|
|
|
def test_frozen_mtime(self):
|
2014-06-03 18:05:05 +02:00
|
|
|
"""Test frozen mtime."""
|
2014-03-03 14:54:27 +01:00
|
|
|
|
|
|
|
# Testing frozen mtime
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertTrue(self.api.days_since_last_freeze('openSUSE:Factory:Staging:A') > 8)
|
|
|
|
self.assertTrue(self.api.days_since_last_freeze('openSUSE:Factory:Staging:B') < 1)
|
2014-03-03 14:54:27 +01:00
|
|
|
|
|
|
|
# U == unfrozen
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertTrue(self.api.days_since_last_freeze('openSUSE:Factory:Staging:U') > 1000)
|
2014-03-04 10:55:55 +01:00
|
|
|
|
2014-03-04 16:32:15 +01:00
|
|
|
def test_frozen_enough(self):
|
2014-06-03 18:05:05 +02:00
|
|
|
"""Test frozen enough."""
|
2014-03-04 16:32:15 +01:00
|
|
|
|
|
|
|
# Testing frozen mtime
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual(self.api.prj_frozen_enough('openSUSE:Factory:Staging:B'), True)
|
|
|
|
self.assertEqual(self.api.prj_frozen_enough('openSUSE:Factory:Staging:A'), False)
|
2014-03-04 16:32:15 +01:00
|
|
|
|
|
|
|
# U == unfrozen
|
2014-06-03 18:05:05 +02:00
|
|
|
self.assertEqual(self.api.prj_frozen_enough('openSUSE:Factory:Staging:U'), False)
|
2014-03-04 16:32:15 +01:00
|
|
|
|
2014-03-05 10:45:35 +01:00
|
|
|
def test_move(self):
|
2014-06-03 18:05:05 +02:00
|
|
|
"""Test package movement."""
|
2014-03-05 10:45:35 +01:00
|
|
|
|
2014-06-03 18:05:05 +02:00
|
|
|
init_data = self.api.get_package_information('openSUSE:Factory:Staging:B', 'wine')
|
|
|
|
self.api.move_between_project('openSUSE:Factory:Staging:B', 333, 'openSUSE:Factory:Staging:A')
|
|
|
|
test_data = self.api.get_package_information('openSUSE:Factory:Staging:A', 'wine')
|
2014-03-05 10:45:35 +01:00
|
|
|
self.assertEqual(init_data, test_data)
|