def test_upcoming_leniency(self): """ Tests fetching a distribution from the recent past using leniency """ schedule = datetime.utcnow() - timedelta(minutes=14) self.insert_distro(dt=schedule) # within leniency bounds dists = get_upcoming_distributions(leniency_minutes=15) assert_equal(1, len(dists[1])) assert_equal(schedule, dists[1][0]['scheduled_at']) # just outside of leniency bounds dists = get_upcoming_distributions(leniency_minutes=14) assert_equal({}, dists) # test multiple dists self.insert_distro() dists = get_upcoming_distributions(leniency_minutes=15) assert_equal(2, len(dists[1])) dists = get_upcoming_distributions(leniency_minutes=14) assert_equal(1, len(dists[1])) # leniency overriden if include_past is given dists = get_upcoming_distributions(leniency_minutes=1, include_past=True) assert_equal(2, len(dists[1]))
def test_upcoming_limits(self): """ Test limits """ distro_times = [self.insert_distro() for i in range(5)] dists = get_upcoming_distributions() assert_equal(5, len(dists[1])) dists = get_upcoming_distributions(limit=1) assert_equal(1, len(dists[1])) assert_equal(distro_times[0], dists[1][0]['scheduled_at'])
def init_data(): """ Initial data provided to the upcoming page """ dists = get_upcoming_distributions() chans = get_channels() return jsonify({'d': {'dists': dists, 'chans': chans, 'schema': schema, 'env': env.config.ENVIRONMENT}})
def distributions(): """ Obtain upcoming distributions """ limit = request.args.get('limit', 100) dists = get_upcoming_distributions(limit=limit) channels = get_channels() return jsonify({'d': {'dists': dists, 'chans': channels}})
def init_data(): """ Initial data provided to the upcoming page """ dists = get_upcoming_distributions() chans = get_channels() return jsonify({ 'd': {'dists': dists, 'chans': chans, 'schema': {"default": get_payload_schema(compact=False), "compact": get_payload_schema(compact=True)}, 'env': env.config.ENVIRONMENT}})
def test_distributions(self): self.insert_distro() response = self.client.get(url_for('api.upcoming.distributions')) dists = get_upcoming_distributions() chans = get_channels() # need to dump using the Flask json serializer to match types # for datetime etc expected = json.loads( json.dumps({'d': { 'dists': dists, 'chans': chans, }})) assert_equal(expected, response.json)
def test_channels(self): """ Test results with multiple channels """ schedule = datetime.utcnow() - timedelta(minutes=14) dist_scheds = { 1: self.insert_distro(channel_id=1, dt=schedule), 2: self.insert_distro(channel_id=2) } dists = get_upcoming_distributions(leniency_minutes=15) assert_equal(2, len(dists.keys())) for dist_id, c_dists in dists.iteritems(): assert_equal(1, len(c_dists)) assert_equal(dist_scheds[dist_id], c_dists[0]['scheduled_at'])
def test_distributions(self): self.insert_distro() response = self.client.get(url_for('api.upcoming.distributions')) dists = get_upcoming_distributions() chans = get_channels() # need to dump using the Flask json serializer to match types # for datetime etc expected = json.loads(json.dumps({ 'd': { 'dists': dists, 'chans': chans, } })) assert_equal(expected, response.json)
def init_data(): """ Initial data provided to the upcoming page """ dists = get_upcoming_distributions() chans = get_channels() return jsonify({ 'd': { 'dists': dists, 'chans': chans, 'schema': { "default": get_payload_schema(compact=False), "compact": get_payload_schema(compact=True) }, 'env': env.config.ENVIRONMENT } })
def test_upcoming_empty(self): """ Test when there is nothing to return """ dists = get_upcoming_distributions() assert_equal({}, dists)