124 lines
4.1 KiB
Python
124 lines
4.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
import json
|
|
from paste.fixture import TestApp
|
|
|
|
from api.models import Release
|
|
from base import BaseHandlers
|
|
from base import reverse
|
|
|
|
|
|
class TestHandlers(BaseHandlers):
|
|
def test_release_list_empty(self):
|
|
resp = self.app.get(
|
|
reverse('ReleaseCollectionHandler'),
|
|
headers=self.default_headers
|
|
)
|
|
self.assertEquals(200, resp.status)
|
|
response = json.loads(resp.body)
|
|
self.assertEquals([], response)
|
|
|
|
def test_release_list_big(self):
|
|
for i in range(100):
|
|
self.create_default_release()
|
|
resp = self.app.get(
|
|
reverse('ReleaseCollectionHandler'),
|
|
headers=self.default_headers
|
|
)
|
|
self.assertEquals(200, resp.status)
|
|
response = json.loads(resp.body)
|
|
self.assertEquals(100, len(response))
|
|
|
|
def test_release_creation(self):
|
|
resp = self.app.post(
|
|
'/api/releases',
|
|
params=json.dumps({
|
|
'name': 'Another test release',
|
|
'version': '1.0'
|
|
}),
|
|
headers=self.default_headers
|
|
)
|
|
self.assertEquals(resp.status, 201)
|
|
|
|
def test_release_create(self):
|
|
release_name = "OpenStack"
|
|
release_version = "1.0.0"
|
|
release_description = "This is test release"
|
|
resp = self.app.post(
|
|
reverse('ReleaseCollectionHandler'),
|
|
json.dumps({
|
|
'name': release_name,
|
|
'version': release_version,
|
|
'description': release_description,
|
|
'networks_metadata': [
|
|
{"name": "floating", "access": "public"},
|
|
{"name": "fixed", "access": "private10"},
|
|
{"name": "storage", "access": "private192"}
|
|
]
|
|
}),
|
|
headers=self.default_headers
|
|
)
|
|
self.assertEquals(resp.status, 201)
|
|
|
|
resp = self.app.post(
|
|
reverse('ReleaseCollectionHandler'),
|
|
json.dumps({
|
|
'name': release_name,
|
|
'version': release_version,
|
|
'description': release_description,
|
|
'networks_metadata': [
|
|
{"name": "fixed", "access": "private10"}
|
|
]
|
|
}),
|
|
headers=self.default_headers,
|
|
expect_errors=True
|
|
)
|
|
self.assertEquals(resp.status, 409)
|
|
|
|
release_from_db = self.db.query(Release).filter(
|
|
Release.name == release_name,
|
|
Release.version == release_version,
|
|
Release.description == release_description
|
|
).all()
|
|
self.assertEquals(len(release_from_db), 1)
|
|
|
|
def test_release_create_already_exist(self):
|
|
release_name = "OpenStack"
|
|
release_version = "1.0.0"
|
|
release_description = "This is test release"
|
|
resp = self.app.post(
|
|
reverse('ReleaseCollectionHandler'),
|
|
json.dumps({
|
|
'name': release_name,
|
|
'version': release_version,
|
|
'description': release_description,
|
|
'networks_metadata': [
|
|
{"name": "floating", "access": "public"},
|
|
{"name": "fixed", "access": "private10"},
|
|
{"name": "storage", "access": "private192"}
|
|
]
|
|
}),
|
|
headers=self.default_headers
|
|
)
|
|
self.assertEquals(resp.status, 201)
|
|
|
|
resp = self.app.post(
|
|
reverse('ReleaseCollectionHandler'),
|
|
json.dumps({
|
|
'name': release_name,
|
|
'version': release_version,
|
|
'description': release_description,
|
|
'networks_metadata': [
|
|
{"name": "fixed", "access": "private10"}
|
|
]
|
|
}),
|
|
headers=self.default_headers,
|
|
expect_errors=True
|
|
)
|
|
self.assertEquals(resp.status, 409)
|
|
|
|
release_from_db = self.db.query(Release).filter(
|
|
Release.name == release_name,
|
|
Release.version == release_version,
|
|
Release.description == release_description
|
|
).one()
|