Example #1
0
    def test_get_site_model_too_many_site_models(self):
        haz_calc = self._create_haz_calc()

        site_model_inp1 = models.Input(
            owner=haz_calc.owner, digest='fake', path='fake',
            input_type='site_model', size=0
        )
        site_model_inp1.save()
        site_model_inp2 = models.Input(
            owner=haz_calc.owner, digest='fake', path='fake',
            input_type='site_model', size=0
        )
        site_model_inp2.save()

        # link both site models to the calculation:
        models.Input2hcalc(
            input=site_model_inp1, hazard_calculation=haz_calc).save()
        models.Input2hcalc(
            input=site_model_inp2, hazard_calculation=haz_calc).save()

        with self.assertRaises(RuntimeError) as assert_raises:
            general.get_site_model(haz_calc.id)

        self.assertEqual('Only 1 site model per job is allowed, found 2.',
                         assert_raises.exception.message)
Example #2
0
    def test_get_site_model(self):
        haz_calc = self._create_haz_calc()

        site_model_inp = models.Input(
            owner=haz_calc.owner, digest='fake', path='fake',
            input_type='site_model', size=0
        )
        site_model_inp.save()

        # The link has not yet been made in the input2haz_calc table.
        self.assertIsNone(general.get_site_model(haz_calc.id))

        # Complete the link:
        models.Input2hcalc(
            input=site_model_inp, hazard_calculation=haz_calc).save()

        actual_site_model = general.get_site_model(haz_calc.id)
        self.assertEqual(site_model_inp, actual_site_model)