How to use the census.tests.CensusTestCase function in census

To help you get started, we’ve selected a few census examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github datamade / census / census / tests.py View on Github external
}


class CensusTestCase(unittest.TestCase):

    def setUp(self):
        self._client = Census(KEY)

    def client(self, name):
        return getattr(self._client, name)

    def tearDown(self):
        self._client.session.close()


class TestDataDefinitions(CensusTestCase):

    def test_valid_json(self):

        with closing(requests.Session()) as http:

            http.headers = {
                'User-Agent': ('python-census/{}/tests '.format(__version__) +
                               'github.com/sunlightlabs/census')
            }

            for name, datasets in DEFINITIONS.items():
                for year, url in datasets.items():
                    resp = http.head(url)
                    self.assertEqual(resp.status_code, 200)
github datamade / census / census / tests.py View on Github external
client = self.client('acs1dp')
        self.assertRaises(UnsupportedYearException,
                          client.state, ('NAME', '06'))

    def test_sf1(self):
        client = self.client('sf1')
        self.assertRaises(UnsupportedYearException,
                          client.state, ('NAME', '06'))

    def test_sf3(self):
        client = self.client('sf3')
        self.assertRaises(UnsupportedYearException,
                          client.state, ('NAME', '06'))


class TestEndpoints(CensusTestCase):

    def check_endpoints(self, client_name, tests, **kwargs):

        if kwargs:
            tests = ((k, kwargs.get(k, v)) for k, v in tests)

        client = self.client(client_name)
        fields = ('NAME',)

        for method_name, expected in tests:

            msg = '{}.{}'.format(client_name, method_name)

            method = getattr(client, method_name)
            data = method(fields, **TEST_DATA)
            self.assertTrue(data, msg)
github datamade / census / census / tests.py View on Github external
def test_valid_json(self):

        with closing(requests.Session()) as http:

            http.headers = {
                'User-Agent': ('python-census/{}/tests '.format(__version__) +
                               'github.com/sunlightlabs/census')
            }

            for name, datasets in DEFINITIONS.items():
                for year, url in datasets.items():
                    resp = http.head(url)
                    self.assertEqual(resp.status_code, 200)


class TestDefaultYears(CensusTestCase):

    def test_default_year_is_supported(self):

        for client_name, method_names in CLIENTS:
            client = self.client(client_name)
            for method_name in method_names:
                method = getattr(client, method_name)
                self.assertIn(client.default_year, method.supported_years)


# class TestSupportedYears(CensusTestCase):
#
#     def test_acs5(self):
#         pass
github datamade / census / census / tests.py View on Github external
def test_default_year_is_supported(self):

        for client_name, method_names in CLIENTS:
            client = self.client(client_name)
            for method_name in method_names:
                method = getattr(client, method_name)
                self.assertIn(client.default_year, method.supported_years)


# class TestSupportedYears(CensusTestCase):
#
#     def test_acs5(self):
#         pass


class TestUnsupportedYears(CensusTestCase):

    def setUp(self):
        self._client = Census(KEY, year=2008)

    def test_acs5(self):
        client = self.client('acs5')
        self.assertRaises(UnsupportedYearException,
                          client.state, ('NAME', '06'))

    def test_acs1dp(self):
        client = self.client('acs1dp')
        self.assertRaises(UnsupportedYearException,
                          client.state, ('NAME', '06'))

    def test_sf1(self):
        client = self.client('sf1')