def test_model_content_unknown_content_type(self): test_file = helpers.touch() params = dict(GMPE_LOGIC_TREE_FILE=test_file, BASE_PATH='/') engine._insert_input_files(params, self.job, True) [glt] = models.inputs4job(self.job.id, input_type="gsim_logic_tree") self.assertEqual('unknown', glt.model_content.content_type)
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="source_model_logic_tree") self.assertEqual('xml', slt.model_content.content_type) self.assertEqual(expected_content, slt.model_content.raw_content)
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, BASE_PATH='/') engine._insert_input_files(params, self.job, True) [glt] = models.inputs4job(self.job.id, input_type="gsim_logic_tree") self.assertEqual('html', glt.model_content.content_type)
def test_model_content_many_files(self): slt_path = os.path.join(self.PARAMS['BASE_PATH'], self.SLT) slt_content = open(slt_path, 'r').read() glt_path = os.path.join(self.PARAMS['BASE_PATH'], self.GLT) glt_content = open(glt_path, 'r').read() engine._insert_input_files(self.PARAMS, self.job, True) [slt] = models.inputs4job(self.job.id, input_type="source_model_logic_tree") [glt] = models.inputs4job(self.job.id, input_type="gsim_logic_tree") 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)