Adding Gabbi Tests to Events API
This contains tests both with and without fixtures to establish an accepted behavior pattern of the Events and Event_Type Endpoints Change-Id: I3d7eff9378e3c261ecc4b972393fd24a2ed4f00a
This commit is contained in:
parent
372e8070d5
commit
abb32213ec
@ -26,6 +26,7 @@ import uuid
|
||||
from gabbi import fixture
|
||||
from oslo_config import fixture as fixture_config
|
||||
|
||||
from ceilometer.event.storage import models
|
||||
from ceilometer.publisher import utils
|
||||
from ceilometer import sample
|
||||
from ceilometer import service
|
||||
@ -48,6 +49,8 @@ class ConfigFixture(fixture.GabbiFixture):
|
||||
conf = fixture_config.Config().conf
|
||||
self.conf = conf
|
||||
conf.import_opt('policy_file', 'ceilometer.openstack.common.policy')
|
||||
conf.import_opt('store_events', 'ceilometer.notification',
|
||||
group='notification')
|
||||
conf.set_override('policy_file',
|
||||
os.path.abspath('etc/ceilometer/policy.json'))
|
||||
|
||||
@ -73,6 +76,8 @@ class ConfigFixture(fixture.GabbiFixture):
|
||||
|
||||
conf.set_override('pecan_debug', True, group='api')
|
||||
|
||||
conf.set_override('store_events', True, group='notification')
|
||||
|
||||
def stop_fixture(self):
|
||||
"""Reset the config and remove data."""
|
||||
storage.get_connection_from_config(self.conf).clear()
|
||||
@ -102,8 +107,7 @@ class SampleDataFixture(fixture.GabbiFixture):
|
||||
resource_id=project_id,
|
||||
timestamp=timestamp,
|
||||
resource_metadata=resource_metadata,
|
||||
source=self.source,
|
||||
)
|
||||
source=self.source)
|
||||
data = utils.meter_message_from_counter(
|
||||
c, conf.publisher.telemetry_secret)
|
||||
self.conn.record_metering_data(data)
|
||||
@ -115,3 +119,29 @@ class SampleDataFixture(fixture.GabbiFixture):
|
||||
print('resource',
|
||||
self.conn.db.resource.remove({'source': self.source}))
|
||||
print('meter', self.conn.db.meter.remove({'source': self.source}))
|
||||
|
||||
|
||||
class EventDataFixture(fixture.GabbiFixture):
|
||||
"""Instantiate some sample event data for use in testing."""
|
||||
|
||||
def start_fixture(self):
|
||||
"""Create some events."""
|
||||
conf = fixture_config.Config().conf
|
||||
self.conn = storage.get_connection_from_config(conf, 'event')
|
||||
events = []
|
||||
name_list = ['chocolate.chip', 'peanut.butter', 'sugar']
|
||||
for ix, name in enumerate(name_list):
|
||||
timestamp = datetime.datetime.utcnow()
|
||||
message_id = 'fea1b15a-1d47-4175-85a5-a4bb2c72924{}'.format(ix)
|
||||
traits = [models.Trait('type', 1, name),
|
||||
models.Trait('ate', 2, ix)]
|
||||
event = models.Event(message_id,
|
||||
'cookies_{}'.format(name),
|
||||
timestamp,
|
||||
traits)
|
||||
events.append(event)
|
||||
self.conn.record_events(events)
|
||||
|
||||
def stop_fixture(self):
|
||||
"""Destroy the events."""
|
||||
self.conn.db.event.remove({'event_type': '/^cookies_/'})
|
||||
|
142
ceilometer/tests/gabbi/gabbits/api_events_no_data.yaml
Normal file
142
ceilometer/tests/gabbi/gabbits/api_events_no_data.yaml
Normal file
@ -0,0 +1,142 @@
|
||||
# These test run against the Events API with no data preloaded into the
|
||||
# datastore. This allows us to verify that requests are still processed
|
||||
# normally even if data is missing for that endpoint.
|
||||
fixtures:
|
||||
- ConfigFixture
|
||||
|
||||
tests:
|
||||
|
||||
# this attempts to get all the events and expects an empty list back
|
||||
- name: get all events
|
||||
url: /v2/events
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/events
|
||||
response_strings:
|
||||
- "[]"
|
||||
|
||||
# this attempts to get all the events with invalid parameters and expects a 400
|
||||
- name: get events with bad params
|
||||
url: /v2/events?bad_Stuff_here
|
||||
status: 400
|
||||
|
||||
# this attempts to query the events with the correct parameterized query syntax
|
||||
# and expects an empty list
|
||||
- name: get events that match query
|
||||
url: /v2/events?q.field=event_type&q.op=eq&q.type=string&q.value=cookies_chocolate.chip
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/events?q.field=event_type&q.op=eq&q.type=string&q.value=cookies_chocolate.chip
|
||||
response_strings:
|
||||
- "[]"
|
||||
|
||||
# this attempts to query the events with the correct data query syntax and
|
||||
# expects an empty list
|
||||
- name: get events that match query via request data
|
||||
url: /v2/events
|
||||
request_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
data:
|
||||
q:
|
||||
- field: event_type
|
||||
op: eq
|
||||
type: string
|
||||
value: cookies_chocolate.chip
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/events
|
||||
response_strings:
|
||||
- "[]"
|
||||
|
||||
# this attempts to query the events with the correct parameterized query syntax
|
||||
# but a bad field name and expects an empty list
|
||||
- name: get events that match bad query
|
||||
url: /v2/events?q.field=bad_field&q.op=eq&q.type=string&q.value=cookies_chocolate.chip
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/events?q.field=bad_field&q.op=eq&q.type=string&q.value=cookies_chocolate.chip
|
||||
response_strings:
|
||||
- "[]"
|
||||
|
||||
# this attempts to query the events with the correct data query syntax and
|
||||
# a bad field name and expects an empty list
|
||||
- name: get events that match bad query via request data
|
||||
url: /v2/events
|
||||
request_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
data:
|
||||
q:
|
||||
- field: bad_field
|
||||
op: eq
|
||||
type: string
|
||||
value: cookies_chocolate.chip
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/events
|
||||
response_strings:
|
||||
- "[]"
|
||||
|
||||
# this attempts to query the events with the wrong data query syntax missing the
|
||||
# q object but supplying the field list and a bad field name and expects a 400
|
||||
- name: get events that match bad query via request data malformed list
|
||||
desc: https://bugs.launchpad.net/ceilometer/+bug/1423634
|
||||
url: /v2/events
|
||||
request_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
data:
|
||||
- field: bad_field
|
||||
op: eq
|
||||
type: string
|
||||
value: cookies_chocolate.chip
|
||||
xfail: True
|
||||
status: 400
|
||||
|
||||
# this attempts to query the events with the wrong data query syntax missing the
|
||||
# q object but supplying the field list along with a bad content-type. Should
|
||||
# return a 400
|
||||
- name: get events that match bad query via request data wrong type
|
||||
desc: https://bugs.launchpad.net/ceilometer/+bug/1423634 and https://bugs.launchpad.net/ceilometer/+bug/1424642
|
||||
url: /v2/events
|
||||
request_headers:
|
||||
content-type: text/plain
|
||||
data:
|
||||
"field: bad_field op: eq type: string value: cookies_chocolate.chip xfail: True"
|
||||
xfail: True
|
||||
status: 400
|
||||
|
||||
# Get a single event by message_id no data is present so should return a 404
|
||||
- name: get a single event
|
||||
url: /v2/events/fea1b15a-1d47-4175-85a5-a4bb2c729240
|
||||
status: 404
|
||||
|
||||
# Get all the event types should return an empty list
|
||||
- name: get all event types
|
||||
url: /v2/event_types
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/event_types
|
||||
response_strings:
|
||||
- "[]"
|
||||
|
||||
# Get a single event type by name, this API is unused and should return a 404
|
||||
- name: get event types for good event_type unused api
|
||||
url: /v2/event_types/cookies_chocolate.chip
|
||||
status: 404
|
||||
|
||||
# Get all traits for an event type should return an empty list
|
||||
- name: get all traits for event type
|
||||
url: /v2/event_types/cookies_chocolate.chip/traits
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/event_types/cookies_chocolate.chip/traits
|
||||
response_strings:
|
||||
- "[]"
|
||||
|
||||
# Get all traits named ate for an event type should return an empty list
|
||||
- name: get all traits named ate for event type
|
||||
url: /v2/event_types/cookies_chocolate.chip/traits/ate
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/event_types/cookies_chocolate.chip/traits/ate
|
||||
response_strings:
|
||||
- "[]"
|
188
ceilometer/tests/gabbi/gabbits/api_events_with_data.yaml
Normal file
188
ceilometer/tests/gabbi/gabbits/api_events_with_data.yaml
Normal file
@ -0,0 +1,188 @@
|
||||
# These test run against the Events API with data preloaded into the datastore.
|
||||
fixtures:
|
||||
- ConfigFixture
|
||||
- EventDataFixture
|
||||
|
||||
tests:
|
||||
|
||||
# this attempts to get all the events and checks to make sure they are valid
|
||||
- name: get all events
|
||||
url: /v2/events
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/events
|
||||
response_json_paths:
|
||||
$.[0].event_type: cookies_chocolate.chip
|
||||
$.[0].traits.[0].value: chocolate.chip
|
||||
$.[0].traits.[1].value: '0'
|
||||
$.[1].event_type: cookies_peanut.butter
|
||||
$.[1].traits.[0].name: type
|
||||
$.[1].traits.[1].name: ate
|
||||
$.[2].event_type: cookies_sugar
|
||||
$.[2].traits.[0].type: string
|
||||
$.[2].traits.[1].type: integer
|
||||
|
||||
# this attempts to get all the events with invalid parameters and expects a 400
|
||||
- name: get events with bad params
|
||||
url: /v2/events?bad_Stuff_here
|
||||
status: 400
|
||||
|
||||
# this attempts to query the events with the correct parameterized query syntax
|
||||
# and expects a matching event
|
||||
- name: get events that match query
|
||||
url: /v2/events?q.field=event_type&q.op=eq&q.type=string&q.value=cookies_chocolate.chip
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/events?q.field=event_type&q.op=eq&q.type=string&q.value=cookies_chocolate.chip
|
||||
response_json_paths:
|
||||
$.[0].event_type: cookies_chocolate.chip
|
||||
$.[0].traits.[0].value: chocolate.chip
|
||||
|
||||
# this attempts to query the events with the correct data query syntax and
|
||||
# expects a matching event
|
||||
- name: get events that match query via data
|
||||
url: /v2/events
|
||||
request_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
data:
|
||||
q:
|
||||
- field: event_type
|
||||
op: eq
|
||||
type: string
|
||||
value: cookies_chocolate.chip
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/events
|
||||
response_json_paths:
|
||||
$.[0].event_type: cookies_chocolate.chip
|
||||
$.[0].traits.[0].value: chocolate.chip
|
||||
|
||||
# this attempts to query the events with the correct parameterized query syntax
|
||||
# but a bad field name and expects an empty list
|
||||
- name: get events that match bad query
|
||||
url: /v2/events?q.field=bad_field&q.op=eq&q.type=string&q.value=cookies_chocolate.chip
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/events?q.field=bad_field&q.op=eq&q.type=string&q.value=cookies_chocolate.chip
|
||||
response_strings:
|
||||
- "[]"
|
||||
|
||||
# this attempts to query the events with the correct data query syntax and
|
||||
# a bad field name and expects an empty list
|
||||
- name: get events that match bad query via data
|
||||
url: /v2/events
|
||||
request_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
data:
|
||||
q:
|
||||
- field: bad_field
|
||||
op: eq
|
||||
type: string
|
||||
value: cookies_chocolate.chip
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/events
|
||||
response_strings:
|
||||
- "[]"
|
||||
|
||||
# this attempts to query the events with the wrong data query syntax missing the
|
||||
# q object but supplying the field list and a bad field name and expects a 400
|
||||
- name: get events that match bad query via data list
|
||||
desc: https://bugs.launchpad.net/ceilometer/+bug/1423634
|
||||
url: /v2/events
|
||||
request_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
data:
|
||||
- field: bad_field
|
||||
op: eq
|
||||
type: string
|
||||
value: cookies_chocolate.chip
|
||||
xfail: True
|
||||
status: 400
|
||||
|
||||
# Get a single event by message_id should return an event
|
||||
- name: get a single event
|
||||
url: /v2/events/fea1b15a-1d47-4175-85a5-a4bb2c729240
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/events/fea1b15a-1d47-4175-85a5-a4bb2c729240
|
||||
response_json_paths:
|
||||
$.event_type: cookies_chocolate.chip
|
||||
$.traits.[0].value: chocolate.chip
|
||||
$.traits.[1].value: '0'
|
||||
|
||||
# Get a single event by message_id no data is present so should return a 404
|
||||
- name: get a single event that does not exist
|
||||
url: /v2/events/bad-id
|
||||
status: 404
|
||||
|
||||
# Get all the event types should return a list of event types
|
||||
- name: get all event types
|
||||
url: /v2/event_types
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/event_types
|
||||
response_strings:
|
||||
- cookies_chocolate.chip
|
||||
- cookies_peanut.butter
|
||||
- cookies_sugar
|
||||
|
||||
# Get a single event type by valid name, this API is unused and should return a 404
|
||||
- name: get event types for good event_type unused api
|
||||
url: /v2/event_types/cookies_chocolate.chip
|
||||
status: 404
|
||||
|
||||
# Get a single event type by invalid name, this API is unused and should return a 404
|
||||
- name: get event types for bad event_type unused api
|
||||
url: /v2/event_types/bad_event_type
|
||||
status: 404
|
||||
|
||||
# Get all traits for a valid event type should return an list of traits
|
||||
- name: get all traits for event type
|
||||
url: /v2/event_types/cookies_chocolate.chip/traits
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/event_types/cookies_chocolate.chip/traits
|
||||
response_json_paths:
|
||||
$.[0].type: string
|
||||
$.[1].name: ate
|
||||
|
||||
# Get all traits for an invalid event type should return an empty list
|
||||
- name: get all traits names for event type bad event type
|
||||
url: /v2/event_types/bad_event_type/traits
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/event_types/bad_event_type/traits
|
||||
response_strings:
|
||||
- "[]"
|
||||
|
||||
# Get all traits of type ate for a valid event type should return an list of
|
||||
# traits
|
||||
- name: get all traits of type ate for event type
|
||||
url: /v2/event_types/cookies_chocolate.chip/traits/ate
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/event_types/cookies_chocolate.chip/traits/ate
|
||||
response_json_paths:
|
||||
$.[0].name: ate
|
||||
$.[0].value: '0'
|
||||
|
||||
# Get all traits of type ate for a invalid event type should return an empty
|
||||
# list
|
||||
- name: get all traits of type for event type bad event type
|
||||
url: /v2/event_types/bad_event_type/traits/ate
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/event_types/bad_event_type/traits/ate
|
||||
response_strings:
|
||||
- "[]"
|
||||
|
||||
# Get all traits of type bad_trait_name for a valid event type should return an
|
||||
# empty list
|
||||
- name: get all traits of type instances for event type bad trait name
|
||||
url: /v2/event_types/cookies_chocolate.chip/traits/bad_trait_name
|
||||
response_headers:
|
||||
content-type: application/json; charset=UTF-8
|
||||
content-location: $SCHEME://$NETLOC/v2/event_types/cookies_chocolate.chip/traits/bad_trait_name
|
||||
response_strings:
|
||||
- "[]"
|
Loading…
Reference in New Issue
Block a user