Merge "Adding Inventory class."
This commit is contained in:
commit
b7a527e269
@ -12,8 +12,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Tests for `cratonclient` module."""
|
||||
import mock
|
||||
|
||||
from cratonclient.tests import base
|
||||
from cratonclient.v1 import client
|
||||
|
||||
|
||||
class TestCratonclient(base.TestCase):
|
||||
@ -22,3 +24,13 @@ class TestCratonclient(base.TestCase):
|
||||
def test_something(self):
|
||||
"""Do nothing."""
|
||||
pass
|
||||
|
||||
@mock.patch('cratonclient.v1.inventory.Inventory')
|
||||
def test_client_creates_inventory(self, mock_inventory):
|
||||
"""Verify that Craton client creates Inventory."""
|
||||
session = mock.Mock()
|
||||
url = 'https://10.1.1.8080'
|
||||
region_id = 1
|
||||
craton = client.Client(session, url)
|
||||
craton.inventory(region_id)
|
||||
mock_inventory.assert_called_once_with(session, url + '/v1', region_id)
|
||||
|
31
cratonclient/tests/unit/test_inventory.py
Normal file
31
cratonclient/tests/unit/test_inventory.py
Normal file
@ -0,0 +1,31 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Tests for `cratonclient.v1.inventory` module."""
|
||||
|
||||
import mock
|
||||
|
||||
from cratonclient.tests import base
|
||||
from cratonclient.v1 import inventory
|
||||
|
||||
|
||||
class TestInventory(base.TestCase):
|
||||
"""Test our craton inventory api class."""
|
||||
|
||||
@mock.patch('cratonclient.v1.hosts.HostManager')
|
||||
def test_inventory_creates_host_manager(self, mock_hostmanager):
|
||||
"""Verify Inventory class creates HostManager."""
|
||||
session = mock.Mock()
|
||||
url = 'https://10.1.1.0:8080/'
|
||||
region_id = 1,
|
||||
inventory.Inventory(session, url, region_id)
|
||||
mock_hostmanager.assert_called_once_with(session, url)
|
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
"""Top-level client for version 1 of Craton's API."""
|
||||
from cratonclient.v1 import hosts
|
||||
from cratonclient.v1 import inventory
|
||||
from cratonclient.v1 import regions
|
||||
|
||||
|
||||
@ -37,6 +38,13 @@ class Client(object):
|
||||
self._url += '/v1'
|
||||
|
||||
manager_kwargs = {'session': self._session, 'url': url}
|
||||
|
||||
# TODO(cmspence):remove self.hosts
|
||||
self.hosts = hosts.HostManager(**manager_kwargs)
|
||||
self.regions = regions.RegionManager(**manager_kwargs)
|
||||
# TODO(cmspence):self.projects, self.users
|
||||
|
||||
def inventory(self, region_id):
|
||||
"""Retrieve inventory for a given region."""
|
||||
return inventory.Inventory(self._session,
|
||||
self._url,
|
||||
region_id)
|
||||
|
35
cratonclient/v1/inventory.py
Normal file
35
cratonclient/v1/inventory.py
Normal file
@ -0,0 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Top-level client for version 1 of Craton's API."""
|
||||
|
||||
from cratonclient.v1 import hosts
|
||||
|
||||
|
||||
class Inventory(object):
|
||||
"""Representation of the viewable inventory."""
|
||||
|
||||
def __init__(self, session, url, region_id):
|
||||
"""Initialize our client object with our session and url.
|
||||
|
||||
:param session:
|
||||
Initialized Session object.
|
||||
:type session:
|
||||
cratonclient.session.Session
|
||||
:param str url:
|
||||
The URL that points us to the craton instance. For example,
|
||||
'https://10.1.1.0:8080/'.
|
||||
"""
|
||||
# TODO(cmspence): self.region = self.regions.get(region=region_id)
|
||||
self.hosts = hosts.HostManager(session, url)
|
||||
# TODO(cmspence): self.users, self.projects, self.workflows
|
Loading…
x
Reference in New Issue
Block a user