Пример #1
0
    def test_parse_missing_requirement(self):
        limit_xml = '<limit class="FakeLimit"></limit>'
        limit_node = etree.fromstring(limit_xml)

        with warnings.catch_warnings(record=True) as w:
            with self.assertRaises(TypeError):
                limit = tools.parse_limit_node('db', 1, limit_node)

            self.assertEqual(len(w), 0)
Пример #2
0
    def test_parse_basic(self):
        limit_xml = """<limit class="FakeLimit">
    <attr name="required">spam</attr>
</limit>"""
        limit_node = etree.fromstring(limit_xml)

        with warnings.catch_warnings(record=True) as w:
            limit = tools.parse_limit_node('db', 1, limit_node)

            self.assertEqual(len(w), 0)

        self.assertIsInstance(limit, FakeLimit)
        self.assertEqual(limit.args, ('db',))
        self.assertEqual(limit.kwargs, dict(required='spam'))
Пример #3
0
    def test_parse_unknown_attr(self):
        limit_xml = """<limit class="FakeLimit">
    <attr name="unknown_attr">spam</attr>
    <attr name="required">spam</attr>
</limit>"""
        limit_node = etree.fromstring(limit_xml)

        with warnings.catch_warnings(record=True) as w:
            limit = tools.parse_limit_node('db', 1, limit_node)

            self.assertEqual(len(w), 1)
            self.assertIn("Limit at index 1 does not accept an attribute "
                          "'unknown_attr'; ignoring...", w[-1].message)

        self.assertIsInstance(limit, FakeLimit)
        self.assertEqual(limit.args, ('db',))
        self.assertEqual(limit.kwargs, dict(required='spam'))
Пример #4
0
    def test_parse_unknown_elem(self):
        limit_xml = """<limit class="FakeLimit">
    <attribute name="badelem">spam</attribute>
    <attr name="required">spam</attr>
</limit>"""
        limit_node = etree.fromstring(limit_xml)

        with warnings.catch_warnings(record=True) as w:
            limit = tools.parse_limit_node('db', 1, limit_node)

            self.assertEqual(len(w), 1)
            self.assertIn("Unrecognized element 'attribute' while parsing "
                          "limit at index 1; ignoring...", w[-1].message)

        self.assertIsInstance(limit, FakeLimit)
        self.assertEqual(limit.args, ('db',))
        self.assertEqual(limit.kwargs, dict(required='spam'))
Пример #5
0
    def test_parse_dict_attr(self):
        limit_xml = """<limit class="FakeLimit">
    <attr name="dict_attr">
        <value key="foo">spam</value>
        <value key="bar">ni</value>
    </attr>
    <attr name="required">spam</attr>
</limit>"""
        limit_node = etree.fromstring(limit_xml)

        with warnings.catch_warnings(record=True) as w:
            limit = tools.parse_limit_node('db', 1, limit_node)

            self.assertEqual(len(w), 0)

        self.assertIsInstance(limit, FakeLimit)
        self.assertEqual(limit.args, ('db',))
        self.assertEqual(limit.kwargs, dict(
                required='spam',
                dict_attr=dict(foo='spam', bar='ni'),
                ))
Пример #6
0
    def test_parse_dict_attr_missing_key(self):
        limit_xml = """<limit class="FakeLimit">
    <attr name="dict_attr">
        <value>spam</value>
        <value key="bar">ni</value>
    </attr>
    <attr name="required">spam</attr>
</limit>"""
        limit_node = etree.fromstring(limit_xml)

        with warnings.catch_warnings(record=True) as w:
            limit = tools.parse_limit_node('db', 1, limit_node)

            self.assertEqual(len(w), 1)
            self.assertIn("Missing 'key' attribute of 'value' element "
                          "while parsing 'dict_attr' attribute of limit "
                          "at index 1; ignoring...", w[-1].message)

        self.assertIsInstance(limit, FakeLimit)
        self.assertEqual(limit.args, ('db',))
        self.assertEqual(limit.kwargs, dict(
                required='spam',
                dict_attr=dict(bar='ni'),
                ))