Beispiel #1
0
 def setUp(self):
     super().setUp()
     config.NITF_MAPPING = self.mapping
     dirname = os.path.dirname(os.path.realpath(__file__))
     fixture = os.path.normpath(os.path.join(dirname, '../fixtures', self.filename))
     provider = {'name': 'Test'}
     with open(fixture) as f:
         self.nitf = f.read()
         self.item = NITFFeedParser().parse(etree.fromstring(self.nitf), provider)
Beispiel #2
0
 def setUp(self):
     config.NITF_MAPPING = self.mapping
     dirname = os.path.dirname(os.path.realpath(__file__))
     fixture = os.path.normpath(
         os.path.join(dirname, "../fixtures", self.filename))
     provider = {"name": "Test"}
     with open(fixture, "rb") as f:
         self.nitf = f.read()
         self.item = NITFFeedParser().parse(etree.fromstring(self.nitf),
                                            provider)
Beispiel #3
0
class MappingTestCase(TestCase):

    filename = 'mapping_test.xml'
    mapping = {
        'subject': {
            'update': True,
            'key_hook': lambda item, value: item.setdefault('subject', []).extend(value)
        },
        'subject_test': {
            'callback': lambda _: ['TEST OK'],
            'key_hook': lambda item, value: item.setdefault('subject', []).extend(value)
        },
    }

    def setUp(self):
        config.NITF_MAPPING = self.mapping
        dirname = os.path.dirname(os.path.realpath(__file__))
        fixture = os.path.normpath(os.path.join(dirname, '../fixtures', self.filename))
        provider = {'name': 'Test'}
        with open(fixture) as f:
            self.nitf = f.read()
            self.item = NITFFeedParser().parse(etree.fromstring(self.nitf), provider)

    def test_update_and_hook(self):
        subjects = self.item.get('subject')
        # have we got both items ?
        self.assertEqual(len(subjects), 2)
        # the initial updated subject need to be here
        self.assertIn({'qcode': '02000000', 'name': 'Kriminalitet og rettsvesen'}, subjects)
        # and our key from subject_test need to be here too
        self.assertIn('TEST OK', subjects)

    def tearDown(self):
        del config.NITF_MAPPING
Beispiel #4
0
class MappingTestCase(TestCase):

    filename = 'mapping_test.xml'
    mapping = {
        'subject': {'update': True,
                    'key_hook': lambda item, value: item.setdefault('subject', []).extend(value)
                    },
        'subject_test': {'callback': lambda _: ['TEST OK'],
                         'key_hook': lambda item, value: item.setdefault('subject', []).extend(value)
                         }, }

    def setUp(self):
        super().setUp()
        config.NITF_MAPPING = self.mapping
        dirname = os.path.dirname(os.path.realpath(__file__))
        fixture = os.path.normpath(os.path.join(dirname, '../fixtures', self.filename))
        provider = {'name': 'Test'}
        with open(fixture) as f:
            self.nitf = f.read()
            self.item = NITFFeedParser().parse(etree.fromstring(self.nitf), provider)

    def test_update_and_hook(self):
        subjects = self.item.get('subject')
        # have we got both items ?
        self.assertEqual(len(subjects), 2)
        # the initial updated subject need to be here
        self.assertIn({'qcode': '02000000', 'name': 'Kriminalitet og rettsvesen'}, subjects)
        # and our key from subject_test need to be here too
        self.assertIn('TEST OK', subjects)

    def tearDown(self):
        super().tearDown()
        del config.NITF_MAPPING
Beispiel #5
0
 def setUp(self):
     config.NITF_MAPPING = self.mapping
     dirname = os.path.dirname(os.path.realpath(__file__))
     fixture = os.path.normpath(os.path.join(dirname, '../fixtures', self.filename))
     provider = {'name': 'Test'}
     with open(fixture) as f:
         self.nitf = f.read()
         self.item = NITFFeedParser().parse(etree.fromstring(self.nitf), provider)
Beispiel #6
0
 def setUp(self):
     super().setUp()
     with self.app.app_context():
         self.app.data.insert('vocabularies', self.vocab)
     dirname = os.path.dirname(os.path.realpath(__file__))
     fixture = os.path.normpath(os.path.join(dirname, '../fixtures', self.filename))
     provider = {'name': 'Test'}
     with open(fixture) as f:
         self.nitf = f.read()
         self.item = NITFFeedParser().parse(etree.fromstring(self.nitf), provider)
Beispiel #7
0
 def test_get_subjects_with_invalid_qcode(self):
     xml = ('<?xml version="1.0" encoding="UTF-8"?>'
            '<nitf><head>'
            '<tobject tobject.type="News">'
            '<tobject.property tobject.property.type="Current" />'
            '<tobject.subject tobject.subject.refnum="00000000" '
            'tobject.subject.type="Justice" tobject.subject.matter="Police" />'
            '</tobject></head></nitf>')
     subjects = NITFFeedParser().get_subjects(etree.fromstring(xml))
     self.assertEqual(len(subjects), 0)
Beispiel #8
0
 def setUp(self):
     with self.app.app_context():
         self.app.data.insert("vocabularies", self.vocab)
     dirname = os.path.dirname(os.path.realpath(__file__))
     fixture = os.path.normpath(
         os.path.join(dirname, "../fixtures", self.filename))
     provider = {"name": "Test"}
     with open(fixture, "rb") as f:
         self.nitf = f.read()
         self.item = NITFFeedParser().parse(etree.fromstring(self.nitf),
                                            provider)
