import unittest
from nose_parameterized import parameterized

import os
import shutil

import cbsodata

datasets = [
    # '81252NED',
    # '82010NED',
    '80884ENG'
]

TEST_ENV = 'test_env'


class TestCBSOData(unittest.TestCase):

    @classmethod
    def setupClass(self):

        if not os.path.exists(TEST_ENV):
            os.makedirs(TEST_ENV)

    @classmethod
    def tearDownClass(self):
        shutil.rmtree(TEST_ENV)

    @parameterized.expand(datasets)
    def test_info(self, table_id):

        # testing
        info = cbsodata.get_info(table_id)

        self.assertIsInstance(info, dict)

    @parameterized.expand(datasets)
    def test_download(self, table_id):

        cbsodata.download_data(table_id)

    @parameterized.expand(datasets)
    def test_download_and_store(self, table_id):

        cbsodata.download_data(
            table_id,
            dir=os.path.join(TEST_ENV, table_id)
        )

        self.assertTrue(
            os.path.exists(
                os.path.join(TEST_ENV, table_id, 'TableInfos.json')
            )
        )

    @parameterized.expand(datasets)
    def test_get_data(self, table_id):

        cbsodata.get_data(table_id)

    @parameterized.expand(datasets)
    def test_info_values(self, table_id):

        info = cbsodata.get_info(table_id)

        # Check response is dict (not a list)
        self.assertIsInstance(info, dict)

        # Check required keys are available
        self.assertTrue('Description' in info.keys())
        self.assertTrue('ID' in info.keys())
        self.assertTrue('Identifier' in info.keys())

    def test_table_list(self):

        self.assertGreaterEqual(len(cbsodata.get_table_list()), 100)



@@ -1692,9 +1692,408 @@
 , 100)%0A%0A
+    def test_filters(self):%0A%0A        default_sel_filt = cbsodata.get_info('82070ENG')%5B'DefaultSelection'%5D%0A        filters_and_selections = default_sel_filt.split(%22&%22)%0A%0A        print (filters_and_selections%5B0%5D)%0A%0A        for fs in filters_and_selections:%0A            if fs.startswith('$filter='):%0A                filt = fs%5B8:%5D%0A%0A        print (filt)%0A%0A        cbsodata.get_data('82070ENG', filters=filt)
 %0A

add tests for filters.