def setUp(self): self.flavor1 = FlavorFactory() self.flavor2 = FlavorFactory(deleted=True) self.flavor3 = FlavorFactory() self.project1 = 'project1' self.project2 = 'project2' self.project3 = 'project3' self.projects = [self.project1, self.project2] self.flavor4 = FlavorFactory(public=False) self.flavor5 = FlavorFactory(public=False) self.flavor6 = FlavorFactory(public=False) self.flavor7 = FlavorFactory(public=False) self.flavor8 = FlavorFactory() self.flavoraccess1 = FlavorAccessFactory(project=self.project1, flavor=self.flavor4) self.flavoraccess2 = FlavorAccessFactory(project=self.project1, flavor=self.flavor5) self.flavoraccess3 = FlavorAccessFactory(project=self.project2, flavor=self.flavor6) self.flavoraccess4 = FlavorAccessFactory(project=self.project3, flavor=self.flavor7) self.flavoraccess5 = FlavorAccessFactory(project=self.project1, flavor=self.flavor8) self.compute_path = get_service_path(cyclades_services, 'compute', version='v2.0')
def test_not_allowed(self): self.view_path = join_urls(get_service_path( pithos_settings.pithos_services, 'pithos_ui'), 'view') self.view_url = join_urls(self.view_path, self.user, get_random_name(), get_random_name()) r = self.delete(self.view_url) self.assertEqual(r.status_code, 405) self.assertTrue('Allow' in r) self.assertEqual(sorted(r['Allow'].split(', ')), ['GET', 'HEAD']) r = self.post(self.view_url) self.assertEqual(r.status_code, 405) self.assertTrue('Allow' in r) self.assertEqual(sorted(r['Allow'].split(', ')), ['GET', 'HEAD']) r = self.put(self.view_url) self.assertEqual(r.status_code, 405) self.assertTrue('Allow' in r) self.assertEqual(sorted(r['Allow'].split(', ')), ['GET', 'HEAD']) r = self.copy(self.view_url) self.assertEqual(r.status_code, 405) self.assertTrue('Allow' in r) self.assertEqual(sorted(r['Allow'].split(', ')), ['GET', 'HEAD']) r = self.move(self.view_url) self.assertEqual(r.status_code, 405) self.assertTrue('Allow' in r) self.assertEqual(sorted(r['Allow'].split(', ')), ['GET', 'HEAD'])
def test_catch_wrong_identity_paths(self, *args): path = get_service_path(astakos_services, 'identity', 'v2.0') path = join_urls(BASE_HOST, path, 'nonexistent') response = self.client.get(path) self.assertEqual(response.status_code, 400) try: error = json.loads(response.content) except ValueError: self.assertTrue(False)
def test_catch_wrong_account_paths(self, *args): path = get_service_path(astakos_services, "account", "v1.0") path = join_urls(BASE_HOST, path, "nonexistent") response = self.client.get(path) self.assertEqual(response.status_code, 400) try: error = json.loads(response.content) except ValueError: self.assertTrue(False)
def test_catch_wrong_api_paths(self, *args): path = get_service_path(cyclades_services, 'compute', version='v2.0') response = self.client.get(join_urls(path, 'nonexistent')) self.assertEqual(response.status_code, 400) try: error = json.loads(response.content) except ValueError: self.assertTrue(False)
def test_api_version(self): """Check API version.""" path = get_service_path(cyclades_services, 'compute', version='v2.0') with astakos_user('user'): response = self.client.get(path.rstrip('/') + '/') self.assertEqual(response.status_code, 200) api_version = json.loads(response.content)['version'] self.assertEqual(api_version['id'], 'v2.0') self.assertEqual(api_version['status'], 'CURRENT')
def setUp(self): PithosAPITest.setUp(self) self.cname = self.create_container()[0] self.oname, self.odata = self.upload_object(self.cname, 'φωτογραφία.JPG')[:-1] self.view_path = join_urls(get_service_path( pithos_settings.pithos_services, 'pithos_ui'), 'view') self.view_url = join_urls(self.view_path, self.user, self.cname, self.oname) self.api_url = join_urls(self.pithos_path, self.user, self.cname, self.oname)
def setUp(self): self.volumes_path = get_service_path(cyclades_services, 'volume', version='v2.0') + '/volumes' self.snapshots_path = get_service_path(cyclades_services, 'volume', version='v2.0') + '/snapshots' # Volume types self.archip_vt = mf.VolumeTypeFactory(name="archipelago", disk_template="ext_archipelago") self.file_vt = mf.VolumeTypeFactory(name="file", disk_template="file") # Common arguments self.userid = "test_user" self.size = 1 self.kwargs = {"user_id": self.userid, } # VMs self.archip_vm = mf.VirtualMachineFactory( userid=self.userid, flavor__volume_type=self.archip_vt) self.file_vm = mf.VirtualMachineFactory( userid=self.userid, flavor__volume_type=self.file_vt)
def extend_with_root_redirects(patterns_obj, filled_services, service_type, base_path, with_slash=True): """ Append additional redirect url entries for `/` and `/<base_path>` paths. `/` redirects to `/<base_path>` and `/<base_path>` to the resolved service type url. This is used in synnefo components root urlpatterns to append sane default redirects to the chosen service url. """ service_path = get_service_path(filled_services, service_type) if with_slash: service_path = service_path.rstrip('/') + '/' root_url_entry = None if base_path and base_path != '/': # redirect slash to /<base_path>/ root_url_entry = url('^$', 'redirect_to', {'url': join_urls('/', base_path.rstrip('/'), '/')}) base_path_pattern = prefix_pattern(base_path) + '$' base_path_pattern_no_slash = prefix_pattern(base_path).rstrip('/') + '$' # redirect /<base_path> and /<base_path>/ to service_path public endpoint base_url_entry = url(base_path_pattern, 'redirect_to', {'url': service_path}) base_url_entry_no_slash = url(base_path_pattern_no_slash, 'redirect_to', {'url': service_path}) # urls order matter. Setting base_url_entry first allows us to avoid # redirect loops when base_path is empty or `/` patterns_obj += patterns('django.views.generic.simple', base_url_entry, base_url_entry_no_slash) if root_url_entry: # register root entry only for non root base_path deployments patterns_obj += patterns('django.views.generic.simple', root_url_entry)
def setUp(self): self.client = PithosTestClient() # Override default block size to spead up tests pithos_settings.BACKEND_BLOCK_SIZE = TEST_BLOCK_SIZE pithos_settings.BACKEND_HASH_ALGORITHM = TEST_HASH_ALGORITHM self.user = '******' self.pithos_path = join_urls(get_service_path( pithos_settings.pithos_services, 'object-store')) # patch astakosclient.AstakosClient.validate_token mock_validate_token = self.create_patch( 'astakosclient.AstakosClient.validate_token') mock_validate_token.return_value = { 'access': { 'user': {'id': smart_unicode(self.user, encoding='utf-8')}}} # patch astakosclient.AstakosClient.get_token mock_get_token = self.create_patch( 'astakosclient.AstakosClient.get_token') mock_get_token.return_value = {'access_token': 'valid_token'} # patch astakosclient.AstakosClient.api_oa2_auth mock_api_oauth2_auth = self.create_patch( 'astakosclient.AstakosClient.oauth2_url', new_callable=PropertyMock) mock_api_oauth2_auth.return_value = '/astakos/oauth2/' mock_service_get_quotas = self.create_patch( 'astakosclient.AstakosClient.service_get_quotas') mock_service_get_quotas.return_value = { self.user: { "system": { "pithos.diskspace": { "usage": 0, "limit": 1073741824, # 1GB "pending": 0}}}}
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import json import urllib from mock import patch from functools import wraps from copy import deepcopy from decimal import Decimal from snf_django.utils.testing import BaseAPITest from synnefo.cyclades_settings import cyclades_services from synnefo.lib.services import get_service_path from synnefo.lib import join_urls PLANKTON_URL = get_service_path(cyclades_services, 'image', version='v1.0') IMAGES_URL = join_urls(PLANKTON_URL, "images/") def assert_backend_closed(func): @wraps(func) def wrapper(self, backend): result = func(self, backend) if backend.called is True: backend.return_value.close.assert_called_once_with() return result return wrapper @patch("synnefo.plankton.backend.get_pithos_backend")
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from snf_django.utils.testing import BaseAPITest import json from synnefo.cyclades_settings import cyclades_services from synnefo.lib.services import get_service_path from synnefo.lib import join_urls from ipaddr import IPv4Network import json import synnefo.db.models_factory as mf NETWORK_URL = get_service_path(cyclades_services, 'network', version='v2.0') SUBNETS_URL = join_urls(NETWORK_URL, "subnets/") class SubnetTest(BaseAPITest): def test_list_subnets(self): """Test list subnets without data""" response = self.get(SUBNETS_URL) self.assertSuccess(response) subnets = json.loads(response.content) self.assertEqual(subnets, {'subnets': []}) def test_list_subnets_data(self): """Test list subnets with data""" test_net = mf.NetworkFactory() test_subnet_ipv4 = mf.IPv4SubnetFactory(network=test_net)
# This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import json from snf_django.utils.testing import BaseAPITest from synnefo.lib.services import get_service_path from synnefo.cyclades_settings import cyclades_services from synnefo.lib import join_urls COMPUTE_URL = get_service_path(cyclades_services, 'compute', version='v2.0') EXTENSIONS_URL = join_urls(COMPUTE_URL, "extensions/") class ExtensionsAPITest(BaseAPITest): def test_list(self): response = self.get(EXTENSIONS_URL, "user") self.assertSuccess(response) extensions = json.loads(response.content)["extensions"] self.assertEqual(extensions, []) def test_get(self): response = self.get(join_urls(EXTENSIONS_URL, "SNF"), "user") self.assertEqual(response.status_code, 404) response = self.get(join_urls(EXTENSIONS_URL, "SNF_asfas_da"), "user") self.assertEqual(response.status_code, 404)
def __init__(self, *args, **kwargs): super(ComputeAPITest, self).__init__(*args, **kwargs) self.compute_path = get_service_path(cyclades_services, 'compute', version='v2.0')
from synnefo.db.models import (Flavor, VirtualMachine, VirtualMachineMetadata, Network, BackendNetwork, NetworkInterface, BridgePoolTable, MacPrefixPoolTable, Backend) from synnefo.db.pools import EmptyPool from snf_django.lib.astakos import get_user from synnefo.plankton.utils import image_backend from synnefo.settings import MAX_CIDR_BLOCK from synnefo.cyclades_settings import cyclades_services, BASE_HOST from synnefo.lib.services import get_service_path from synnefo.lib import join_urls COMPUTE_URL = \ join_urls(BASE_HOST, get_service_path(cyclades_services, "compute", version="v2.0")) SERVERS_URL = join_urls(COMPUTE_URL, "servers/") NETWORKS_URL = join_urls(COMPUTE_URL, "networks/") FLAVORS_URL = join_urls(COMPUTE_URL, "flavors/") IMAGES_URL = join_urls(COMPUTE_URL, "images/") PLANKTON_URL = \ join_urls(BASE_HOST, get_service_path(cyclades_services, "image", version="v1.0")) IMAGES_PLANKTON_URL = join_urls(PLANKTON_URL, "images/") log = getLogger('synnefo.api') def random_password(): """Generates a random password
def extend_endpoint_with_slash(patterns_obj, filled_services, service_type, version=None): path = get_service_path(filled_services, service_type, version) extend_path_with_slash(patterns_obj, path)
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import json from snf_django.lib.api import faults from snf_django.utils.testing import BaseAPITest from synnefo.lib.services import get_service_path from synnefo.cyclades_settings import cyclades_services from synnefo.lib import join_urls from mock import patch from functools import wraps compute_path = get_service_path(cyclades_services, 'compute', version='v2.0') IMAGES_URL = join_urls(compute_path, "images/") def assert_backend_closed(func): """Decorator for ensuring that PlanktonBackend is returned to pool.""" @wraps(func) def wrapper(self, backend): result = func(self, backend) if backend.called is True: backend.return_value.close.asssert_called return result return wrapper @patch('synnefo.plankton.backend.PlanktonBackend')
import sys import json from django.conf import settings from django.utils.importlib import import_module from django.test.utils import override_settings from mock import patch, Mock from snf_django.utils.testing import BaseAPITest, mocked_quotaholder from synnefo.db.models_factory import (VolumeFactory, VolumeTypeFactory, VirtualMachineFactory) from synnefo.lib.services import get_service_path from synnefo.cyclades_settings import cyclades_services from synnefo.lib import join_urls from copy import deepcopy VOLUME_URL = get_service_path(cyclades_services, 'volume', version='v2.0') VOLUMES_URL = join_urls(VOLUME_URL, "volumes") SNAPSHOTS_URL = join_urls(VOLUME_URL, "snapshots") @patch("synnefo.logic.rapi_pool.GanetiRapiClient") class VolumeAPITest(BaseAPITest): @override_settings(CYCLADES_DETACHABLE_DISK_TEMPLATES=("ext_vlmc",)) def test_create_volume(self, mrapi): vm = VirtualMachineFactory( operstate="ACTIVE", flavor__volume_type__disk_template="ext_vlmc") vt = VolumeTypeFactory(disk_template="ext_vlmc") user = vm.userid _data = {"display_name": "test_vol", "size": 2,
from snf_django.lib.api import faults from synnefo.db.models import (Flavor, VirtualMachine, VirtualMachineMetadata, Network, NetworkInterface, SecurityGroup, BridgePoolTable, MacPrefixPoolTable, IPAddress, IPPoolTable) from synnefo.plankton.backend import PlanktonBackend from synnefo.webproject.memory_cache import MemoryCache from synnefo.cyclades_settings import cyclades_services, BASE_HOST from synnefo.lib.services import get_service_path from synnefo.lib import join_urls COMPUTE_URL = \ join_urls(BASE_HOST, get_service_path(cyclades_services, "compute", version="v2.0")) SERVERS_URL = join_urls(COMPUTE_URL, "servers/") FLAVORS_URL = join_urls(COMPUTE_URL, "flavors/") IMAGES_URL = join_urls(COMPUTE_URL, "images/") PLANKTON_URL = \ join_urls(BASE_HOST, get_service_path(cyclades_services, "image", version="v1.0")) IMAGES_PLANKTON_URL = join_urls(PLANKTON_URL, "images/") NETWORK_URL = \ join_urls(BASE_HOST, get_service_path(cyclades_services, "network", version="v2.0")) NETWORKS_URL = join_urls(NETWORK_URL, "networks/") PORTS_URL = join_urls(NETWORK_URL, "ports/") SUBNETS_URL = join_urls(NETWORK_URL, "subnets/") FLOATING_IPS_URL = join_urls(NETWORK_URL, "floatingips/")
def setUp(self, *args, **kwargs): super(VMAPITest, self).setUp(*args, **kwargs) self.api_path = get_service_path(cyclades_services, 'vmapi', version='v1.0')
def setUp(self, *args, **kwargs): super(PlanktonAPITest, self).setUp(*args, **kwargs) self.api_path = get_service_path(cyclades_services, 'image', version='v1.0')
# along with this program. If not, see <http://www.gnu.org/licenses/>. from django.utils import simplejson as json from django.conf import settings from snf_django.utils.testing import BaseAPITest, mocked_quotaholder, \ with_settings from synnefo.db.models import IPAddress, Network, Subnet, IPPoolTable from synnefo.db import models_factory as mf from mock import patch, Mock from synnefo.cyclades_settings import cyclades_services from synnefo.lib.services import get_service_path from synnefo.lib import join_urls network_path = get_service_path(cyclades_services, "network", version="v2.0") URL = join_urls(network_path, "floatingips") NETWORKS_URL = join_urls(network_path, "networks") SERVERS_URL = join_urls(network_path, "servers") floating_ips = IPAddress.objects.filter(floating_ip=True) class FloatingIPAPITest(BaseAPITest): def setUp(self): self.pool = mf.NetworkWithSubnetFactory(floating_ip_pool=True, public=True, subnet__cidr="192.168.2.0/24", subnet__gateway="192.168.2.1") def test_no_floating_ip(self):
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import json from mock import patch, Mock from snf_django.utils.testing import BaseAPITest, mocked_quotaholder from synnefo.db.models_factory import (VolumeFactory, VolumeTypeFactory, VirtualMachineFactory) from synnefo.lib.services import get_service_path from synnefo.cyclades_settings import cyclades_services from synnefo.lib import join_urls from copy import deepcopy VOLUME_URL = get_service_path(cyclades_services, 'volume', version='v2.0') VOLUMES_URL = join_urls(VOLUME_URL, "volumes") @patch("synnefo.logic.rapi_pool.GanetiRapiClient") class VolumeAPITest(BaseAPITest): def test_create_volume(self, mrapi): vm = VirtualMachineFactory( operstate="ACTIVE", flavor__volume_type__disk_template="ext_vlmc") user = vm.userid _data = {"display_name": "test_vol", "size": 2, "server_id": vm.id} # Test Success mrapi().ModifyInstance.return_value = 42 with mocked_quotaholder(): r = self.post(VOLUMES_URL, user, json.dumps({"volume": _data}),
# # The views and conclusions contained in the software and # documentation are those of the authors and should not be # interpreted as representing official policies, either expressed # or implied, of GRNET S.A.i from django.conf import settings from snf_django.utils.testing import BaseAPITest, override_settings from django.utils import simplejson as json from synnefo.cyclades_settings import cyclades_services from synnefo.lib.services import get_service_path from synnefo.lib import join_urls from mock import patch import synnefo.db.models_factory as dbmf NETWORK_URL = get_service_path(cyclades_services, 'network', version='v2.0') PORTS_URL = join_urls(NETWORK_URL, "ports/") class PortTest(BaseAPITest): def test_get_ports(self): url = join_urls(PORTS_URL) response = self.get(url) self.assertEqual(response.status_code, 200) ports = json.loads(response.content) self.assertEqual(ports, {"ports": []}) def test_get_port_unfound(self): url = join_urls(PORTS_URL, "123") response = self.get(url) self.assertEqual(response.status_code, 404)
server_id = int(server_id) except (TypeError, ValueError): raise faults.BadRequest("Invalid server id: %s" % server_id) try: return get_vm(server_id, user_id, for_update=for_update, non_deleted=non_deleted, non_suspended=True) except faults.ItemNotFound: raise exception("Server %s not found" % server_id) VOLUME_URL = \ join_urls(BASE_HOST, get_service_path(cyclades_services, "volume", version="v2.0")) VOLUMES_URL = join_urls(VOLUME_URL, "volumes/") SNAPSHOTS_URL = join_urls(VOLUME_URL, "snapshots/") def volume_to_links(volume_id): href = join_urls(VOLUMES_URL, str(volume_id)) return [{"rel": rel, "href": href} for rel in ("self", "bookmark")] def snapshot_to_links(snapshot_id): href = join_urls(SNAPSHOTS_URL, str(snapshot_id)) return [{"rel": rel, "href": href} for rel in ("self", "bookmark")]
VirtualMachineMetadata, Network, NetworkInterface, SecurityGroup, BridgePoolTable, MacPrefixPoolTable, IPAddress, IPPoolTable, ) from synnefo.plankton.utils import image_backend from synnefo.cyclades_settings import cyclades_services, BASE_HOST from synnefo.lib.services import get_service_path from synnefo.lib import join_urls COMPUTE_URL = join_urls(BASE_HOST, get_service_path(cyclades_services, "compute", version="v2.0")) SERVERS_URL = join_urls(COMPUTE_URL, "servers/") FLAVORS_URL = join_urls(COMPUTE_URL, "flavors/") IMAGES_URL = join_urls(COMPUTE_URL, "images/") PLANKTON_URL = join_urls(BASE_HOST, get_service_path(cyclades_services, "image", version="v1.0")) IMAGES_PLANKTON_URL = join_urls(PLANKTON_URL, "images/") NETWORK_URL = join_urls(BASE_HOST, get_service_path(cyclades_services, "network", version="v2.0")) NETWORKS_URL = join_urls(NETWORK_URL, "networks/") PORTS_URL = join_urls(NETWORK_URL, "ports/") SUBNETS_URL = join_urls(NETWORK_URL, "subnets/") FLOATING_IPS_URL = join_urls(NETWORK_URL, "floatingips/") PITHOSMAP_PREFIX = "pithosmap://" log = getLogger("synnefo.api")
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from snf_django.utils.testing import BaseAPITest, override_settings from django.utils import simplejson as json from synnefo.cyclades_settings import cyclades_services from synnefo.lib.services import get_service_path from synnefo.lib import join_urls import synnefo.db.models_factory as dbmf from synnefo.db.models import Network, QuotaHolderSerial from django.conf import settings NETWORK_URL = get_service_path(cyclades_services, "network", version="v2.0") NETWORKS_URL = join_urls(NETWORK_URL, "networks/") class NetworkTest(BaseAPITest): def test_list_networks(self): response = self.get(NETWORKS_URL) self.assertSuccess(response) networks = json.loads(response.content) self.assertEqual(networks, {"networks": []}) def test_invalid_create(self): """Test invalid flavor""" request = {"network": {}} response = self.post(NETWORKS_URL, "user1", params=json.dumps(request)) self.assertBadRequest(response)
def setUp(self, *args, **kwargs): super(ComputeAPITest, self).setUp(*args, **kwargs) self.compute_path = get_service_path(cyclades_services, 'compute', version='v2.0')
def setUp(self): self.flavor1 = FlavorFactory() self.flavor2 = FlavorFactory(deleted=True) self.flavor3 = FlavorFactory() self.compute_path = get_service_path(cyclades_services, 'compute', version='v2.0')
# # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import json from snf_django.lib.api import faults from snf_django.utils.testing import BaseAPITest from synnefo.lib.services import get_service_path from synnefo.cyclades_settings import cyclades_services from synnefo.lib import join_urls from mock import patch from functools import wraps compute_path = get_service_path(cyclades_services, 'compute', version='v2.0') IMAGES_URL = join_urls(compute_path, "images/") def assert_backend_closed(func): """Decorator for ensuring that PlanktonBackend is returned to pool.""" @wraps(func) def wrapper(self, backend): result = func(self, backend) if backend.called is True: backend.return_value.close.asssert_called return result return wrapper
from django.utils import simplejson as json from django.conf import settings from snf_django.utils.testing import BaseAPITest, mocked_quotaholder, \ with_settings from synnefo.db.models import IPAddress, Network, Subnet, IPPoolTable from synnefo.db import models_factory as mf from mock import patch, Mock from synnefo.cyclades_settings import cyclades_services from synnefo.lib.services import get_service_path from synnefo.lib import join_urls network_path = get_service_path(cyclades_services, "network", version="v2.0") URL = join_urls(network_path, "floatingips") NETWORKS_URL = join_urls(network_path, "networks") SERVERS_URL = join_urls(network_path, "servers") floating_ips = IPAddress.objects.filter(floating_ip=True) class FloatingIPAPITest(BaseAPITest): def setUp(self): self.pool = mf.NetworkWithSubnetFactory(floating_ip_pool=True, public=True, subnet__cidr="192.168.2.0/24", subnet__gateway="192.168.2.1")
# You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import json import urllib from mock import patch from functools import wraps from copy import deepcopy from decimal import Decimal from snf_django.utils.testing import BaseAPITest from synnefo.cyclades_settings import cyclades_services from synnefo.lib.services import get_service_path from synnefo.lib import join_urls PLANKTON_URL = get_service_path(cyclades_services, 'image', version='v1.0') IMAGES_URL = join_urls(PLANKTON_URL, "images/") def assert_backend_closed(func): @wraps(func) def wrapper(self, backend): result = func(self, backend) if backend.called is True: backend.return_value.close.assert_called_once_with() return result return wrapper @patch("synnefo.plankton.backend.get_pithos_backend") class PlanktonTest(BaseAPITest):
def get_server(user_id, server_id, for_update=False, non_deleted=False, exception=faults.ItemNotFound): try: server_id = int(server_id) except (TypeError, ValueError): raise faults.BadRequest("Invalid server id: %s" % server_id) try: return get_vm(server_id, user_id, for_update=for_update, non_deleted=non_deleted, non_suspended=True) except faults.ItemNotFound: raise exception("Server %s not found" % server_id) VOLUME_URL = \ join_urls(BASE_HOST, get_service_path(cyclades_services, "volume", version="v2.0")) VOLUMES_URL = join_urls(VOLUME_URL, "volumes/") SNAPSHOTS_URL = join_urls(VOLUME_URL, "snapshots/") def volume_to_links(volume_id): href = join_urls(VOLUMES_URL, str(volume_id)) return [{"rel": rel, "href": href} for rel in ("self", "bookmark")] def snapshot_to_links(snapshot_id): href = join_urls(SNAPSHOTS_URL, str(snapshot_id)) return [{"rel": rel, "href": href} for rel in ("self", "bookmark")]
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # The views and conclusions contained in the software and # documentation are those of the authors and should not be # interpreted as representing official policies, either expressed # or implied, of GRNET S.A. import json from snf_django.utils.testing import BaseAPITest from synnefo.lib.services import get_service_path from synnefo.cyclades_settings import cyclades_services from synnefo.lib import join_urls COMPUTE_URL = get_service_path(cyclades_services, 'compute', version='v2.0') EXTENSIONS_URL = join_urls(COMPUTE_URL, "extensions/") class ExtensionsAPITest(BaseAPITest): def test_list(self): response = self.get(EXTENSIONS_URL, "user") self.assertSuccess(response) extensions = json.loads(response.content)["extensions"] self.assertEqual(extensions, []) def test_get(self): response = self.get(join_urls(EXTENSIONS_URL, "SNF"), "user") self.assertEqual(response.status_code, 404) response = self.get(join_urls(EXTENSIONS_URL, "SNF_asfas_da"), "user") self.assertEqual(response.status_code, 404)