Beispiel #9
0
 def test_get_subjects(self):
     xml = ('<?xml version="1.0" encoding="UTF-8"?>'
            '<nitf><head>'
            '<tobject tobject.type="News">'
            '<tobject.property tobject.property.type="Current" />'
            '<tobject.subject tobject.subject.refnum="02003000" '
            'tobject.subject.type="Justice" tobject.subject.matter="Police" />'
            '</tobject></head></nitf>')
     subjects = NITFFeedParser().get_subjects(etree.fromstring(xml))
     self.assertEqual(len(subjects), 2)
     self.assertIn({'qcode': '02000000', 'name': 'Justice'}, subjects)
     self.assertIn({'qcode': '02003000', 'name': 'Police'}, subjects)
Beispiel #10
0
 def test_get_subjects(self):
     xml = (
         b'<?xml version="1.0" encoding="UTF-8"?>'
         b"<nitf><head>"
         b'<tobject tobject.type="News">'
         b'<tobject.property tobject.property.type="Current" />'
         b'<tobject.subject tobject.subject.refnum="02003000" '
         b'tobject.subject.type="Justice" tobject.subject.matter="Police" />'
         b"</tobject></head></nitf>")
     subjects = NITFFeedParser().get_subjects(etree.fromstring(xml))
     self.assertEqual(len(subjects), 2)
     self.assertIn({"qcode": "02000000", "name": "Justice"}, subjects)
     self.assertIn({"qcode": "02003000", "name": "Police"}, subjects)
Beispiel #11
0
    def setUp(self):
        super().setUp()
        # we need to prepopulate vocabularies to get qcodes
        voc_file = os.path.join(os.path.abspath(os.path.dirname(settings.__file__)), "data/vocabularies.json")
        VocabulariesPopulateCommand().run(voc_file)

        # settings are needed in order to get into account NITF_MAPPING
        for key in dir(settings):
            if key.isupper():
                setattr(config, key, getattr(settings, key))
        dirname = os.path.dirname(os.path.realpath(__file__))
        fixture = os.path.normpath(os.path.join(dirname, '../fixtures', self.filename))
        provider = {'name': 'Test'}
        with open(fixture) as f:
            self.nitf = f.read()
            self.item = NITFFeedParser().parse(etree.fromstring(self.nitf), provider)
Beispiel #12
0
class MappingTestCase(TestCase):

    filename = "mapping_test.xml"
    mapping = {
        "subject": {
            "update":
            True,
            "key_hook":
            lambda item, value: item.setdefault("subject", []).extend(value)
        },
        "subject_test": {
            "callback":
            lambda _: ["TEST OK"],
            "key_hook":
            lambda item, value: item.setdefault("subject", []).extend(value),
        },
    }

    def setUp(self):
        config.NITF_MAPPING = self.mapping
        dirname = os.path.dirname(os.path.realpath(__file__))
        fixture = os.path.normpath(
            os.path.join(dirname, "../fixtures", self.filename))
        provider = {"name": "Test"}
        with open(fixture, "rb") as f:
            self.nitf = f.read()
            self.item = NITFFeedParser().parse(etree.fromstring(self.nitf),
                                               provider)

    def test_update_and_hook(self):
        subjects = self.item.get("subject")
        # have we got both items ?
        self.assertEqual(len(subjects), 2)
        # the initial updated subject need to be here
        self.assertIn(
            {
                "qcode": "02000000",
                "name": "Kriminalitet og rettsvesen"
            }, subjects)
        # and our key from subject_test need to be here too
        self.assertIn("TEST OK", subjects)

    def tearDown(self):
        del config.NITF_MAPPING
class NTBTestCase(XMLParserTestCase):

    filename = 'nitf_test.xml'
    parser = NITFFeedParser()

    def test_subject_update(self):
        self.assertEqual(len(self.item.get('subject')), 4)

    def test_category(self):
        self.assertIn({
            'qcode': 'Sport',
            'name': 'Sport',
            'scheme': 'category'
        }, self.item.get('subject'))

    def test_genre(self):
        self.assertEqual(self.item.get('genre'), [{
            'qcode': 'Tabeller og resultater',
            'name': 'Tabeller og resultater',
            'scheme': 'genre_custom'
        }])

    def test_slugline(self):
        self.assertEqual(self.item.get('slugline'), "NU-FLASH-K")

    def test_subject(self):
        self.assertIn(
            {
                'qcode': '15000000',
                'name': 'Sport',
                'scheme': 'subject_custom'
            }, self.item.get('subject'))
        self.assertIn(
            {
                'qcode': '15073031',
                'name': 'Nasjonal toppliga',
                'scheme': 'subject_custom',
                'parent': '15000000'
            }, self.item.get('subject'))
        self.assertIn(
            {
                'qcode': '15054000',
                'name': 'Fotball',
                'scheme': 'subject_custom',
                'parent': '15000000'
            }, self.item.get('subject'))

    def test_abstract(self):
        self.assertEqual(self.item.get('abstract'), ABSTRACT)

    def test_body_html(self):
        self.assertNotIn(ABSTRACT, self.item.get('body_html'))

    def test_keywords(self):
        self.assertNotIn('keywords', self.item)
        self.assertEqual(self.item.get('guid'), self.item.get('uri'))

    def test_service(self):
        self.assertEqual(self.item.get('anpa_category'), [{
            'qcode': 'n',
            'name': 'Nyhetstjenesten',
            'language': 'nb-NO'
        }])

    def test_priority(self):
        self.assertEqual(self.item.get('priority'), 3)