Repository: ocadotechnology/aimmo

Issue:
Fix aimmo view tests 
The new PR on branch `fix_staging` is breaking some tests.


Discussion:

Resolving patch:
diff --git a/example_project/example_project/settings.py b/example_project/example_project/settings.py
--- a/example_project/example_project/settings.py
+++ b/example_project/example_project/settings.py
@@ -109,16 +109,25 @@
 ]
 
 
-def get_url(game):
+def get_game_url_base_and_path(game):
     if os.environ.get('AIMMO_MODE', '') == 'minikube':
         output = subprocess.check_output([os.environ['MINIKUBE_PATH'], 'service',
                                           'game-%s' % game, '--url'])
-        return 'http://dev.aimmo.codeforlife.education', '/game-%s' % game
+        return 'local.aimmo.codeforlife.education', '/game-%s' % game
     else:
-        return 'http://localhost:%d' % (6001 + int(game) * 1000), ''
+        return 'localhost', ''
 
 
-AIMMO_GAME_SERVER_LOCATION_FUNCTION = get_url
+def get_game_port(game):
+    if os.environ.get('AIMMO_MODE', '') == 'minikube':
+        return 0
+
+    return 6001 + int(game) * 1000
+
+
+AIMMO_GAME_SERVER_URL_FUNCTION = get_game_url_base_and_path
+AIMMO_GAME_SERVER_PORT_FUNCTION = get_game_port
+AIMMO_GAME_SERVER_SSL_FLAG = False
 
 try:
     from example_project.local_settings import *  # pylint: disable=E0611
diff --git a/players/app_settings.py b/players/app_settings.py
--- a/players/app_settings.py
+++ b/players/app_settings.py
@@ -1,6 +1,8 @@
 from django.conf import settings
 
 #: URL function for locating the game server, takes one parameter `game`
-GAME_SERVER_LOCATION_FUNCTION = getattr(settings, 'AIMMO_GAME_SERVER_LOCATION_FUNCTION', None)
+GAME_SERVER_URL_FUNCTION = getattr(settings, 'AIMMO_GAME_SERVER_URL_FUNCTION', None)
+GAME_SERVER_PORT_FUNCTION = getattr(settings, 'AIMMO_GAME_SERVER_PORT_FUNCTION', None)
+GAME_SERVER_SSL_FLAG = getattr(settings, 'AIMMO_GAME_SERVER_SSL_FLAG', False)
 
 MAX_LEVEL = 1
diff --git a/players/views.py b/players/views.py
--- a/players/views.py
+++ b/players/views.py
@@ -123,7 +123,9 @@ def _render_game(request, game):
         'active': game.is_active,
         'static_data': game.static_data or '{}',
     }
-    context['game_url_base'], context['game_url_path'] = app_settings.GAME_SERVER_LOCATION_FUNCTION(game.id)
+    context['game_url_base'], context['game_url_path'] = app_settings.GAME_SERVER_URL_FUNCTION(game.id)
+    context['game_url_port'] = app_settings.GAME_SERVER_PORT_FUNCTION(game.id)
+    context['game_ssl_flag'] = app_settings.GAME_SERVER_SSL_FLAG
     context['game_id'] = game.id
     return render(request, 'players/viewer.html', context)
 


Test patch:
diff --git a/integration-tests/tests/test_kubernetes.py b/integration-tests/tests/test_kubernetes.py
--- a/integration-tests/tests/test_kubernetes.py
+++ b/integration-tests/tests/test_kubernetes.py
@@ -86,7 +86,7 @@ def test_correct_initial_ingress_yaml(self):
         rule = api_response.items[0].spec.rules[0]
         self.assertEqual(len(api_response.items[0].spec.rules), 1)
         self.assertEqual(rule.host,
-                         "dev.aimmo.codeforlife.education")
+                         "local.aimmo.codeforlife.education")
 
         # PATHS
         path = rule.http.paths[0]
diff --git a/players/tests.py b/players/tests.py
--- a/players/tests.py
+++ b/players/tests.py
@@ -6,7 +6,9 @@
 
 from players import models, views
 
-views.app_settings.GAME_SERVER_LOCATION_FUNCTION = lambda num: ('base %s' % num, 'path %s' % num)
+views.app_settings.GAME_SERVER_URL_FUNCTION = lambda game_id: ('base %s' % game_id, 'path %s' % game_id)
+views.app_settings.GAME_SERVER_PORT_FUNCTION = lambda game_id: 0
+views.app_settings.GAME_SERVER_SSL_FLAG = True
 
 
 class TestViews(TestCase):
diff --git a/test_settings.py b/test_settings.py
--- a/test_settings.py
+++ b/test_settings.py
@@ -11,5 +11,9 @@
 ROOT_URLCONF = 'django_autoconfig.autourlconf'
 STATIC_ROOT = '.tests_static/'
 
+GAME_SERVER_URL_FUNCTION = lambda game_id: ('base %s' % game_id, 'path %s' % game_id)
+GAME_SERVER_PORT_FUNCTION = lambda game_id: 8001
+GAME_SERVER_SSL_FLAG = False
+
 from django_autoconfig.autoconfig import configure_settings  # noqa: E402
 configure_settings(globals())