def setUp(self):
     self.command = Command()
class XML_Import_Tests(CustomSettingsTestCase):

    new_settings = dict(
        INSTALLED_APPS=(
           'dingos',
        )
    )

    def setUp(self):
        self.command = Command()
 
    def common_import_delta(self, xml_file):
        """ Returns the resulting list of elements parsing a given XML file in IODEF format """

        @deltaCalc
        def t_import(*args,**kwargs):
            return self.command.handle(*args,**kwargs)


        (delta,result) = t_import(xml_file,
                                  identifier_ns_uri=None)
        #pp.pprint(delta)
        return delta

    def test_botnet_example_import(self,show_result=SHOW_RESULTS):
        expected = [('DataTypeNameSpace', 2),
                    ('Fact', 34),
                    ('FactDataType', 1),
                    ('FactTerm', 28),
                    ('FactTerm2Type', 28),
                    ('FactValue', 34),
                    ('Identifier', 1),
                    ('IdentifierNameSpace', 1),
                    ('InfoObject', 1),
                    ('InfoObject2Fact', 40),
                    ('InfoObjectFamily', 1),
                    ('InfoObjectType', 1),
                    ('NodeID', 40),
                    ('Revision', 1)]


        result = self.common_import_delta('tests/mocks/botnet_iodef.xml')

        if show_result:
            pp.pprint(result)
        else:
            self.assertEqual( expected, result )

    def test_scan_example(self,show_result=SHOW_RESULTS):
        expected = [ ('DataTypeNameSpace', 2),
                     ('Fact', 30),
                     ('FactDataType', 1),
                     ('FactTerm', 24),
                     ('FactTerm2Type', 24),
                     ('FactValue', 33),
                     ('Identifier', 1),
                     ('IdentifierNameSpace', 1),
                     ('InfoObject', 1),
                     ('InfoObject2Fact', 36),
                     ('InfoObjectFamily', 1),
                     ('InfoObjectType', 1),
                     ('NodeID', 36),
                     ('Revision', 1)]
        result = self.common_import_delta('tests/mocks/scan_iodef.xml')

        if show_result:
            pp.pprint(result)
        else:
            self.assertEqual( expected, result )


    def test_worm_example(self,show_result=SHOW_RESULTS):
        expected =  [ ('DataTypeNameSpace', 3),
                      ('Fact', 32),
                      ('FactDataType', 3),
                      ('FactTerm', 28),
                      ('FactTerm2Type', 28),
                      ('FactValue', 31),
                      ('Identifier', 1),
                      ('IdentifierNameSpace', 1),
                      ('InfoObject', 1),
                      ('InfoObject2Fact', 32),
                      ('InfoObjectFamily', 1),
                      ('InfoObjectType', 1),
                      ('NodeID', 32),
                      ('Revision', 1)]

        result = self.common_import_delta('tests/mocks/worm_iodef.xml')

        if show_result:
            pp.pprint(result)
        else:
            self.assertEqual( expected, result )