Skip to content
This repository has been archived by the owner on Feb 2, 2018. It is now read-only.

Commit

Permalink
Merge pull request #3 from ashcrow/update-example-calls
Browse files Browse the repository at this point in the history
example: Added host endpoint.

PR passes with expected results.

=> Listing Hosts Without Auth (Should Fail)
127.0.0.1 - - [2016-01-20 13:59:13] "GET /api/v0/hosts HTTP/1.1" 403 175 0.000326
{u'description': u'Forbidden', u'title': u'Forbidden'}
SUCCESS!
=> Listing Hosts With Auth
127.0.0.1 - - [2016-01-20 13:59:13] "GET /api/v0/hosts HTTP/1.1" 200 280 0.249626
[{u'status': u'available', u'space': 487652, u'address': u'10.0.0.1', u'cpus': 2, u'last_check': u'2015-12-17T15:48:18.710454', u'memory': 11989228, u'os': u'atomic'}]
SUCCESS!
=> Listing Existing Host 10.0.0.1
127.0.0.1 - - [2016-01-20 13:59:14] "GET /api/v0/host/10.0.0.1 HTTP/1.1" 200 278 0.252620
{u'status': u'available', u'space': 487652, u'address': u'10.0.0.1', u'cpus': 2, u'last_check': u'2015-12-17T15:48:18.710454', u'memory': 11989228, u'os': u'atomic'}
SUCCESS!
=> Listing Non Existing Host 10.0.0.2
127.0.0.1 - - [2016-01-20 13:59:14] "GET /api/v0/hosts/10.0.0.2 HTTP/1.1" 404 131 0.246412
{}
SUCCESS!
=> Creating Host 10.2.0.2
127.0.0.1 - - [2016-01-20 13:59:14] "PUT /api/v0/host/10.2.0.2 HTTP/1.1" 201 265 0.262298
{u'status': u'investigating', u'space': -1, u'address': u'10.2.0.2', u'cpus': -1, u'last_check': u'0001-01-01T00:00:00', u'memory': -1, u'os': u''}
SUCCESS!
=> Creating Host Again 10.2.0.2 (Should Fail)
127.0.0.1 - - [2016-01-20 13:59:14] "PUT /api/v0/host/10.2.0.2 HTTP/1.1" 409 130 0.249732
{}
SUCCESS!
=> Deleting Host 10.2.0.2
127.0.0.1 - - [2016-01-20 13:59:15] "DELETE /api/v0/host/10.2.0.2 HTTP/1.1" 410 126 0.261026
{}
SUCCESS!
(testing)[rcook@goku example]$
  • Loading branch information
cooktheryan committed Jan 20, 2016
2 parents 41802dc + 1d98f9a commit f3bd0fb
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions example/rest_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,49 @@

import requests

def expected_status(r, code):
if r.status_code == code:
print("SUCCESS!")
else:
print("FAILURE {0} != {1}".format(code, r.status_code))


print("=> Listing Hosts Without Auth (Should Fail)")
r = requests.get('http://127.0.0.1:8000/api/v0/hosts')
print(r.json())
expected_status(r, 403)

print("=> Listing Hosts With Auth")
r = requests.get('http://127.0.0.1:8000/api/v0/hosts', auth=('a', 'a'))
print(r.json())
expected_status(r, 200)

print("=> Listing Existing Host 10.0.0.1")
r = requests.get(
'http://127.0.0.1:8000/api/v0/hosts/10.0.0.1', auth=('a', 'a'))
'http://127.0.0.1:8000/api/v0/host/10.0.0.1', auth=('a', 'a'))
print(r.json())
expected_status(r, 200)

print("=> Listing Non Existing Host 10.0.0.2")
r = requests.get(
'http://127.0.0.1:8000/api/v0/hosts/10.0.0.2', auth=('a', 'a'))
print(r.json())
expected_status(r, 404)

print("=> Creating Host 10.2.0.2")
r = requests.put(
'http://127.0.0.1:8000/api/v0/hosts/10.2.0.2',
'http://127.0.0.1:8000/api/v0/host/10.2.0.2',
auth=('a', 'a'),
json={
"address": "10.2.0.2",
"status": "available",
"os": "atomic",
"cpus": 2,
"memory": 11989228,
"space": 487652,
"last_check": "2015-12-17T15:48:18.710454"})
"ssh_priv_key": "dGVzdAo=",
})
print(r.json())
expected_status(r, 201)

print("=> Creating Host Again 10.2.0.2 (Should Fail)")
r = requests.put(
'http://127.0.0.1:8000/api/v0/hosts/10.2.0.2',
'http://127.0.0.1:8000/api/v0/host/10.2.0.2',
auth=('a', 'a'),
json={
"address": "10.2.0.2",
Expand All @@ -60,9 +68,11 @@
"space": 487652,
"last_check": "2015-12-17T15:48:18.710454"})
print(r.json())
expected_status(r, 409)

print("=> Deleting Host 10.2.0.2")
r = requests.delete(
'http://127.0.0.1:8000/api/v0/hosts/10.2.0.2',
'http://127.0.0.1:8000/api/v0/host/10.2.0.2',
auth=('a', 'a'))
print(r.json())
expected_status(r, 410)

0 comments on commit f3bd0fb

Please sign in to comment.