Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Add tests for transforms endpoint
Browse files Browse the repository at this point in the history
We need to ensure the task creator is called when
the transforms endpoint is called with a valid request.
  • Loading branch information
mattrco committed Dec 19, 2014
1 parent f45a36e commit 6046495
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/write/test_api.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import datetime
import json
import unittest
import pytz

from hamcrest import assert_that, is_
from mock import patch

from backdrop.write import api
from backdrop.write.api import bounding_dates, trigger_transforms, parse_bounding_dates

from tests.support.performanceplatform_client import fake_data_set_exists, fake_no_data_sets_exist
from tests.support.test_helpers import is_ok


class BoundingDatesTestCase(unittest.TestCase):

Expand Down Expand Up @@ -78,3 +83,49 @@ def test_trigger_transforms_with_dates(self, mock_celery_app):
mock_celery_app.send_task.assert_called_with(
'backdrop.transformers.dispatch.entrypoint',
args=('dataset', earliest, latest))


class TriggerTransformsEndpointTestCase(unittest.TestCase):

def setUp(self):
self.app = api.app.test_client()

@fake_data_set_exists("foo", data_group="some-group", data_type="some-type", bearer_token="foo-bearer-token")
def test_endpoint_succeeds(self):

data = json.dumps({
"_start_at": "2014-12-17T00:00:00Z",
})

response = self.app.post(
'/data/some-group/some-type/transform',
data=data,
content_type='application/json',
headers=[('Authorization', 'Bearer foo-bearer-token')],
)
assert_that(response, is_ok())

@fake_data_set_exists("foo", data_group="some-group", data_type="some-type", bearer_token="foo-bearer-token")
@patch('backdrop.write.api.trigger_transforms')
def test_endpoint_triggers_task(self, mock_trigger_transforms):

earliest = datetime.datetime(2014, 12, 17, 0, 0)
latest = datetime.datetime(2014, 12, 18, 0, 0)
data = json.dumps({
"_start_at": str(earliest),
"_end_at": str(latest),
})

self.app.post(
'/data/some-group/some-type/transform',
data=data,
content_type='application/json',
headers=[('Authorization', 'Bearer foo-bearer-token')],
)
mock_trigger_transforms.assert_called_with({'bearer_token': 'foo-bearer-token',
'capped_size': 0,
'name': 'foo',
'data_type': 'some-type',
'data_group': 'some-group'},
earliest=earliest,
latest=latest)

0 comments on commit 6046495

Please sign in to comment.