Example #1
0
    def test_add_lifestage_model(self,get_g,m_ls):
        self.make_grass_mock(get_g.return_value)
        # Assume no appropriate files in tmp
        c = config.get_config()
        m = ModelRepository(self.temp_dir)
        m2 = ModelRepository()
        a_file = m2.get_models()['lifestage_test']

        self.create_mock_location(self.temp_dir)
        self.assertEqual(len(m.get_models()), 0)
        # add location to model, save as new
        dm = DispersalModel(a_file)
        dm.set_location('grass_location')
        temp_model_fn = os.path.join(os.path.dirname(a_file),"with_location_model.xml")
        dm.save_model(filename=temp_model_fn)

        get_g.return_value.get_range.return_value = [ 'xxxxxx10' ] * 10
        get_g.return_value.raster_value_freq.return_value = [ [1],[2],[3] ]
        m_ls.return_value = {}

        # and then try to add
        m.add_model(temp_model_fn) 
        self.assertEqual(len(m.get_models()), 1)
        # more tests about lifestage resources?
        self.remove_mock_location(self.temp_dir)
    def test_add_lifestage_model(self, get_g, m_ls):
        self.make_grass_mock(get_g.return_value)
        # Assume no appropriate files in tmp
        c = config.get_config()
        m = ModelRepository(self.temp_dir)
        m2 = ModelRepository()
        a_file = m2.get_models()['lifestage_test']

        self.create_mock_location(self.temp_dir)
        self.assertEqual(len(m.get_models()), 0)
        # add location to model, save as new
        dm = DispersalModel(a_file)
        dm.set_location('grass_location')
        temp_model_fn = os.path.join(os.path.dirname(a_file),
                                     "with_location_model.xml")
        dm.save_model(filename=temp_model_fn)

        get_g.return_value.get_range.return_value = ['xxxxxx10'] * 10
        get_g.return_value.raster_value_freq.return_value = [[1], [2], [3]]
        m_ls.return_value = {}

        # and then try to add
        m.add_model(temp_model_fn)
        self.assertEqual(len(m.get_models()), 1)
        # more tests about lifestage resources?
        self.remove_mock_location(self.temp_dir)
Example #3
0
 def test_submit_model_missing_files(self):
     import tempfile
     fn = self.repo.get_models()['lifestage_test']
     dm = DispersalModel(fn)
     temp_fn = tempfile.mktemp(suffix='.xml')
     dm.set_name('lifestage_test2')
     dm.set_location('grass_location')
     dm.save_model(temp_fn)
     f= open(temp_fn)
     import os.path
     r = self.postmultipart('/models/',fields={},files=[('new_model',temp_fn,f.read())])
     f.close()
     os.remove(temp_fn)
     self.assertTrue('error' in r['body'])
     self.assertTrue('lifestage_test2' not in self.repo.get_models())
Example #4
0
 def test_submit_model_already_exists(self):
     import tempfile
     fn = self.repo.get_models()['variables']
     dm = DispersalModel(fn)
     temp_fn = tempfile.mktemp(suffix='.xml')
     dm.set_location('grass_location')
     dm.save_model(temp_fn)
     f= open(temp_fn)
     import os.path
     count=len(self.repo.get_models())
     self.postmultipart('/models/',fields={},files=[('new_model',temp_fn,f.read())])
     f.close()
     os.remove(temp_fn)
     self.assertEqual(count,len(self.repo.get_models()))
     self.assertTrue('variables' in self.repo.get_models())
Example #5
0
 def test_submit_model(self):
     import tempfile
     fn = self.repo.get_models()['variables']
     dm = DispersalModel(fn)
     temp_fn = tempfile.mktemp(suffix='.xml')
     dm.set_name('variable_test')
     dm.set_location('grass_location')
     dm.save_model(temp_fn)
     f= open(temp_fn)
     import os.path
     self.postmultipart('/models/',fields={},files=[('new_model',temp_fn,f.read())])
     f.close()
     os.remove(temp_fn)
     self.assertTrue('variable_test' in self.repo.get_models())
     r = self.urlopen('/models/variable_test/del',method='POST')
Example #6
0
 def test_add_model_to_repo(self):
     import tempfile
     fn = self.repo.get_models()['variables']
     dm = DispersalModel(fn)
     temp_fn = tempfile.mktemp(suffix='.xml')
     dm.set_name('variable_test')
     dm.set_location('grass_location')
     dm.save_model(temp_fn)
     f = open(temp_fn,'r')
     data = f.read()
     f.close()
     webui.add_model_to_repo(data)
     os.remove(temp_fn)
     self.assertTrue('variable_test' in self.repo.get_models())
     self.repo.remove_model('variable_test',force=True)
