示例#1
0
    def test_post_lgjson(self):

        c = RestClient("localhost", lgweb_port, timeout=10)

        # new graphs cannot currently be added
        form_data = {
            "lg_name": "new.graph",
            "lg_content": '{"id": 1, "name": "example"}',
            "rmode": "1",
        }
        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.graph")
        copy_fname = tempfile.mktemp()
        shutil.copy(original_fname, copy_fname)

        try:
            form_data["lg_name"] = "logical_graphs/chiles_simple.graph"
            c._post_form("/jsonbody", form_data)
            new = c._get_json("/jsonbody?lg_name=logical_graphs/chiles_simple.graph")
            self.assertIsNotNone(new)
            self.assertIn("id", new)
            self.assertIn("name", new)
            self.assertEqual(1, new["id"])
            self.assertEqual("example", new["name"])
            self.assertEqual("1", new["reprodata"]["rmode"])
        finally:
            shutil.move(copy_fname, original_fname)
示例#2
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)