Esempio n. 1
0
class MeasureXMLParserTest(TestCase):

    def setUp(self):
        filepath = os.path.join(
            os.path.dirname(__file__),
            "test_data/test_measure.xml")
        self.parser = MeasureXMLParser(filepath)
        self.measure_objects = self.parser.parse("Waternet")

    def test_parse(self):
        measure_objects = self.parser.parse("HHNK")
        self.assertTrue(len(measure_objects) == 0)
        measure_objects = self.parser.parse("Waternet")
        self.assertTrue(len(measure_objects) == 2)

    def test_identificatie(self):
        matident = self.measure_objects[0].identificatie.matident
        land = self.measure_objects[0].identificatie.land
        waterschapid = self.measure_objects[0].identificatie.waterschapid
        self.assertTrue(matident == "90886")
        self.assertTrue(land == "NL")
        self.assertTrue(waterschapid == "11")

    def test_omschrijving(self):
        omschrijving = self.measure_objects[0].omschrijving
        self.assertTrue(omschrijving == 'Aanleggen natuurvriendelijke oevers')

    def test_waarde(self):
        waarde1 = self.measure_objects[0].waarde
        waarde2 = self.measure_objects[1].waarde
        self.assertTrue(waarde1 == "3")
        self.assertTrue(waarde2 is None)

    def test_typemaatregel(self):
        """Test parsing typemaatregel xml element."""
        code = "IN07"
        measure_type = testmodels.MeasureTypeF.build()
        measure_type.code = code
        type_maatregel = self.measure_objects[0].typeMaatregel.code
        self.assertTrue(type_maatregel == code)
        measure_model_obj = self.measure_objects[0].typeMaatregel.modelObject
        self.assertTrue(measure_model_obj.code == code)

    def test_kostendatatype(self):
        kosten = self.measure_objects[0].maatregelKostenDatatype.kostenGrondverwerving
        self.assertTrue(kosten == 0)

    def test_initielekostendrager(self):
        naam = "Hoogheemraadschap Amstel Gooi en Vecht"
        kostendrager = self.measure_objects[0].initieleKostendrager
        self.assertTrue(kostendrager.naam == naam)

    def test_parse_geldenvoorwaterbeheergebiede(self):
        mat1_gebieden = self.measure_objects[0].geldenVoorWaterbeheerGebied.gebieden
        mat2_gebieden = self.measure_objects[1].geldenVoorWaterbeheerGebied.gebieden
        self.assertTrue(len(mat1_gebieden) == 2)
        self.assertTrue(len(mat2_gebieden) == 1)
    def handle(self, *args, **options):
        rel_path = 'import_krw_portaal/import_krw_portaal_new/Maatregelen_v2.xml'
        measure_filepath = os.path.join(settings.BUILDOUT_DIR, rel_path)
        logger.info(
            'Importing KRW portaal xml files from %s.', measure_filepath)
        action = options.get('action')
        dataset_name = options.get('dataset_name')

        if action != "insert" and action != "update":
            logger.error('Unknown action {}, see --help'.format(action))
            return

        if dataset_name is None:
            logger.error('Unknown data_set, see --help')
            return

        parser = MeasureXMLParser(measure_filepath)
        krw_measures = parser.parse(dataset_name)
        if action == "insert":
            self.insert(krw_measures)