2014-02-04 11:23:23 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
#
|
|
|
|
# (C) 2014 tchvatal@suse.cz, openSUSE.org
|
|
|
|
# Distribute under GPLv2 or later
|
|
|
|
|
2014-02-04 14:04:46 +01:00
|
|
|
import os
|
2014-02-04 11:23:23 +01:00
|
|
|
import contextlib
|
|
|
|
import unittest
|
2014-02-04 14:04:46 +01:00
|
|
|
import httpretty
|
2014-02-04 11:23:23 +01:00
|
|
|
|
2014-02-04 14:04:46 +01:00
|
|
|
import oscs
|
|
|
|
import osc
|
2014-02-04 11:23:23 +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 _get_fixtures_dir(self):
|
|
|
|
"""
|
|
|
|
Return path for fixtures
|
|
|
|
"""
|
|
|
|
return os.path.join(os.getcwd(), 'tests/fixtures')
|
|
|
|
|
|
|
|
def _register_pretty_url_get(self, url, filename):
|
|
|
|
"""
|
|
|
|
Register specified url with specific filename in fixtures
|
2014-02-04 17:16:37 +01:00
|
|
|
:param url: url address to "open"
|
|
|
|
:param filename: name of the fixtures file
|
2014-02-04 14:04:46 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
response = open(os.path.join(self._get_fixtures_dir(), filename), 'r')
|
|
|
|
content = response.read()
|
|
|
|
response.close()
|
|
|
|
|
|
|
|
httpretty.register_uri(httpretty.GET,
|
|
|
|
url,
|
|
|
|
body=content)
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Initialize the configuration so the osc is happy
|
|
|
|
"""
|
|
|
|
|
|
|
|
oscrc = os.path.join(self._get_fixtures_dir(), 'oscrc')
|
|
|
|
osc.core.conf.get_config(override_conffile=oscrc,
|
|
|
|
override_no_keyring=True,
|
|
|
|
override_no_gnome_keyring=True)
|
|
|
|
os.environ['OSC_CONFIG'] = oscrc
|
2014-02-04 11:23:23 +01:00
|
|
|
|
2014-02-04 14:04:46 +01:00
|
|
|
@httpretty.activate
|
2014-02-04 11:23:23 +01:00
|
|
|
def test_list_projects(self):
|
|
|
|
"""
|
|
|
|
List projects and their content
|
|
|
|
"""
|
|
|
|
prjlist = [
|
|
|
|
'openSUSE:Factory:Staging:A',
|
|
|
|
'openSUSE:Factory:Staging:B',
|
|
|
|
'openSUSE:Factory:Staging:C',
|
|
|
|
'openSUSE:Factory:Staging:D'
|
|
|
|
]
|
|
|
|
|
2014-02-04 14:04:46 +01:00
|
|
|
# Initiate the pretty overrides
|
|
|
|
self._register_pretty_url_get('http://localhost/search/project/id?match=starts-with(@name,\'openSUSE:Factory:Staging:\')',
|
|
|
|
'staging-project-list.xml')
|
2014-02-04 11:23:23 +01:00
|
|
|
|
2014-02-04 14:04:46 +01:00
|
|
|
# Ensure the output is equal to what we expect
|
|
|
|
self.assertEqual(prjlist,
|
|
|
|
oscs.list_staging_projects('http://localhost'))
|