def test_missing_elements(self):
        """Test if we can get missing elements correctly."""
        # Copy the inasafe template to temp dir
        template_path = os.path.join(
            temp_dir('test'), 'inasafe-portrait-a4.qpt')
        shutil.copy2(INASAFE_TEMPLATE_PATH, template_path)

        template_composition = TemplateComposition(template_path=template_path)
        # No missing elements here
        component_ids = ['safe-logo', 'north-arrow', 'organisation-logo',
                         'impact-map', 'impact-legend']
        template_composition.component_ids = component_ids
        message = 'There should be no missing elements, but it gets: %s' % (
            template_composition.missing_elements)
        expected_result = []
        self.assertEqual(
            template_composition.missing_elements, expected_result, message)

        # There are missing elements
        component_ids = ['safe-logo', 'north-arrow', 'organisation-logo',
                         'impact-map', 'impact-legend',
                         'i-added-element-id-here-nooo']
        template_composition.component_ids = component_ids
        message = 'There should be no missing elements, but it gets: %s' % (
            template_composition.missing_elements)
        expected_result = ['i-added-element-id-here-nooo']
        self.assertEqual(
            template_composition.missing_elements, expected_result, message)

        # Remove test dir
        shutil.rmtree(temp_dir('test'))
示例#2
0
    def test_missing_elements(self):
        """Test if we can get missing elements correctly."""
        # Copy the inasafe template to temp dir
        template_path = os.path.join(temp_dir('test'), 'a4-portrait-blue.qpt')
        shutil.copy2(INASAFE_TEMPLATE_PATH, template_path)

        template_composition = TemplateComposition(template_path=template_path)
        # No missing elements here
        component_ids = [
            'white-inasafe-logo', 'north-arrow', 'organisation-logo',
            'impact-map', 'impact-legend'
        ]
        template_composition.component_ids = component_ids
        message = 'There should be no missing elements, but it gets: %s' % (
            template_composition.missing_elements)
        expected_result = []
        self.assertEqual(template_composition.missing_elements,
                         expected_result, message)

        # There are missing elements
        component_ids = [
            'white-inasafe-logo', 'north-arrow', 'organisation-logo',
            'impact-map', 'impact-legend', 'i-added-element-id-here-nooo'
        ]
        template_composition.component_ids = component_ids
        message = 'There should be no missing elements, but it gets: %s' % (
            template_composition.missing_elements)
        expected_result = ['i-added-element-id-here-nooo']
        self.assertEqual(template_composition.missing_elements,
                         expected_result, message)

        # Remove test dir
        shutil.rmtree(temp_dir('test'))
    def test_load_template(self):
        """Test we can load template correctly."""
        # Copy the inasafe template to temp dir
        template_path = os.path.join(
            temp_dir('test'), 'a4-portrait-blue.qpt')
        shutil.copy2(INASAFE_TEMPLATE_PATH, template_path)

        template_composition = TemplateComposition(
            template_path=template_path,
            map_settings=CANVAS.mapSettings())
        template_composition.load_template()

        # Check the element of the composition
        # In that template, there should be these components:
        component_ids = [
            'white-inasafe-logo',
            'north-arrow',
            'organisation-logo',
            'impact-map',
            'impact-legend']
        for component_id in component_ids:
            component = template_composition.composition.getComposerItemById(
                component_id)
            message = ('In this template: %s, there should be this component '
                       '%s') % (INASAFE_TEMPLATE_PATH, component_id)
            self.assertIsNotNone(component, message)
示例#4
0
    def test_load_template(self):
        """Test we can load template correctly."""
        # Copy the inasafe template to temp dir
        template_path = os.path.join(temp_dir('test'), 'a4-portrait-blue.qpt')
        shutil.copy2(INASAFE_TEMPLATE_PATH, template_path)

        template_composition = TemplateComposition(
            template_path=template_path, map_settings=CANVAS.mapSettings())
        template_composition.load_template()

        # Check the element of the composition
        # In that template, there should be these components:
        component_ids = [
            'white-inasafe-logo', 'north-arrow', 'organisation-logo',
            'impact-map', 'impact-legend'
        ]
        for component_id in component_ids:
            component = template_composition.composition.getComposerItemById(
                component_id)
            message = ('In this template: %s, there should be this component '
                       '%s') % (INASAFE_TEMPLATE_PATH, component_id)
            self.assertIsNotNone(component, message)
    def test_check_aggregation(self):
        """Test for keywords dialog's behavior for aggregation layer."""
        layer = clone_shp_layer(
            name='district_osm_jakarta',
            include_keywords=True,
            source_directory=test_data_path('boundaries'))
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)

        # Load existing keywords
        keywords = dialog.get_keywords()
        expected_keywords = {
            u'category': u'postprocessing',
            u'aggregation attribute': u'KAB_NAME',
            u'title': u'D\xedstr\xedct\'s of Jakarta',
            u'elderly ratio attribute': u'Global default',
            u'youth ratio default': u'0.26',
            u'elderly ratio default': u'0.08',
            u'adult ratio attribute': u'Global default',
            u'female ratio attribute': u'PEREMPUAN',
            u'youth ratio attribute': u'Global default',
            u'adult ratio default': u'0.66'}
        message = 'Expected %s but I got %s' % (expected_keywords, keywords)
        self.assertDictEqual(expected_keywords, keywords, message)

        # Check age ratios are valid
        good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords)
        message = 'Expected %s but I got %s' % (True, good_sum_ratio)
        self.assertEqual(True, good_sum_ratio, message)

        # Change youth ratio attribute to Don't Use
        dialog.cboYouthRatioAttribute.setCurrentIndex(1)
        keywords = dialog.get_keywords()
        expected_keywords = {
            u'category': u'postprocessing',
            u'aggregation attribute': u'KAB_NAME',
            u'title': u'D\xedstr\xedct\'s of Jakarta',
            u'elderly ratio attribute': u'Global default',
            u'elderly ratio default': u'0.08',
            u'adult ratio attribute': u'Global default',
            u'female ratio attribute': u'PEREMPUAN',
            u'youth ratio attribute': u'Don\'t use',
            u'adult ratio default': u'0.66'}
        message = 'Expected %s but I got %s' % (expected_keywords, keywords)
        self.assertDictEqual(expected_keywords, keywords, message)

        good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords)
        message = 'Expected %s but I got %s' % (True, good_sum_ratio)
        self.assertEqual(True, good_sum_ratio, message)

        # Change youth ratio attribute to Global Default
        # Change youth ratio default to 0.99
        dialog.cboYouthRatioAttribute.setCurrentIndex(0)
        dialog.dsbYouthRatioDefault.setValue(0.99)
        keywords = dialog.get_keywords()
        expected_keywords = {
            u'category': u'postprocessing',
            u'aggregation attribute': u'KAB_NAME',
            u'title': u'D\xedstr\xedct\'s of Jakarta',
            u'elderly ratio attribute': u'Global default',
            u'elderly ratio default': u'0.08',
            u'adult ratio attribute': u'Global default',
            u'female ratio attribute': u'PEREMPUAN',
            u'youth ratio attribute': u'Global default',
            u'youth ratio default': u'0.99',
            u'adult ratio default': u'0.66'}
        message = 'Expected %s but I got %s' % (expected_keywords, keywords)
        self.assertDictEqual(expected_keywords, keywords, message)

        good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords)
        message = 'Expected %s but I got %s' % (False, good_sum_ratio)
        self.assertEqual(False, good_sum_ratio, message)

        # We need to delete reference to layer on Windows before removing
        # the files
        del layer
        del dialog.layer
        # Using clone_shp_layer the files are saved in testing dir under
        # InaSAFE temp dir
        shutil.rmtree(temp_dir(sub_dir='testing'))
