<commit_before>import uuid

from qonos.common import exception
from qonos.common import utils as qonos_utils
from qonos.openstack.common import timeutils
from qonos.openstack.common import uuidutils
from qonos.tests import utils as utils
from qonos.tests.unit import utils as unit_utils


#NOTE(ameade): This is set in each individual db test module
db_api = None


class TestDBApi(utils.BaseTestCase):

    def setUp(self):
        super(TestDBApi, self).setUp()
        self.db_api = db_api

    def tearDown(self):
        super(TestDBApi, self).setUp()
        self.db_api.reset()

    def test_reset(self):
        fixture = {
            'tenant_id': str(uuid.uuid4()),
            'action': 'snapshot',
            'minute': '30',
            'hour': '2',
        }
        self.db_api.schedule_create(fixture)
        self.db_api.reset()
        self.assertFalse(self.db_api.schedule_get_all())


class TestSchedulesDBApi(utils.BaseTestCase):

    def setUp(self):
        super(TestSchedulesDBApi, self).setUp()
        self.db_api = db_api
        self._create_schedules()

    def tearDown(self):
        super(TestSchedulesDBApi, self).setUp()
        self.db_api.reset()

    def _create_schedules(self):
        fixture = {
            'tenant_id': str(uuid.uuid4()),
            'action': 'snapshot',
            'minute': 30,
            'hour': 2,
            'next_run': qonos_utils.cron_string_to_next_datetime(30, 2)
        }
        self.schedule_1 = self.db_api.schedule_create(fixture)
        fixture = {
            'tenant_id': str(uuid.uuid4()),
            'action': 'snapshot',
            'minute': 30,
            'hour': 3,
            'next_run': qonos_utils.cron_string_to_next_datetime(30, 3)
        }
        self.schedule_2 = self.db_api.schedule_create(fixture)

    def test_schedule_get_all(self):
        schedules = self.db_api.schedule_get_all()
        self.assertEqual(len(schedules), 2)

    def test_schedule_get_all_filter(self):
        filters = {}
        filters['next_run_after'] = self.schedule_1['next_run']
        filters['next_run_before'] = self.schedule_1['next_run']
        schedules = self.db_api.schedule_get_all(filter_args=filters)
        self.assertEqual(len(schedules), 1)

    def test_schedule_get_by_id(self):
        fixture = {<commit_msg>Improving schedule filter db api test<commit_after>import uuid

from qonos.common import exception
from qonos.common import utils as qonos_utils
from qonos.openstack.common import timeutils
from qonos.openstack.common import uuidutils
from qonos.tests import utils as utils
from qonos.tests.unit import utils as unit_utils


#NOTE(ameade): This is set in each individual db test module
db_api = None


class TestDBApi(utils.BaseTestCase):

    def setUp(self):
        super(TestDBApi, self).setUp()
        self.db_api = db_api

    def tearDown(self):
        super(TestDBApi, self).setUp()
        self.db_api.reset()

    def test_reset(self):
        fixture = {
            'tenant_id': str(uuid.uuid4()),
            'action': 'snapshot',
            'minute': '30',
            'hour': '2',
        }
        self.db_api.schedule_create(fixture)
        self.db_api.reset()
        self.assertFalse(self.db_api.schedule_get_all())


class TestSchedulesDBApi(utils.BaseTestCase):

    def setUp(self):
        super(TestSchedulesDBApi, self).setUp()
        self.db_api = db_api
        self._create_schedules()

    def tearDown(self):
        super(TestSchedulesDBApi, self).setUp()
        self.db_api.reset()

    def _create_schedules(self):
        fixture = {
            'tenant_id': str(uuid.uuid4()),
            'action': 'snapshot',
            'minute': 30,
            'hour': 2,
            'next_run': qonos_utils.cron_string_to_next_datetime(30, 2)
        }
        self.schedule_1 = self.db_api.schedule_create(fixture)
        fixture = {
            'tenant_id': str(uuid.uuid4()),
            'action': 'snapshot',
            'minute': 30,
            'hour': 3,
            'next_run': qonos_utils.cron_string_to_next_datetime(30, 3)
        }
        self.schedule_2 = self.db_api.schedule_create(fixture)

    def test_schedule_get_all(self):
        schedules = self.db_api.schedule_get_all()
        self.assertEqual(len(schedules), 2)

    def test_schedule_get_all_filter(self):
        filters = {}
        filters['next_run_after'] = self.schedule_1['next_run']
        filters['next_run_before'] = self.schedule_1['next_run']
        schedules = self.db_api.schedule_get_all(filter_args=filters)
        self.assertEqual(len(schedules), 1)
        self.assertEqual(schedules[0]['id'], self.schedule_1['id'])

    def test_schedule_get_by_id(self):
        fixture = {
{'fraction_non_alphanumeric': 0.11414654807285049, 'fraction_numerical': 0.010588733587462939, 'mean_word_length': 2.5943683409436833, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5879671', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1535, 'n_words': 277}