# Path: rpaas/hc.py
# class Dumb(object):
# class HCAPI(object):
# class HCCreationError(Exception):
# class URLCreationError(Exception):
#     def __init__(self, *args, **kwargs):
#     def create(self, name):
#     def destroy(self, name):
#     def add_url(self, name, url):
#     def remove_url(self, name, url):
#     def __init__(self, storage, url, user=None, password=None,
#                  hc_format=None, expected_string="WORKING"):
#     def _issue_request(self, method, path, data=None):
#     def create(self, name):
#     def destroy(self, name):
#     def add_url(self, name, url):
#     def remove_url(self, name, url):
# 
# Path: rpaas/storage.py
# class InstanceNotFoundError(Exception):
# class PlanNotFoundError(Exception):
# class FlavorNotFoundError(Exception):
# class DuplicateError(Exception):
# class MongoDBStorage(storage.MongoDBStorage):
#     def store_hc(self, hc):
#     def retrieve_hc(self, name):
#     def remove_hc(self, name):
#     def store_healing(self, instance, machine):
#     def update_healing(self, id, status):
#     def list_healings(self, quantity):
#     def store_task(self, name):
#     def remove_task(self, query):
#     def update_task(self, name, task_id_or_spec):
#     def find_task(self, query):
#     def store_instance_metadata(self, instance_name, **data):
#     def find_instance_metadata(self, instance_name):
#     def find_host_id(self, name):
#     def remove_instance_metadata(self, instance_name):
#     def store_plan(self, plan):
#     def update_plan(self, name, description=None, config=None):
#     def delete_plan(self, name):
#     def find_plan(self, name):
#     def list_plans(self):
#     def _plan_from_dict(self, dict):
#     def store_flavor(self, flavor):
#     def update_flavor(self, name, description=None, config=None):
#     def delete_flavor(self, name):
#     def find_flavor(self, name):
#     def list_flavors(self):
#     def _flavor_from_dict(self, dict):
#     def store_binding(self, name, app_host, app_host_only=False):
#     def remove_binding(self, name):
#     def remove_root_binding(self, name, remove_root_binding_path):
#     def find_binding(self, name):
#     def replace_binding_path(self, name, path, destination=None, content=None, https_only=False):
#     def delete_binding_path(self, name, path):
#     def set_team_quota(self, teamname, quota):
#     def find_team_quota(self, teamname):
#     def _find_team_quota(self, teamname):
#     def increment_quota(self, teamname, prev_used, servicename):
#     def decrement_quota(self, servicename):
#     def store_le_certificate(self, name, domain):
#     def remove_le_certificate(self, name, domain):
#     def find_le_certificates(self, query):


import json
import unittest
import os
import mock
from requests import auth
from rpaas import hc, storage
        hc_api = hc.HCAPI(self.storage, "http://localhost/")
        got_resp = hc_api._issue_request("GET", "/url", data={"abc": 1})
        self.assertEqual(resp, got_resp)
        request.assert_called_with("GET", "http://localhost/url",
                                   data={"abc": 1})

    @mock.patch("requests.request")
    def test_issue_authenticated_request(self, request):
        request.return_value = resp = mock.Mock()
        hc_api = hc.HCAPI(self.storage, "http://localhost/",
                          user="zabbix", password="zabbix123")
        got_resp = hc_api._issue_request("GET", "/url", data={"abc": 1})
        self.assertEqual(resp, got_resp)
        call = request.call_args_list[0]
        self.assertEqual(("GET", "http://localhost/url"), call[0])
        self.assertEqual({"abc": 1}, call[1]["data"])
        req_auth = call[1]["auth"]
        self.assertIsInstance(req_auth, auth.HTTPBasicAuth)
        self.assertEqual("zabbix", req_auth.username)
        self.assertEqual("zabbix123", req_auth.password)

    @mock.patch("uuid.uuid4")
    def test_create(self, uuid4):
        self.issue_request.return_value = mock.Mock(status_code=201)
        uuid = mock.Mock(hex="abc123")
        uuid4.return_value = uuid
        self.hc.create("myinstance")
        self.issue_request.assert_called_with("POST", "/resources",
                                              data={"name":
                                                    "rpaas_myinstance_abc123"})

