Пример #1
0
    def test_model_content_unknown_content_type(self):
        test_file = helpers.touch()

        params = dict(GMPE_LOGIC_TREE_FILE=test_file)
        engine._insert_input_files(params, self.job, True)

        [glt] = models.inputs4job(self.job.id, input_type="lt_gmpe")
        self.assertEqual('unknown', glt.model_content.content_type)
Пример #2
0
    def test_model_content_unknown_content_type(self):
        test_file = helpers.touch()

        params = dict(GMPE_LOGIC_TREE_FILE=test_file)
        engine._insert_input_files(params, self.job, True)

        [glt] = models.inputs4job(self.job.id, input_type="lt_gmpe")
        self.assertEqual('unknown', glt.model_content.content_type)
Пример #3
0
 def test__insert_input_files(self):
     # A new input record is inserted for the GMPE logic tree but the
     # existing input row is reused for the source model logic tree.
     engine._insert_input_files(self.PARAMS, self.job, False)
     [glt_i] = models.inputs4job(self.job.id, input_type="lt_gmpe")
     self.assertNotEqual(self.glt_i.id, glt_i.id)
     [slt_i] = models.inputs4job(self.job.id, input_type="lt_source")
     self.assertEqual(self.slt_i.id, slt_i.id)
Пример #4
0
    def test_model_content_single_file(self):
        # The contents of input files (such as logic trees, exposure models,
        # etc.) should be saved to the uiapi.model_content table.
        slt_path = os.path.join(self.PARAMS['BASE_PATH'], self.SLT)
        expected_content = open(slt_path, 'r').read()
        engine._insert_input_files(self.PARAMS, self.job, True)
        [slt] = models.inputs4job(self.job.id, input_type="lt_source")

        self.assertEqual('xml', slt.model_content.content_type)
        self.assertEqual(expected_content, slt.model_content.raw_content)
Пример #5
0
    def test_model_content_single_file(self):
        # The contents of input files (such as logic trees, exposure models,
        # etc.) should be saved to the uiapi.model_content table.

        expected_content = open(self.SLT, 'r').read()
        params = dict(SOURCE_MODEL_LOGIC_TREE_FILE=self.SLT)

        engine._insert_input_files(params, self.job, True)
        [slt] = models.inputs4job(self.job.id, input_type="lt_source")

        self.assertEqual('xml', slt.model_content.content_type)
        self.assertEqual(expected_content, slt.model_content.raw_content)
Пример #6
0
    def test_model_content_single_file(self):
        # The contents of input files (such as logic trees, exposure models,
        # etc.) should be saved to the uiapi.model_content table.

        expected_content = open(self.SLT, 'r').read()
        params = dict(SOURCE_MODEL_LOGIC_TREE_FILE=self.SLT)

        engine._insert_input_files(params, self.job, True)
        [slt] = models.inputs4job(self.job.id, input_type="lt_source")

        self.assertEqual('xml', slt.model_content.content_type)
        self.assertEqual(expected_content, slt.model_content.raw_content)
Пример #7
0
    def test_model_content_detect_content_type(self):
        # Test detection of the content type (using the file extension).
        test_file = helpers.touch(suffix=".html")

        # We use the gmpe logic tree as our test target because there is no
        # parsing required in the function under test. Thus, we can put
        # whatever test garbage we want in the file, or just use an empty file
        # (which is the case here).
        params = dict(GMPE_LOGIC_TREE_FILE=test_file)
        engine._insert_input_files(params, self.job, True)

        [glt] = models.inputs4job(self.job.id, input_type="lt_gmpe")
        self.assertEqual('html', glt.model_content.content_type)
Пример #8
0
    def test_model_content_many_files(self):
        slt_content = open(self.SLT, 'r').read()
        glt_content = open(self.GLT, 'r').read()

        engine._insert_input_files(self.PARAMS, self.job, True)
        [slt] = models.inputs4job(self.job.id, input_type="lt_source")
        [glt] = models.inputs4job(self.job.id, input_type="lt_gmpe")

        self.assertEqual('xml', slt.model_content.content_type)
        self.assertEqual(slt_content, slt.model_content.raw_content)

        self.assertEqual('xml', glt.model_content.content_type)
        self.assertEqual(glt_content, glt.model_content.raw_content)
Пример #9
0
    def test_model_content_detect_content_type(self):
        # Test detection of the content type (using the file extension).
        test_file = helpers.touch(suffix=".html")

        # We use the gmpe logic tree as our test target because there is no
        # parsing required in the function under test. Thus, we can put
        # whatever test garbage we want in the file, or just use an empty file
        # (which is the case here).
        params = dict(GMPE_LOGIC_TREE_FILE=test_file)
        engine._insert_input_files(params, self.job, True)

        [glt] = models.inputs4job(self.job.id, input_type="lt_gmpe")
        self.assertEqual('html', glt.model_content.content_type)
Пример #10
0
    def test_model_content_many_files(self):
        slt_content = open(self.SLT, 'r').read()
        glt_content = open(self.GLT, 'r').read()

        engine._insert_input_files(self.PARAMS, self.job, True)
        [slt] = models.inputs4job(self.job.id, input_type="lt_source")
        [glt] = models.inputs4job(self.job.id, input_type="lt_gmpe")

        self.assertEqual('xml', slt.model_content.content_type)
        self.assertEqual(slt_content, slt.model_content.raw_content)

        self.assertEqual('xml', glt.model_content.content_type)
        self.assertEqual(glt_content, glt.model_content.raw_content)
Пример #11
0
 def test__insert_input_files(self):
     # A new input record is inserted for the GMPE logic tree but the
     # existing input row is reused for the source model logic tree.
     engine._insert_input_files(self.PARAMS, self.job, False)
     [glt_i] = models.inputs4job(self.job.id, input_type="lt_gmpe")
     self.assertNotEqual(self.glt_i.id, glt_i.id)
     [slt_i] = models.inputs4job(self.job.id, input_type="lt_source")
     self.assertEqual(self.slt_i.id, slt_i.id)
     # Make sure the LT and the hazard source have been associated.
     [src_link] = models.Src2ltsrc.objects.filter(lt_src=slt_i)
     self.assertEqual("dissFaultModel.xml", src_link.filename)
     self.assertEqual(slt_i, src_link.lt_src)
     [hzrd_i] = models.inputs4job(self.job.id, input_type="source")
     self.assertEqual(hzrd_i, src_link.hzrd_src)
Пример #12
0
 def test__insert_input_files(self):
     # A new input record is inserted for the GMPE logic tree but the
     # existing input row is reused for the source model logic tree.
     engine._insert_input_files(self.PARAMS, self.job, False)
     [glt_i] = models.inputs4job(self.job.id, input_type="lt_gmpe")
     self.assertNotEqual(self.glt_i.id, glt_i.id)
     [slt_i] = models.inputs4job(self.job.id, input_type="lt_source")
     self.assertEqual(self.slt_i.id, slt_i.id)
     # Make sure the LT and the hazard source have been associated.
     [src_link] = models.Src2ltsrc.objects.filter(lt_src=slt_i)
     self.assertEqual("dissFaultModel.xml", src_link.filename)
     self.assertEqual(slt_i, src_link.lt_src)
     [hzrd_i] = models.inputs4job(self.job.id, input_type="source")
     self.assertEqual(hzrd_i, src_link.hzrd_src)