Skip to content

Commit

Permalink
Merge pull request #16 from UpCloudLtd/0.3.4-devel
Browse files Browse the repository at this point in the history
0.3.4 devel
  • Loading branch information
Elias Nygren authored Jun 21, 2016
2 parents a7ef273 + cc7cb35 commit 2ee612b
Show file tree
Hide file tree
Showing 10 changed files with 974 additions and 858 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true


[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest==2.6.4
py==1.4.26
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
future==0.14.3
mock==1.0.1
py==1.4.26
pytest==2.6.4
requests==2.6.0
responses==0.3.0
six==1.9.0
Expand Down
4 changes: 1 addition & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='upcloud-api',
version='0.3.3',
version='0.3.4',
description='UpCloud API Client',
author='Elias Nygren',
author_email='elias.nygren@upcloud.com',
Expand All @@ -17,8 +17,6 @@
install_requires=[
'future==0.14.3',
'mock==1.0.1',
'py==1.4.26',
'pytest==2.6.4',
'requests==2.6.0',
'responses==0.3.0',
'six==1.9.0',
Expand Down
250 changes: 125 additions & 125 deletions test/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,139 +10,139 @@
import json, pytest, responses

class TestServer(object):
@responses.activate
def test_get_server(self, manager):
data = Mock.mock_get("server/00798b85-efdc-41ca-8021-f6ef457b8531")
server = manager.get_server("00798b85-efdc-41ca-8021-f6ef457b8531")

assert type(server).__name__ == "Server"
assert server.uuid == "00798b85-efdc-41ca-8021-f6ef457b8531"

@responses.activate
def test_get_unpopulated_servers(self, manager):
data = Mock.mock_get("server")
servers = manager.get_servers()
@responses.activate
def test_get_server(self, manager):
data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')

assert type(server).__name__ == 'Server'
assert server.uuid == '00798b85-efdc-41ca-8021-f6ef457b8531'

@responses.activate
def test_get_unpopulated_servers(self, manager):
data = Mock.mock_get('server')
servers = manager.get_servers()

for server in servers:
assert type(server).__name__ == "Server"

@responses.activate
def test_get_populated_servers(self, manager):
data = Mock.mock_get("server")
data = Mock.mock_get("server/00798b85-efdc-41ca-8021-f6ef457b8531")
data = Mock.mock_get("server/009d64ef-31d1-4684-a26b-c86c955cbf46")
servers = manager.get_servers(populate=True)
for server in servers:
assert type(server).__name__ == 'Server'

@responses.activate
def test_get_populated_servers(self, manager):
data = Mock.mock_get('server')
data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
data = Mock.mock_get('server/009d64ef-31d1-4684-a26b-c86c955cbf46')
servers = manager.get_servers(populate=True)

for server in servers:
assert type(server).__name__ == "Server"
for server in servers:
assert type(server).__name__ == 'Server'

@responses.activate
def test_start_server(self, manager):
data = Mock.mock_get("server/009d64ef-31d1-4684-a26b-c86c955cbf46")
server = manager.get_server("009d64ef-31d1-4684-a26b-c86c955cbf46")
@responses.activate
def test_start_server(self, manager):
data = Mock.mock_get('server/009d64ef-31d1-4684-a26b-c86c955cbf46')
server = manager.get_server('009d64ef-31d1-4684-a26b-c86c955cbf46')

assert server.state == "stopped"
assert server.state == 'stopped'

data = Mock.mock_server_operation("server/009d64ef-31d1-4684-a26b-c86c955cbf46/start")
server.start()

assert server.state == "started"

@responses.activate
def test_stop_server(self, manager):
data = Mock.mock_get("server/00798b85-efdc-41ca-8021-f6ef457b8531")
server = manager.get_server("00798b85-efdc-41ca-8021-f6ef457b8531")

assert server.state == "started"

data = Mock.mock_server_operation("server/00798b85-efdc-41ca-8021-f6ef457b8531/stop")
server.stop()

assert server.state == "maintenance"

@responses.activate
def test_restart_server(self, manager):
data = Mock.mock_get("server/00798b85-efdc-41ca-8021-f6ef457b8531")
server = manager.get_server("00798b85-efdc-41ca-8021-f6ef457b8531")

assert server.state == "started"

data = Mock.mock_server_operation("server/00798b85-efdc-41ca-8021-f6ef457b8531/restart")
server.restart()

assert server.state == "maintenance"

@responses.activate
def test_attach_and_detach_IP(self, manager):
data = Mock.mock_get("server/00798b85-efdc-41ca-8021-f6ef457b8531")
server = manager.get_server("00798b85-efdc-41ca-8021-f6ef457b8531")
assert len(server.ip_addresses) == 2

data = Mock.mock_post("ip_address")
server.add_IP()
assert len(server.ip_addresses) == 3

Mock.mock_delete("ip_address/"+server.ip_addresses[2].address)
server.remove_IP(server.ip_addresses[2])
assert len(server.ip_addresses) == 2

@responses.activate
def test_attach_and_detach_storage(self, manager):
data = Mock.mock_get("server/00798b85-efdc-41ca-8021-f6ef457b8531")
server = manager.get_server("00798b85-efdc-41ca-8021-f6ef457b8531")
assert len(server.storage_devices) == 1
assert server.storage_devices[0].title == "Storage for server1.example.com"

data = Mock.mock_get("storage/01d4fcd4-e446-433b-8a9c-551a1284952e")
storage = manager.get_storage("01d4fcd4-e446-433b-8a9c-551a1284952e")


responses.add(
responses.POST,
Mock.base_url + "/server/00798b85-efdc-41ca-8021-f6ef457b8531/storage/attach",
body = Mock.read_from_file("storage_attach.json"),
status = 200,
content_type='application/json'
)
server.add_storage(storage)
assert len(server.storage_devices) == 2
assert server.storage_devices[0].title == "Storage for server1.example.com"
assert server.storage_devices[1].title == "Operating system disk"

responses.add(
responses.POST,
Mock.base_url + "/server/00798b85-efdc-41ca-8021-f6ef457b8531/storage/detach",
body = Mock.read_from_file("storage_attach.json"),
status = 200,
content_type='application/json'
)
data = Mock.mock_server_operation('server/009d64ef-31d1-4684-a26b-c86c955cbf46/start')
server.start()

assert server.state == 'started'

@responses.activate
def test_stop_server(self, manager):
data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')

assert server.state == 'started'

data = Mock.mock_server_operation('server/00798b85-efdc-41ca-8021-f6ef457b8531/stop')
server.stop()

assert server.state == 'maintenance'

@responses.activate
def test_restart_server(self, manager):
data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')

assert server.state == 'started'

data = Mock.mock_server_operation('server/00798b85-efdc-41ca-8021-f6ef457b8531/restart')
server.restart()

assert server.state == 'maintenance'

@responses.activate
def test_attach_and_detach_IP(self, manager):
data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')
assert len(server.ip_addresses) == 2

data = Mock.mock_post('ip_address')
server.add_IP()
assert len(server.ip_addresses) == 3

Mock.mock_delete('ip_address/'+server.ip_addresses[2].address)
server.remove_IP(server.ip_addresses[2])
assert len(server.ip_addresses) == 2

@responses.activate
def test_attach_and_detach_storage(self, manager):
data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')
assert len(server.storage_devices) == 1
assert server.storage_devices[0].title == 'Storage for server1.example.com'

data = Mock.mock_get('storage/01d4fcd4-e446-433b-8a9c-551a1284952e')
storage = manager.get_storage('01d4fcd4-e446-433b-8a9c-551a1284952e')


responses.add(
responses.POST,
Mock.base_url + '/server/00798b85-efdc-41ca-8021-f6ef457b8531/storage/attach',
body = Mock.read_from_file('storage_attach.json'),
status = 200,
content_type='application/json'
)
server.add_storage(storage)
assert len(server.storage_devices) == 2
assert server.storage_devices[0].title == 'Storage for server1.example.com'
assert server.storage_devices[1].title == 'Operating system disk'

responses.add(
responses.POST,
Mock.base_url + '/server/00798b85-efdc-41ca-8021-f6ef457b8531/storage/detach',
body = Mock.read_from_file('storage_attach.json'),
status = 200,
content_type='application/json'
)

server.remove_storage(server.storage_devices[1])

assert len(server.storage_devices) == 1
assert server.storage_devices[0].title == "Storage for server1.example.com"
server.remove_storage(server.storage_devices[1])

assert len(server.storage_devices) == 1
assert server.storage_devices[0].title == 'Storage for server1.example.com'

@responses.activate
def test_update_server_oop(self, manager):
data = Mock.mock_get("server/00798b85-efdc-41ca-8021-f6ef457b8531")
server = manager.get_server("00798b85-efdc-41ca-8021-f6ef457b8531")

server.core_number = 6
server.memory_amount = 1024
server.title = "Updated server"
@responses.activate
def test_update_server_oop(self, manager):
data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')

server.core_number = 6
server.memory_amount = 1024
server.title = 'Updated server'

data = Mock.mock_put("server/00798b85-efdc-41ca-8021-f6ef457b8531")
server.save()
data = Mock.mock_put('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server.save()

assert server.core_number == 6
assert server.memory_amount == 1024
assert server.title == "Updated server"
assert server.core_number == 6
assert server.memory_amount == 1024
assert server.title == 'Updated server'

@responses.activate
def test_update_server_non_updateable_fields(self, manager):
data = Mock.mock_get("server/00798b85-efdc-41ca-8021-f6ef457b8531")
server = manager.get_server("00798b85-efdc-41ca-8021-f6ef457b8531")
@responses.activate
def test_update_server_non_updateable_fields(self, manager):
data = Mock.mock_get('server/00798b85-efdc-41ca-8021-f6ef457b8531')
server = manager.get_server('00798b85-efdc-41ca-8021-f6ef457b8531')

with pytest.raises(Exception) as excinfo:
server.state = "rekt"
assert "'state' is a readonly field" in str(excinfo.value)
with pytest.raises(Exception) as excinfo:
server.state = 'rekt'
assert "'state' is a readonly field" in str(excinfo.value)
Loading

0 comments on commit 2ee612b

Please sign in to comment.