def test_numpy_dict(self):
     obj = dict(t=1, j=numpy.array([[0, 1], [1, 2], [3, 5]]))
     js = json_dumps(obj)
     obj2 = json_loads(js)
     self.assertIsInstance(obj2, dict)
     self.assertIn('j', obj2)
     self.assertEqualArray(obj['j'], obj2['j'])
示例#2
0
    def test_dummy_error(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        bodyin = json_dumps({'X': [0.1, 0.2, 0.3]})
        body = self.simulate_post('/', body=bodyin)
        self.assertEqual(body.status, falcon.HTTP_400)
        d = json_loads(body.content)
        self.assertIn('Unable to predict', d['title'])
        self.assertIn('X has 3 features per sample; expecting 2', d['title'])
        self.assertIn('.py', d['description'])
示例#3
0
    def test_dummy_app(self):
        fLOG(
            __file__,
            self._testMethodName,
            OutputPrint=__name__ == "__main__")

        bodyin = json_dumps({'X': [0.1, 0.2]})
        body = self.simulate_post('/', body=bodyin)
        self.assertEqual(body.status, falcon.HTTP_201)
        d = json_loads(body.content)
        self.assertTrue('Y' in d)
        self.assertIsInstance(d['Y'], (list, numpy.ndarray))
        self.assertEqual(len(d['Y']), 1)
        self.assertEqual(len(d['Y'][0]), 3)
 def test_dummy_app_auth(self):
     client = self.get_client_api()
     bodyin = json_dumps({'X': [0.1, 0.2]})
     body = client.simulate_post('/', body=bodyin, protocol='http')
     self.assertIn("HTTPS Required", str(body.content))
     self.assertEqual(body.status, falcon.HTTP_400)
     body = client.simulate_post('/', body=bodyin, protocol='https')
     self.assertIn("Missing Authorization Header", str(body.content))
     self.assertEqual(body.status, falcon.HTTP_401)
     zoo = base64.b64encode("me:dummy".encode('utf-8')).decode('utf-8')
     body = client.simulate_post(path='/',
                                 body=bodyin,
                                 protocol='https',
                                 headers=dict(Authorization="Basic " + zoo))
     self.assertIn(body.status, (falcon.HTTP_200, falcon.HTTP_201))
     d = json_loads(body.content)
     self.assertTrue('Y' in d)
     self.assertIsInstance(d['Y'], (list, numpy.ndarray))
     self.assertEqual(len(d['Y']), 1)
     self.assertEqual(len(d['Y'][0]), 3)
    def test_dummy_app_logging_nosecret(self):
        temp = get_temp_folder(__file__, 'temp_dummy_app_logging_nosecret')
        self.app = dummy_application(secret=None, folder=temp)

        bodyin = json_dumps({'X': [0.1, 0.2]})
        result = self.simulate_post('/', body=bodyin)
        self.assertEqual(result.status, falcon.HTTP_201)
        d = json_loads(result.content)
        self.assertTrue('Y' in d)
        self.assertIsInstance(d['Y'], (list, numpy.ndarray))
        self.assertEqual(len(d['Y']), 1)
        self.assertEqual(len(d['Y'][0]), 3)
        res = list(enumerate_parsed_logs(temp, secret=None))
        self.assertEqual(len(res), 2)
        for r in res:
            self.assertIn('dt', r)
            self.assertIn('code', r)
            self.assertIn('data', r)
        for _ in range(0, 10):
            result = self.simulate_post('/', body=bodyin)
            self.assertEqual(result.status, falcon.HTTP_201)
 def test_dummy_error(self):
     client = self.get_client_api()
     bodyin = json_dumps({'X': [0.1, 0.2, 0.3]})
     body = client.simulate_request(path='/',
                                    method="POST",
                                    body=bodyin,
                                    protocol='http')
     self.assertIn("HTTPS Required", str(body.content))
     body = client.simulate_post('/', body=bodyin, protocol='https')
     self.assertIn("Missing Authorization Header", str(body.content))
     self.assertEqual(body.status, falcon.HTTP_401)
     zoo = base64.b64encode("me:dummy".encode('utf-8')).decode('utf-8')
     body = client.simulate_post('/',
                                 body=bodyin,
                                 protocol='https',
                                 headers=dict(Authorization="Basic " + zoo))
     self.assertEqual(body.status, falcon.HTTP_400)
     d = json_loads(body.content)
     self.assertIn('Unable to predict', d['title'])
     self.assertIn('X has 3 features per sample; expecting 2', d['title'])
     self.assertIn('.py', d['description'])
 def test_numpy(self):
     obj = numpy.array([[0, 1], [1, 2], [3, 5]])
     js = json_dumps(obj)
     obj2 = json_loads(js)
     self.assertEqualArray(obj, obj2)
 def test_dict(self):
     obj = dict(a=1, b='g')
     js = json_dumps(obj)
     obj2 = json_loads(js)
     self.assertEqual(obj, obj2)