Example #1
0
    def test_gets_correct_collection(self, mock_get_collection):
        """
        make sure this operation uses the correct collection
        """
        utils.get_updated_since(time.time())

        mock_get_collection.assert_called_once_with()
Example #2
0
    def test_gets_correct_collection(self, mock_get_collection):
        """
        make sure this operation uses the correct collection
        """
        utils.get_updated_since(time.time())

        mock_get_collection.assert_called_once_with()
Example #3
0
    def test_empty_result(self, mock_query):
        mock_query.return_value = []
        now = time.time()

        ret = list(utils.get_updated_since(now))

        self.assertEqual(mock_query.call_count, 1)

        self.assertEqual(len(ret), 0)
Example #4
0
    def test_empty_result(self, mock_query):
        mock_query.return_value = []
        now = time.time()

        ret = list(utils.get_updated_since(now))

        self.assertEqual(mock_query.call_count, 1)

        self.assertEqual(len(ret), 0)
Example #5
0
    def test_query(self, mock_query):
        mock_query.return_value = SCHEDULES

        now = time.time()
        ret = list(utils.get_updated_since(now))

        self.assertEqual(mock_query.call_count, 1)
        # there should only be 1 argument, a criteria
        self.assertEqual(len(mock_query.call_args[0]), 1)
        criteria = mock_query.call_args[0][0]
        self.assertTrue(isinstance(criteria, Criteria))
        self.assertEqual(criteria.filters['last_updated'], {'$gt': now})
        self.assertEqual(criteria.filters['enabled'], True)

        # three instances of dict should be returned
        self.assertEqual(len(ret), 3)
        for schedule in ret:
            self.assertTrue(isinstance(schedule, dict))
Example #6
0
    def test_query(self, mock_query):
        mock_query.return_value = SCHEDULES

        now = time.time()
        ret = list(utils.get_updated_since(now))

        self.assertEqual(mock_query.call_count, 1)
        # there should only be 1 argument, a criteria
        self.assertEqual(len(mock_query.call_args[0]), 1)
        criteria = mock_query.call_args[0][0]
        self.assertTrue(isinstance(criteria, Criteria))
        self.assertEqual(criteria.filters['last_updated'], {'$gt': now})
        self.assertEqual(criteria.filters['enabled'], True)

        # three instances of dict should be returned
        self.assertEqual(len(ret), 3)
        for schedule in ret:
            self.assertTrue(isinstance(schedule, dict))
Example #7
0
    def schedule_changed(self):
        """
        Looks at the update timestamps in the database to determine if there
        are new or modified schedules.

        Indexing should make this very fast.

        :return:    True iff the set of enabled scheduled calls has changed
                    in the database.
        :rtype:     bool
        """
        if utils.get_enabled().count() != self._loaded_from_db_count:
            logging.debug(_('number of enabled schedules has changed'))
            return True

        if utils.get_updated_since(self._most_recent_timestamp).count() > 0:
            logging.debug(_('one or more enabled schedules has been updated'))
            return True

        return False
Example #8
0
    def schedule_changed(self):
        """
        Looks at the update timestamps in the database to determine if there
        are new or modified schedules.

        Indexing should make this very fast.

        :return:    True iff the set of enabled scheduled calls has changed
                    in the database.
        :rtype:     bool
        """
        if utils.get_enabled().count() != self._loaded_from_db_count:
            logging.debug(_('number of enabled schedules has changed'))
            return True

        if utils.get_updated_since(self._most_recent_timestamp).count() > 0:
            logging.debug(_('one or more enabled schedules has been updated'))
            return True

        return False