# Path: rpaas/hc.py
# class Dumb(object):
# class HCAPI(object):
# class HCCreationError(Exception):
# class URLCreationError(Exception):
#     def __init__(self, *args, **kwargs):
#     def create(self, name):
#     def destroy(self, name):
#     def add_url(self, name, url):
#     def remove_url(self, name, url):
#     def __init__(self, storage, url, user=None, password=None,
#                  hc_format=None, expected_string="WORKING"):
#     def _issue_request(self, method, path, data=None):
#     def create(self, name):
#     def destroy(self, name):
#     def add_url(self, name, url):
#     def remove_url(self, name, url):
# 
# Path: rpaas/storage.py
# class InstanceNotFoundError(Exception):
# class PlanNotFoundError(Exception):
# class FlavorNotFoundError(Exception):
# class DuplicateError(Exception):
# class MongoDBStorage(storage.MongoDBStorage):
#     def store_hc(self, hc):
#     def retrieve_hc(self, name):
#     def remove_hc(self, name):
#     def store_healing(self, instance, machine):
#     def update_healing(self, id, status):
#     def list_healings(self, quantity):
#     def store_task(self, name):
#     def remove_task(self, query):
#     def update_task(self, name, task_id_or_spec):
#     def find_task(self, query):
#     def store_instance_metadata(self, instance_name, **data):
#     def find_instance_metadata(self, instance_name):
#     def find_host_id(self, name):
#     def remove_instance_metadata(self, instance_name):
#     def store_plan(self, plan):
#     def update_plan(self, name, description=None, config=None):
#     def delete_plan(self, name):
#     def find_plan(self, name):
#     def list_plans(self):
#     def _plan_from_dict(self, dict):
#     def store_flavor(self, flavor):
#     def update_flavor(self, name, description=None, config=None):
#     def delete_flavor(self, name):
#     def find_flavor(self, name):
#     def list_flavors(self):
#     def _flavor_from_dict(self, dict):
#     def store_binding(self, name, app_host, app_host_only=False):
#     def remove_binding(self, name):
#     def remove_root_binding(self, name, remove_root_binding_path):
#     def find_binding(self, name):
#     def replace_binding_path(self, name, path, destination=None, content=None, https_only=False):
#     def delete_binding_path(self, name, path):
#     def set_team_quota(self, teamname, quota):
#     def find_team_quota(self, teamname):
#     def _find_team_quota(self, teamname):
#     def increment_quota(self, teamname, prev_used, servicename):
#     def decrement_quota(self, servicename):
#     def store_le_certificate(self, name, domain):
#     def remove_le_certificate(self, name, domain):
#     def find_le_certificates(self, query):


# Path: tests/test_hc.py
import json
import unittest
import os
import mock
from requests import auth
from rpaas import hc, storage

        hc_api = hc.HCAPI(self.storage, "http://localhost/")
        got_resp = hc_api._issue_request("GET", "/url", data={"abc": 1})
        self.assertEqual(resp, got_resp)
        request.assert_called_with("GET", "http://localhost/url",
                                   data={"abc": 1})

    @mock.patch("requests.request")
    def test_issue_authenticated_request(self, request):
        request.return_value = resp = mock.Mock()
        hc_api = hc.HCAPI(self.storage, "http://localhost/",
                          user="zabbix", password="zabbix123")
        got_resp = hc_api._issue_request("GET", "/url", data={"abc": 1})
        self.assertEqual(resp, got_resp)
        call = request.call_args_list[0]
        self.assertEqual(("GET", "http://localhost/url"), call[0])
        self.assertEqual({"abc": 1}, call[1]["data"])
        req_auth = call[1]["auth"]
        self.assertIsInstance(req_auth, auth.HTTPBasicAuth)
        self.assertEqual("zabbix", req_auth.username)
        self.assertEqual("zabbix123", req_auth.password)

    @mock.patch("uuid.uuid4")
    def test_create(self, uuid4):
        self.issue_request.return_value = mock.Mock(status_code=201)
        uuid = mock.Mock(hex="abc123")
        uuid4.return_value = uuid
        self.hc.create("myinstance")
        self.issue_request.assert_called_with("POST", "/resources",
                                              data={"name":
                                                    "rpaas_myinstance_abc123"})

        hc = self.storage.retrieve_hc("myinstance")