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

Commit

Permalink
tests for upcoming unschedule api
Browse files Browse the repository at this point in the history
  • Loading branch information
oyiptong committed Feb 12, 2015
1 parent ce31862 commit c484b98
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/api/test_upcoming.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import calendar
from datetime import datetime, timedelta
from nose.tools import assert_equal
from flask import url_for
from mock import Mock, PropertyMock
from tests.base import BaseTestCase
import splice.ingest
from splice.queries import get_scheduled_distributions
from splice.environment import Environment

env = Environment.instance()


class TestUpcomingUnschedule(BaseTestCase):
def setUp(self):
self.key_mock = Mock()
self.key_mock.name = PropertyMock()

def get_key_mock(*args, **kwargs):
return self.key_mock
splice.ingest.Key = Mock(side_effect=get_key_mock)

self.env.s3.get_bucket = Mock(return_value=Mock())

with open(self.get_fixture_path("mozilla-tiles.fennec.json"), 'r') as f:
self.sample_tile_data = f.read()

super(TestUpcomingUnschedule, self).setUp()

def test_unschedule(self):
now = datetime.utcnow() + timedelta(minutes=5)
now_ts = calendar.timegm(now.timetuple())

url = "{0}?deploy=0&channelId=1&scheduledTS={1}".format(url_for('api.authoring.all_tiles'), now_ts)

self.client.post(url, data=self.sample_tile_data)
dist = get_scheduled_distributions(1, now)[0]

url = "{0}?distId={1}".format(url_for('api.upcoming.unschedule'), dist.id)
response = self.client.post(url)
assert_equal(response.status_code, 204)
dists = get_scheduled_distributions(1, now)
assert_equal(len(dists), 0)

def test_dist_id_not_found(self):
url = "{0}?distId={1}".format(url_for('api.upcoming.unschedule'), 2000)
response = self.client.post(url)
assert_equal(response.status_code, 404)

def test_dist_id_invalid(self):
url = "{0}?distId={1}".format(url_for('api.upcoming.unschedule'), 'bad_data')
response = self.client.post(url)
assert_equal(response.status_code, 404)

def test_no_dist_id(self):
response = self.client.post(url_for('api.upcoming.unschedule'), 'bad_data')
assert_equal(response.status_code, 400)

0 comments on commit c484b98

Please sign in to comment.