示例#6
0
    def test_check_aggregation(self):
        """Test for keywords dialog's behavior for aggregation layer."""
        layer = clone_shp_layer(name='district_osm_jakarta',
                                include_keywords=True,
                                source_directory=test_data_path('boundaries'))
        dialog = KeywordsDialog(PARENT, IFACE, layer=layer)

        # Load existing keywords
        keywords = dialog.get_keywords()
        expected_keywords = {
            u'category': u'postprocessing',
            u'aggregation attribute': u'KAB_NAME',
            u'title': u'D\xedstr\xedct\'s of Jakarta',
            u'elderly ratio attribute': u'Global default',
            u'youth ratio default': u'0.26',
            u'elderly ratio default': u'0.08',
            u'adult ratio attribute': u'Global default',
            u'female ratio attribute': u'PEREMPUAN',
            u'youth ratio attribute': u'Global default',
            u'adult ratio default': u'0.66'
        }
        message = 'Expected %s but I got %s' % (expected_keywords, keywords)
        self.assertDictEqual(expected_keywords, keywords, message)

        # Check age ratios are valid
        good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords)
        message = 'Expected %s but I got %s' % (True, good_sum_ratio)
        self.assertEqual(True, good_sum_ratio, message)

        # Change youth ratio attribute to Don't Use
        dialog.cboYouthRatioAttribute.setCurrentIndex(1)
        keywords = dialog.get_keywords()
        expected_keywords = {
            u'category': u'postprocessing',
            u'aggregation attribute': u'KAB_NAME',
            u'title': u'D\xedstr\xedct\'s of Jakarta',
            u'elderly ratio attribute': u'Global default',
            u'elderly ratio default': u'0.08',
            u'adult ratio attribute': u'Global default',
            u'female ratio attribute': u'PEREMPUAN',
            u'youth ratio attribute': u'Don\'t use',
            u'adult ratio default': u'0.66'
        }
        message = 'Expected %s but I got %s' % (expected_keywords, keywords)
        self.assertDictEqual(expected_keywords, keywords, message)

        good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords)
        message = 'Expected %s but I got %s' % (True, good_sum_ratio)
        self.assertEqual(True, good_sum_ratio, message)

        # Change youth ratio attribute to Global Default
        # Change youth ratio default to 0.99
        dialog.cboYouthRatioAttribute.setCurrentIndex(0)
        dialog.dsbYouthRatioDefault.setValue(0.99)
        keywords = dialog.get_keywords()
        expected_keywords = {
            u'category': u'postprocessing',
            u'aggregation attribute': u'KAB_NAME',
            u'title': u'D\xedstr\xedct\'s of Jakarta',
            u'elderly ratio attribute': u'Global default',
            u'elderly ratio default': u'0.08',
            u'adult ratio attribute': u'Global default',
            u'female ratio attribute': u'PEREMPUAN',
            u'youth ratio attribute': u'Global default',
            u'youth ratio default': u'0.99',
            u'adult ratio default': u'0.66'
        }
        message = 'Expected %s but I got %s' % (expected_keywords, keywords)
        self.assertDictEqual(expected_keywords, keywords, message)

        good_sum_ratio, _ = dialog.age_ratios_are_valid(keywords)
        message = 'Expected %s but I got %s' % (False, good_sum_ratio)
        self.assertEqual(False, good_sum_ratio, message)

        # We need to delete reference to layer on Windows before removing
        # the files
        del layer
        del dialog.layer
        # Using clone_shp_layer the files are saved in testing dir under
        # InaSAFE temp dir
        shutil.rmtree(temp_dir(sub_dir='testing'))