From f5b6b6bf257be3f2a6eb52f8b8510a3b7ab42f3b Mon Sep 17 00:00:00 2001
From: Sebastian Lobinger <sebastian.lobinger@fu-berlin.de>
Date: Tue, 30 May 2017 13:44:38 +0200
Subject: [PATCH] add test_hub_provides_apps_with_proxies to test_sams_hub.py
 see #8

---
 test/test_sams_hub.py | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/test/test_sams_hub.py b/test/test_sams_hub.py
index ccecc99..4911dc1 100644
--- a/test/test_sams_hub.py
+++ b/test/test_sams_hub.py
@@ -1,12 +1,44 @@
-import unittest
+import unittest, requests
 from sams_classes import SAMSHub, SAMSApp
 from sams_classes.exceptions import AppNotExist
 from flask import Flask, Blueprint
-import sys
+import sys, time
+from .helper_classes import FlaskInThread
 
 def eprint(*args, **kwargs):
   print(*args, file=sys.stderr, **kwargs)
 
+class CaseSAMSHubWithThreadedAPI(unittest.TestCase):
+
+  def setUp(self):
+    self.hub = SAMSHub(
+      name = 'test', config = {'default_language': 'de', 'main_app' : 'test'})
+    from .api_test_server import app as apiApp
+    apiApp.config['TESTING'] = True
+    thApi = FlaskInThread(apiApp, host="localhost", port=4711)
+    thApi.start()
+    time.sleep(0.01)
+ 
+  def tearDown(self):
+    response = requests.get('http://localhost:4711/shutdown')
+    print(response.content.decode('utf-8'))
+    time.sleep(0.01)
+  
+  def test_hub_provides_apps_with_proxies(self):
+    manifest = {
+      'default_language': 'de',
+      'proxies': [{'in': 'api', 'out': 'http://localhost:4711'}]
+    }
+    self.hub.addApp(
+      SAMSApp(name = 'test',manifest = manifest, langDict={'de':{}})
+    )
+    self.hub.addApp(
+      SAMSApp(name = 'test.app', manifest = manifest, langDict={'de':{}})
+    )
+    with self.hub.flaskApp.test_client() as client:
+      self.assertIs(client.get(path='/api/hello').status_code, 200)
+      self.assertIs(client.get(path='/test.app/api/hello').status_code, 200)
+
 class CaseSAMSHubWithMainApp(unittest.TestCase):
   
   def setUp(self):
-- 
GitLab