Ejemplo n.º 1
0
    def test_get_quick_num_or_link(self):
        """
        Make sure the proper exceptions are raised when the input
        is bad and that the proper data is returned wheninput is good.
        """

        # For testing dict keys
        a = {'text': 'Foobar', 'number': '773-702-8740', 'link': None}
        b = {'label': 'Foobar', 'link': None}

        # For testing dict key -> values
        c = {'label': '', 'number': '773-702-8740', 'link': None}
        d = {'label': 'Foobar', 'number': '773-702-8740', 'link': '/'}

        # For testing return values
        e = {'label': 'Foobar', 'number': '773-702-8740', 'link': None}
        f = {'label': 'Foobar', 'number': '', 'link': PUBLIC_HOMEPAGE}
        g = {'label': 'Foobar', 'number': '', 'link': None}

        # Test dict keys
        self.assertTrue(assert_assertion_error(get_quick_num_or_link, a))
        self.assertTrue(assert_assertion_error(get_quick_num_or_link, b))

        # Test dict key -> values
        self.assertTrue(assert_assertion_error(get_quick_num_or_link, c))
        self.assertTrue(assert_assertion_error(get_quick_num_or_link, d))

        # Test return values
        self.assertEqual(
            get_quick_num_or_link(e), (0, 'Foobar', '773-702-8740')
        )
        self.assertEqual(get_quick_num_or_link(f), (1, 'Foobar', '/'))
        self.assertRaises(ValueError, get_quick_num_or_link, g)
Ejemplo n.º 2
0
    def test_assert_assertion_error(self):
        """
        Should return True when a function throws an AssertionError.
        If no AssertionError is raised by the function that was passed,
        it should throw an AssertionError of its own.
        """

        # Should return True
        self.assertTrue(t.assert_assertion_error(foo, 2))

        # Should throw an AssertionError
        try:
            self.assertTrue(t.assert_assertion_error(foo, -2))
        except (AssertionError):
            pass

        # Should throw an AssertionError
        try:
            self.assertTrue(t.assert_assertion_error(foo, {'bar': 1}))
        except (AssertionError):
            pass
Ejemplo n.º 3
0
    def test_assert_assertion_error(self):
        """
        Should return True when a function throws an AssertionError.
        If no AssertionError is raised by the function that was passed,
        it should throw an AssertionError of its own.
        """

        # Should return True
        self.assertTrue(t.assert_assertion_error(foo, 2))

        # Should throw an AssertionError
        try:
            self.assertTrue(t.assert_assertion_error(foo, -2))
        except(AssertionError):
            pass

        # Should throw an AssertionError
        try:
            self.assertTrue(t.assert_assertion_error(foo, {'bar':1}))
        except(AssertionError):
            pass
Ejemplo n.º 4
0
    def test_get_quick_nums_for_library_or_dept_with_bad_config(self):
        """
        Bad dictionary missing a required key, should throw an assertion error.
        """
        client = Client()
        site = Site.objects.filter(is_default_site=True)[0]
        response = client.get('/about/directory/?view=staff&department=Voyager', HTTP_HOST=site.hostname) # Must stay outside of the context manager

        with self.settings(QUICK_NUMS = {
                'voyager':
                    self.dlist,
                'enterprise':
                    [{'label': 'Captain Picard',    'number': '11100', 'link': None},
                     {'label': 'Worf Rozhenko',     'number': '00001', 'link': None},
                     {'label': 'Data',              'number': '10111', 'link': None}],
            }):

            request = response.wsgi_request
            self.assertTrue(assert_assertion_error(get_quick_nums_for_library_or_dept, request))