Merge "Fix Scale-up issue in HWLB"
[yardstick.git] / tests / unit / apiserver / __init__.py
1 from __future__ import absolute_import
2
3 import os
4 import socket
5 import unittest
6 import tempfile
7
8 from oslo_serialization import jsonutils
9
10 from yardstick.common import constants as consts
11
12
13 class APITestCase(unittest.TestCase):
14
15     def setUp(self):
16         self.db_fd, self.db_path = tempfile.mkstemp()
17         consts.SQLITE = 'sqlite:///{}'.format(self.db_path)
18
19         try:
20             from api import server
21         except socket.gaierror:
22             self.app = None
23             return
24
25         server.app.config['TESTING'] = True
26         self.app = server.app.test_client()
27
28         server.init_db()
29
30     def tearDown(self):
31         os.close(self.db_fd)
32         os.unlink(self.db_path)
33
34     def _post(self, url, data):
35         headers = {'Content-Type': 'application/json'}
36         resp = self.app.post(url, data=jsonutils.dumps(data), headers=headers)
37         return jsonutils.loads(resp.data)
38
39     def _get(self, url):
40         resp = self.app.get(url)
41         return jsonutils.loads(resp.data)