This commit is contained in:
kevgliss
2016-06-27 14:40:46 -07:00
committed by GitHub
parent b44a7c73d8
commit fe9703dd94
36 changed files with 1140 additions and 187 deletions

View File

@ -3,7 +3,7 @@ from datetime import date
from factory import Sequence, post_generation, SubFactory
from factory.alchemy import SQLAlchemyModelFactory
from factory.fuzzy import FuzzyChoice, FuzzyText, FuzzyDate
from factory.fuzzy import FuzzyChoice, FuzzyText, FuzzyDate, FuzzyInteger
from lemur.database import db
@ -210,3 +210,20 @@ class UserFactory(BaseFactory):
if extracted:
for authority in extracted:
self.authorities.append(authority)
class PolicyFactory(BaseFactory):
"""Policy Factory."""
name = Sequence(lambda n: 'endpoint{0}'.format(n))
class EndpointFactory(BaseFactory):
"""Endpoint Factory."""
owner = 'joe@example.com'
name = Sequence(lambda n: 'endpoint{0}'.format(n))
type = FuzzyChoice(['elb'])
active = True
port = FuzzyInteger(0, high=65535)
policy = SubFactory(PolicyFactory)
certificate = SubFactory(CertificateFactory)
destination = SubFactory(DestinationFactory)

View File

@ -0,0 +1,87 @@
import pytest
from lemur.endpoints.views import * # noqa
from .vectors import VALID_ADMIN_HEADER_TOKEN, VALID_USER_HEADER_TOKEN
@pytest.mark.parametrize("token,status", [
(VALID_USER_HEADER_TOKEN, 404),
(VALID_ADMIN_HEADER_TOKEN, 404),
('', 401)
])
def test_endpoint_get(client, token, status):
assert client.get(api.url_for(Endpoints, endpoint_id=1), headers=token).status_code == status
@pytest.mark.parametrize("token,status", [
(VALID_USER_HEADER_TOKEN, 405),
(VALID_ADMIN_HEADER_TOKEN, 405),
('', 405)
])
def test_endpoint_post_(client, token, status):
assert client.post(api.url_for(Endpoints, endpoint_id=1), data={}, headers=token).status_code == status
@pytest.mark.parametrize("token,status", [
(VALID_USER_HEADER_TOKEN, 405),
(VALID_ADMIN_HEADER_TOKEN, 405),
('', 405)
])
def test_endpoint_put(client, token, status):
assert client.put(api.url_for(Endpoints, endpoint_id=1), data={}, headers=token).status_code == status
@pytest.mark.parametrize("token,status", [
(VALID_USER_HEADER_TOKEN, 405),
(VALID_ADMIN_HEADER_TOKEN, 405),
('', 405)
])
def test_endpoint_delete(client, token, status):
assert client.delete(api.url_for(Endpoints, endpoint_id=1), headers=token).status_code == status
@pytest.mark.parametrize("token,status", [
(VALID_USER_HEADER_TOKEN, 405),
(VALID_ADMIN_HEADER_TOKEN, 405),
('', 405)
])
def test_endpoint_patch(client, token, status):
assert client.patch(api.url_for(Endpoints, endpoint_id=1), data={}, headers=token).status_code == status
@pytest.mark.parametrize("token,status", [
(VALID_USER_HEADER_TOKEN, 405),
(VALID_ADMIN_HEADER_TOKEN, 405),
('', 405)
])
def test_endpoint_list_post_(client, token, status):
assert client.post(api.url_for(EndpointsList), data={}, headers=token).status_code == status
@pytest.mark.parametrize("token,status", [
(VALID_USER_HEADER_TOKEN, 200),
(VALID_ADMIN_HEADER_TOKEN, 200),
('', 401)
])
def test_endpoint_list_get(client, token, status):
assert client.get(api.url_for(EndpointsList), headers=token).status_code == status
@pytest.mark.parametrize("token,status", [
(VALID_USER_HEADER_TOKEN, 405),
(VALID_ADMIN_HEADER_TOKEN, 405),
('', 405)
])
def test_endpoint_list_delete(client, token, status):
assert client.delete(api.url_for(EndpointsList), headers=token).status_code == status
@pytest.mark.parametrize("token,status", [
(VALID_USER_HEADER_TOKEN, 405),
(VALID_ADMIN_HEADER_TOKEN, 405),
('', 405)
])
def test_endpoint_list_patch(client, token, status):
assert client.patch(api.url_for(EndpointsList), data={}, headers=token).status_code == status