Example #7
0
 def test_add_and_delete_model(self):
     import tempfile
     fn = self.repo.get_models()['variables']
     dm = DispersalModel(fn)
     temp_fn = tempfile.mktemp(suffix='.xml')
     dm.set_name('variable_test')
     dm.set_location('grass_location')
     dm.save_model(temp_fn)
     f = open(temp_fn,'r')
     data = f.read()
     f.close()
     webui.add_model_to_repo(data)
     os.remove(temp_fn)
     self.assertTrue('variable_test' in self.repo.get_models())
     r = self.urlopen('/models/variable_test/del',method='POST')
     self.assertEqual(r['code'],303)
     self.assertTrue('variable_test' not in self.repo.get_models())
Example #8
0
    def test_lifestage_model_missing_files(self,get_g):
        self.make_grass_mock(get_g.return_value)
        # Assume no appropriate files in tmp
        c = config.get_config()
        m = ModelRepository(self.temp_dir)
        m2 = ModelRepository()
        a_file = m2.get_models()['lifestage_test']

        self.create_mock_location(self.temp_dir)
        self.assertEqual(len(m.get_models()), 0)
        # add location to model, save as new
        dm = DispersalModel(a_file)
        dm.set_location('grass_location')
        temp_model_fn = os.path.join(self.temp_dir,"with_location_model.xml")
        dm.save_model(filename=temp_model_fn)

        # and then try to add
        self.assertRaises(mdig.modelrepository.RepositoryException,m.add_model,temp_model_fn) 
        self.assertEqual(len(m.get_models()), 0)
        # more tests about lifestage resources?
        self.remove_mock_location(self.temp_dir)
    def test_lifestage_model_missing_files(self, get_g):
        self.make_grass_mock(get_g.return_value)
        # Assume no appropriate files in tmp
        c = config.get_config()
        m = ModelRepository(self.temp_dir)
        m2 = ModelRepository()
        a_file = m2.get_models()['lifestage_test']

        self.create_mock_location(self.temp_dir)
        self.assertEqual(len(m.get_models()), 0)
        # add location to model, save as new
        dm = DispersalModel(a_file)
        dm.set_location('grass_location')
        temp_model_fn = os.path.join(self.temp_dir, "with_location_model.xml")
        dm.save_model(filename=temp_model_fn)

        # and then try to add
        self.assertRaises(mdig.modelrepository.RepositoryException,
                          m.add_model, temp_model_fn)
        self.assertEqual(len(m.get_models()), 0)
        # more tests about lifestage resources?
        self.remove_mock_location(self.temp_dir)
Example #10
0
        try:
            self.remove_mock_location(self.temp_dir)
        except OSError, e:
            stre = str(e)
            if 'No such file' not in stre and \
                'system cannot find the path specified' not in stre:
                raise e
        m2 = ModelRepository()
        a_file = m2.get_models()['variables']
        self.create_mock_location(self.temp_dir)

        # Add location to model
        dm = DispersalModel(a_file)
        dm.set_location('grass_location')
        temp_model_fn = "with_location_model.xml"
        dm.save_model(filename=temp_model_fn)

        m.add_model(temp_model_fn)
        self.assertEqual(len(m.get_models()), 1)
        m.remove_model('variables',force=True)
        self.assertEqual(get_g.return_value.remove_mapset.call_args[0][0], 'variables')
        os.remove(temp_model_fn)

        self.assertRaises(mdig.modelrepository.RepositoryException,m.remove_model,'non_existant')
        self.remove_mock_location(self.temp_dir)

    @patch('mdig.grass.get_g')
    @patch('__builtin__.raw_input')
    def remove_other_test(self,m_in,get_g):
        self.make_grass_mock(get_g.return_value)
        # Assume no appropriate files in tmp
Example #11
0
        try:
            self.remove_mock_location(self.temp_dir)
        except OSError, e:
            stre = str(e)
            if 'No such file' not in stre and \
                'system cannot find the path specified' not in stre:
                raise e
        m2 = ModelRepository()
        a_file = m2.get_models()['variables']
        self.create_mock_location(self.temp_dir)

        # Add location to model
        dm = DispersalModel(a_file)
        dm.set_location('grass_location')
        temp_model_fn = "with_location_model.xml"
        dm.save_model(filename=temp_model_fn)

        m.add_model(temp_model_fn)
        self.assertEqual(len(m.get_models()), 1)
        m.remove_model('variables', force=True)
        self.assertEqual(get_g.return_value.remove_mapset.call_args[0][0],
                         'variables')
        os.remove(temp_model_fn)

        self.assertRaises(mdig.modelrepository.RepositoryException,
                          m.remove_model, 'non_existant')
        self.remove_mock_location(self.temp_dir)

    @patch('mdig.grass.get_g')
    @patch('__builtin__.raw_input')
    def remove_other_test(self, m_in, get_g):