Beispiel #1
0
    def test_post_lgjson(self):

        c = RestClient('localhost', lgweb_port, 10)

        # new graphs cannot currently be added
        form_data = {'lg_name': 'new.json', 'lg_content': '{"id": 1, "name": "example"}'}
        self.assertRaises(RestClientException, c._post_form, '/jsonbody', form_data)

        # Replace the contents of an existing one
        # (but replace it back with original after the test)
        original_fname = os.path.join(lg_dir, 'logical_graphs', 'chiles_simple.json')
        copy_fname = tempfile.mktemp()
        shutil.copy(original_fname, copy_fname)

        try:
            form_data['lg_name'] = 'logical_graphs/chiles_simple.json'
            c._post_form('/jsonbody', form_data)
            new = c._get_json('/jsonbody?lg_name=logical_graphs/chiles_simple.json')
            self.assertIsNotNone(new)
            self.assertIn('id', new)
            self.assertIn('name', new)
            self.assertEqual(1, new['id'])
            self.assertEqual('example', new['name'])
        finally:
            shutil.move(copy_fname, original_fname)
Beispiel #2
0
    def test_get_lgjson(self):

        c = RestClient('localhost', lgweb_port, 10)

        # a specific one
        lg = c._get_json('/jsonbody?lg_name=logical_graphs/chiles_simple.json')
        self.assertIsNotNone(lg)

        # by default the first one found by the lg_web should be returned
        lg = c._get_json('/jsonbody')
        self.assertIsNotNone(lg)

        # doesn't exist
        self.assertRaises(RestClientException, c._get_json, '/jsonbody?lg_name=doesnt_exist.json')
Beispiel #3
0
 def _request(self, url, method, content=None, headers={}):
     # Normalize first
     if not url.startswith('/'):
         url = '/' + url
     url = '/api' + url
     return RestClient._request(self,
                                url,
                                method,
                                content=content,
                                headers=headers)
Beispiel #4
0
    def test_gen_pgt(self):

        c = RestClient('localhost', lgweb_port, 10)

        # doesn't exist!
        self.assertRaises(RestClientException, c._GET, '/gen_pgt?lg_name=doesnt_exist.json&num_par=5&algo=metis&min_goal=0&ptype=0&max_load_imb=100')
        # unknown algorithm
        self.assertRaises(RestClientException, c._GET, '/gen_pgt?lg_name=logical_graphs/chiles_simple.json&num_par=5&algo=noidea')
        # this should work now
        self._generate_pgt(c)
Beispiel #5
0
    def test_get_pgtjson(self):

        c = RestClient('localhost', lgweb_port, 10)
        c._GET('/gen_pgt?lg_name=logical_graphs/chiles_simple.json&num_par=5&algo=metis&min_goal=0&ptype=0&max_load_imb=100')

        # doesn't exist
        self.assertRaises(RestClientException, c._get_json, '/pgt_jsonbody?pgt_name=unknown.json')
        # good!
        c._get_json('/pgt_jsonbody?pgt_name=logical_graphs/chiles_simple1_pgt.json')
Beispiel #6
0
    def test_load_lgeditor(self):

        c = RestClient('localhost', lgweb_port, 10)

        # doesn't exist
        self.assertRaises(RestClientException, c._get_json, '/lg_editor?lg_name=unknown.json')
        # Defaults to first LG
        c._GET('/lg_editor')
        # also fine, LG exists
        c._GET('/lg_editor?lg_name=logical_graphs/chiles_simple.json')
Beispiel #7
0
    def test_pg_viewer(self):

        c = RestClient('localhost', lgweb_port, 10)
        self._generate_pgt(c)

        # doesn't exist
        self.assertRaises(RestClientException, c._GET, '/pg_viewer?pgt_view_name=unknown.json')
        # Defaults to first PGT
        c._GET('/pg_viewer')
        # also fine, PGT exists
        c._GET('/pg_viewer?pgt_view_name=logical_graphs/chiles_simple1_pgt.json')
Beispiel #8
0
    def _test_pgt_action(self, path, unknown_fails):

        c = RestClient('localhost', lgweb_port, 10)
        self._generate_pgt(c)

        # doesn't exist
        if unknown_fails:
            self.assertRaises(RestClientException, c._GET, '/' + path + '?pgt_id=unknown.json')
        else:
            c._GET('/' + path + '?pgt_id=unknown.json')

        # exists
        c._GET('/' + path + '?pgt_id=logical_graphs/chiles_simple1_pgt.json')
Beispiel #9
0
 def createDataIsland(self, host):
     with RestClient(host=host,
                     port=constants.DAEMON_DEFAULT_REST_PORT,
                     timeout=10) as c:
         c._post_json('/managers/dataisland', bottle.request.body.read())
     self.dm.addDmHost(host)
Beispiel #10
0
 def _request(self, url, method, content=None, headers={}):
     # Normalize first
     if not url.startswith('/'):
         url = '/' + url
     url = '/api' + url
     return RestClient._request(self, url, method, content=content, headers=headers)
Beispiel #11
0
 def test_index(self):
     # Just check that the HTML pages load properly
     with RestClient(hostname, constants.NODE_DEFAULT_REST_PORT, 10) as c:
         c._GET('/')
         c._GET('/session')