コード例 #1
0
ファイル: tests.py プロジェクト: OskarPersson/ESSArch
    def test_with_content_type_file(self):
        backend = xml.XMLReceiptBackend()
        Path.objects.create(entity='temp')

        ip = InformationPackage.objects.create(
            object_path=self.datadir,
            package_type=InformationPackage.AIP,
        )
        ProfileIP.objects.create(ip=ip,
                                 profile=Profile.objects.create(
                                     profile_type='aip',
                                     structure=[{
                                         'name':
                                         'cts.xml',
                                         'use':
                                         'content_type_specification',
                                     }]))

        tag_version = TagVersion.objects.create(
            tag=Tag.objects.create(information_package=ip),
            type=TagVersionType.objects.create(name='foo'),
            reference_code="ABC 1234",
            elastic_index='index',
        )

        xml_file_content = """<?xml version="1.0" encoding="UTF-8"?>
        <ArkivobjektArende>
            <ArkivobjektID>ABC 1234</ArkivobjektID>
            <Arendemening>Makulerat</Arendemening>
            <EgnaElement>
                <EgetElement Namn="Recno">
                  <Varde>123456</Varde>
                </EgetElement>
            </EgnaElement>
        </ArkivobjektArende>
        """

        xml_file_path = os.path.join(self.datadir, 'cts.xml')
        with open(xml_file_path, 'w') as f:
            f.write(xml_file_content)

        dest_file_path = os.path.join(self.datadir, "dest_file.xml")

        backend.create(
            ip=ip,
            template="receipts/xml.json",
            destination=dest_file_path,
            outcome="outcome data",
            short_message="some short message",
            message="some longer message",
        )

        expected_attributes = {
            'id': str(tag_version.pk),
            'ArkivobjektID': 'ABC 1234',
            'Recno': '123456',
        }
        receipt = etree.parse(dest_file_path)
        el = receipt.xpath('//ärende')[0]
        self.assertEqual(el.attrib, expected_attributes)
コード例 #2
0
ファイル: tests.py プロジェクト: karatekaneen/ESSArch
    def test_with_no_ip_and_date_passed_should_create_xml(self):
        backend = xml.XMLReceiptBackend()
        dest_file_path = os.path.join(self.datadir, "dest_file.xml")

        datetime_now = datetime.datetime.now()

        backend.create(
            template="receipts/xml.json",
            destination=dest_file_path,
            outcome="outcome data",
            short_message="some short message",
            message="some longer message",
            date=datetime_now,
        )

        expected_attributes = {
            'outcome': 'outcome data',
            'message': 'some longer message'
        }

        root_xml = etree.parse(dest_file_path)
        status_el = root_xml.xpath("/receipt/status")[0]
        datetime_el = root_xml.xpath("/receipt/datetime")[0]

        self.assertEqual(status_el.attrib, expected_attributes)
        self.assertEqual(datetime_el.text, datetime_now.isoformat())
コード例 #3
0
ファイル: tests.py プロジェクト: OskarPersson/ESSArch
    def test_bad_template(self):
        backend = xml.XMLReceiptBackend()

        with self.assertRaises(TemplateDoesNotExist):
            backend.create(template="bad_template",
                           destination="some_destination",
                           outcome="outcome_data",
                           short_message="some_short_message",
                           message="some message nothuentohe notehu")
コード例 #4
0
ファイル: tests.py プロジェクト: karatekaneen/ESSArch
    def test_with_tasks_passed_should_be_added_to_xml(self):
        backend = xml.XMLReceiptBackend()
        task = self.create_task()
        validation = self.create_validation()
        validation.task = task
        validation.passed = True
        validation.save()

        dest_file_path = os.path.join(self.datadir, "dest_file.xml")

        backend.create(
            template="receipts/xml.json",
            destination=dest_file_path,
            outcome="outcome data",
            short_message="some short message",
            message="some longer message",
            task=task,
        )

        expected_status_attributes = {
            'outcome': 'outcome data',
            'message': 'some longer message'
        }

        expected_validation_attributes = {
            'passed': 'true'
        }

        root_xml = etree.parse(dest_file_path)
        status_el = root_xml.xpath("/receipt/status")[0]
        datetime_el = root_xml.xpath("/receipt/datetime")[0]
        validations_el = root_xml.xpath("/receipt/validations/validation")

        self.assertEqual(status_el.attrib, expected_status_attributes)
        self.assertIsNotNone(datetime_el.text)
        self.assertEqual(len(validations_el), 1)
        self.assertEqual(validations_el[0].attrib, expected_validation_attributes)