Exemplo n.º 1
0
    def test_range(self):
        """
        Test scheduling range
        """
        scheduled_dt = self.insert_distro()

        # found when queried at exactly the same time
        dists = get_scheduled_distributions(1, scheduled_dt)
        assert_equal(1, len(dists))

        # found within 2 minutes of scheduled time + 1 minute
        dists = get_scheduled_distributions(2, scheduled_dt + timedelta(minutes=1))
        assert_equal(1, len(dists))

        # not found when query is after scheduled time
        dists = get_scheduled_distributions(1, scheduled_dt - timedelta(seconds=30))
        assert_equal(0, len(dists))

        # larger range check
        base_dt = datetime(2015, 1, 1, 0, 0)
        schedule_dt = base_dt - timedelta(minutes=5)
        self.insert_distro(dt=schedule_dt)

        # ran looking for distributions from 23:50 up until 00:05
        dists = get_scheduled_distributions(15, base_dt + timedelta(minutes=5))
        assert_equal(1, len(dists))
Exemplo n.º 2
0
    def test_range(self):
        """
        Test scheduling range
        """
        scheduled_dt = self.insert_distro()

        # found when queried at exactly the same time
        dists = get_scheduled_distributions(1, scheduled_dt)
        assert_equal(1, len(dists))

        # found within 2 minutes of scheduled time + 1 minute
        dists = get_scheduled_distributions(
            2, scheduled_dt + timedelta(minutes=1))
        assert_equal(1, len(dists))

        # not found when query is after scheduled time
        dists = get_scheduled_distributions(
            1, scheduled_dt - timedelta(seconds=30))
        assert_equal(0, len(dists))

        # larger range check
        base_dt = datetime(2015, 1, 1, 0, 0)
        schedule_dt = base_dt - timedelta(minutes=5)
        self.insert_distro(dt=schedule_dt)

        # ran looking for distributions from 23:50 up until 00:05
        dists = get_scheduled_distributions(15, base_dt + timedelta(minutes=5))
        assert_equal(1, len(dists))
Exemplo n.º 3
0
 def test_unschedule(self):
     """
     Simple Unschedule
     """
     dt = self.insert_distro()
     dist = get_scheduled_distributions(1, dt)[0]
     unschedule_distribution(dist.id)
     dists = get_scheduled_distributions(1, dt)
     assert_equal(0, len(dists))
Exemplo n.º 4
0
 def test_unschedule(self):
     """
     Simple Unschedule
     """
     dt = self.insert_distro()
     dist = get_scheduled_distributions(1, dt)[0]
     unschedule_distribution(dist.id)
     dists = get_scheduled_distributions(1, dt)
     assert_equal(0, len(dists))
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
 def test_get_present(self):
     """
     Test scheduled within 1 minute
     """
     self.insert_distro(dt=datetime.utcnow())
     dists = get_scheduled_distributions(1)
     assert_equal(1, len(dists))
Exemplo n.º 8
0
 def test_get_present(self):
     """
     Test scheduled within 1 minute
     """
     self.insert_distro(dt=datetime.utcnow())
     dists = get_scheduled_distributions(1)
     assert_equal(1, len(dists))
Exemplo n.º 9
0
    def test_schedule_future(self):
        now = datetime.utcnow() + timedelta(hours=5)
        now_ts = calendar.timegm(now.timetuple())

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

        # no scheduled distros
        dists = get_scheduled_distributions(1, now)
        assert_equal(0, len(dists))

        response = self.client.post(url, data=self.sample_tile_data)
        assert_equal(response.status_code, 200)
        # count is 5: 4 images and one distribution file
        assert_equal(5, self.key_mock.set_contents_from_string.call_count)

        # scheduled distros now
        dists = get_scheduled_distributions(1, now)
        assert_equal(1, len(dists))
Exemplo n.º 10
0
    def test_invalid_minutes(self):
        with assert_raises(ValueError):
            get_scheduled_distributions(0)

        with assert_raises(ValueError):
            get_scheduled_distributions(-1)

        with assert_raises(ValueError):
            get_scheduled_distributions(None)
Exemplo n.º 11
0
    def test_invalid_minutes(self):
        """
        Test scheduled invalid
        """
        with assert_raises(ValueError):
            get_scheduled_distributions(0)

        with assert_raises(ValueError):
            get_scheduled_distributions(-1)

        with assert_raises(ValueError):
            get_scheduled_distributions(None)
Exemplo n.º 12
0
def deploy_scheduled(console_out, deploy_flag, leniency, verbose, quiet, *args,
                     **kwargs):
    """
    Find scheduled distributions and deploy
    """
    if verbose:
        logger = setup_command_logger(logging.DEBUG)
    elif quiet:
        logger = setup_command_logger(logging.ERROR)
    else:
        logger = setup_command_logger(logging.INFO)

    from splice.queries import get_scheduled_distributions, unschedule_distribution
    import requests

    dt = datetime.utcnow()
    distributions = get_scheduled_distributions(leniency, dt)
    logger.info("{0} - found {1} distributions".format(dt, len(distributions)))

    dist_data = []
    for dist in distributions:
        logger.info("fetching {0}".format(dist.url))
        r = requests.get(dist.url)
        if r.status_code == 200:
            dist_data.append((r.json(), dist.channel_id, dist.id))
        else:
            logger.error("FETCH_ERROR status_code:{0} url:{1}".format(
                r.status_code, dist.url))

    from splice.ingest import ingest_links, distribute, IngestError

    if deploy_flag:
        for rawdata, channel_id, dist_id in dist_data:
            try:
                new_data = ingest_links(rawdata, channel_id)

                if console_out:
                    print json.dumps(new_data, sort_keys=True, indent=2)

                distribute(new_data, channel_id, deploy_flag)
                unschedule_distribution(dist_id)
            except IngestError, e:
                raise InvalidCommand(e.message)
            except:
Exemplo n.º 13
0
def deploy_scheduled(console_out, deploy_flag, leniency, verbose, quiet, *args, **kwargs):
    """
    Find scheduled distributions and deploy
    """
    if verbose:
        logger = setup_command_logger(logging.DEBUG)
    elif quiet:
        logger = setup_command_logger(logging.ERROR)
    else:
        logger = setup_command_logger(logging.INFO)

    from splice.queries import get_scheduled_distributions, unschedule_distribution
    import requests

    dt = datetime.utcnow()
    distributions = get_scheduled_distributions(leniency, dt)
    logger.info("{0} - found {1} distributions".format(dt, len(distributions)))

    dist_data = []
    for dist in distributions:
        logger.info("fetching {0}".format(dist.url))
        r = requests.get(dist.url)
        if r.status_code == 200:
            dist_data.append((r.json(), dist.channel_id, dist.id))
        else:
            logger.error("FETCH_ERROR status_code:{0} url:{1}".format(r.status_code, dist.url))

    from splice.ingest import ingest_links, distribute, IngestError

    if deploy_flag:
        for rawdata, channel_id, dist_id in dist_data:
            try:
                new_data = ingest_links(rawdata, channel_id)

                if console_out:
                    print json.dumps(new_data, sort_keys=True, indent=2)

                distribute(new_data, channel_id, deploy_flag)
                unschedule_distribution(dist_id)
            except IngestError, e:
                raise InvalidCommand(e.message)
            except:
Exemplo n.º 14
0
 def test_get_present(self):
     self.insert_distro(datetime.utcnow())
     dists = get_scheduled_distributions(1)
     assert_equal(1, len(dists))