Repository: ocadotechnology/aimmo

Issue:
[New UI] Introduce different reducers aside from editor
## New UI - Fix on `UI_new_design` branch

We currently only have one reducer that we use, editor. This should be splitted per feature into different reducers.


Discussion:

Resolving patch:
diff --git a/players/game_renderer.py b/players/game_renderer.py
--- a/players/game_renderer.py
+++ b/players/game_renderer.py
@@ -20,7 +20,7 @@ def render_game(request, game):
 
     context.update(connection_settings)
 
-    return render(request, 'players/viewer.html', context)
+    return render(request, 'players/game_ide.html', context)
 
 
 def get_environment_connection_settings(game_id):
diff --git a/players/urls.py b/players/urls.py
--- a/players/urls.py
+++ b/players/urls.py
@@ -14,12 +14,8 @@
     url(r'^accounts/logout/$', auth_views.logout, {'next_page' : 'aimmo/logout_success'}, name='aimmo/logout'),
     url(r'^accounts/logout_success/$', TemplateView.as_view(template_name='registration/success_logout.html'), name='aimmo/logout_success'),
 
-    url(r'^program/(?P<id>[0-9]+)/$', login_required(preview_user_required(views.ProgramView.as_view())), name='aimmo/program'),
-    url(r'^program_level/(?P<num>[0-9]+)/$', login_required(preview_user_required(views.program_level)), name='aimmo/program_level'),
-    url(r'^watch/(?P<id>[0-9]+)/$', login_required(preview_user_required(views.watch_game)), name='aimmo/watch'),
-    url(r'^watch_level/(?P<num>[0-9]+)/$', login_required(preview_user_required(views.watch_level)), name='aimmo/watch_level'),
+    url(r'^play/(?P<id>[0-9]+)/$', login_required(preview_user_required(views.watch_game)), name='aimmo/play'),
     url(r'^statistics/$', TemplateView.as_view(template_name='players/statistics.html'), name='aimmo/statistics'),
-    url(r'^game_ide/$', TemplateView.as_view(template_name='players/game_ide.html'), name='aimmo/game_ide'),
 
     url(r'^api/csrf_token', views.csrfToken, name='aimmo/csrf_token'),
     url(r'^api/code/(?P<id>[0-9]+)/$', views.code, name='aimmo/code'),
diff --git a/players/views.py b/players/views.py
--- a/players/views.py
+++ b/players/views.py
@@ -122,16 +122,6 @@ def get_context_data(self, **kwargs):
         return context
 
 
-def program_level(request, num):
-    try:
-        game = Game.objects.get(levelattempt__user=request.user, levelattempt__level_number=num)
-    except Game.DoesNotExist:
-        LOGGER.debug('Adding level')
-        game = _add_and_return_level(num, request.user)
-    LOGGER.debug('Programming game with id %s', game.id)
-    return render(request, 'players/program.html', {'game_id': game.id})
-
-
 def watch_game(request, id):
     game = get_object_or_404(Game, id=id)
     if not game.can_user_play(request.user):
@@ -177,7 +167,7 @@ def add_game(request):
             users = get_users_for_new_game(request)
             if users is not None:
                 game.can_play.add(*users)
-            return redirect('aimmo/program', id=game.id)
+            return redirect('aimmo/play', id=game.id)
     else:
         form = forms.AddGameForm()
     return render(request, 'players/add_game.html', {'form': form})


Test patch:
diff --git a/players/tests.py b/players/tests.py
--- a/players/tests.py
+++ b/players/tests.py
@@ -57,14 +57,6 @@ def test_code_for_non_authed_user(self):
         response = c.post(reverse('aimmo/code', kwargs={'id': 1}), {'code': self.CODE})
         self.assertEqual(response.status_code, 404)
 
-    def test_login_required_for_code(self):
-        self.game.public = False
-        self.game.can_play = [self.user]
-        self.game.save()
-        c = Client()
-        response = c.post(reverse('aimmo/program', kwargs={'id': 1}), {'code': self.CODE})
-        self.assertNotEqual(response.status_code, 200)
-
     def test_default_code(self):
         c = self.login()
         response = c.get(reverse('aimmo/code', kwargs={'id': 1}))
@@ -78,24 +70,6 @@ def test_retrieve_code(self):
         self.assertEqual(response.status_code, 200)
         self.assertJSONEqual(response.content, {'code': self.CODE})
 
-    def test_program(self):
-        c = self.login()
-        response = c.get(reverse('aimmo/program', kwargs={'id': 1}))
-        self.assertEqual(response.status_code, 200)
-        self.assertEqual(response.context['game_id'], 1)
-
-    def test_program_for_non_existant_game(self):
-        c = self.login()
-        response = c.get(reverse('aimmo/program', kwargs={'id': 2}))
-        self.assertEqual(response.status_code, 404)
-
-    def test_program_for_non_authed_user(self):
-        self.game.public = False
-        self.game.save()
-        c = self.login()
-        response = c.get(reverse('aimmo/program', kwargs={'id': 1}))
-        self.assertEqual(response.status_code, 404)
-
     def _associate_game_as_level_num(self, level_num=1, user=None, game=None):
         if game is None:
             game = self.game
@@ -104,97 +78,34 @@ def _associate_game_as_level_num(self, level_num=1, user=None, game=None):
         models.LevelAttempt(user=user, game=game, level_number=level_num).save()
         models.Game(name='Wrong').save()
 
-    def test_program_level(self):
-        self._associate_game_as_level_num()
-        c = self.login()
-        response = c.get(reverse('aimmo/program_level', kwargs={'num': 1}))
-        self.assertEqual(response.status_code, 200)
-        self.assertEqual(response.context['game_id'], 1)
-
-    def test_program_level_creates_level(self):
-        if models.Game.objects.filter(levelattempt__user=self.user, levelattempt__level_number=1).exists():
-            self.skipTest('DB is polluted, alreaday a level attempt for level 1')
+    def test_play(self):
         c = self.login()
-        response = c.get(reverse('aimmo/program_level', kwargs={'num': 1}))
-        self.assertEqual(response.status_code, 200)
-        game = models.Game.objects.get(id=response.context['game_id'])
-        self.assertEqual(game.name, 'Level 1', 'Game name should be "Level 1"')
-        self.assertEqual(game.owner, None, 'Game should not have an owner')
-        self.assertEqual(game.public, False, 'Game should not be public')
-        self.assertEqual(list(game.can_play.all()), [self.user], 'Game should be playable by current user')
-        self.assertEqual(game.completed, False, 'Game should not be completed')
-        self.assertEqual(game.main_user, self.user, 'Game should have current user as main user')
-        self.assertEqual(game.generator, 'Level1', 'Game should use "Level1" generator')
-        self.assertEqual(game.levelattempt.user, self.user, 'Game should be an attempt for the current user')
-        self.assertEqual(game.levelattempt.level_number, 1, 'Game should be an attempt at level 1')
-
-    def test_program_level_too_high(self):
-        c = self.login()
-        # We cause a warning by using a level too high which is expected
-        logging.disable(logging.WARNING)
-        response = c.get(reverse('aimmo/program_level', kwargs={'num': 1000}))
-        logging.disable(logging.INFO)
-        self.assertEqual(response.status_code, 404)
-
-    def test_watch(self):
-        c = self.login()
-        response = c.get(reverse('aimmo/watch', kwargs={'id': 1}))
+        response = c.get(reverse('aimmo/play', kwargs={'id': 1}))
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.context['current_user_player_key'], self.user.pk)
         self.assertEqual(response.context['game_url_base'], 'base 1')
         self.assertEqual(response.context['game_url_path'], 'path 1')
 
-    def test_watch_for_non_existant_watch(self):
+    def test_play_for_non_existant_game(self):
         c = self.login()
-        response = c.get(reverse('aimmo/watch', kwargs={'id': 2}))
+        response = c.get(reverse('aimmo/play', kwargs={'id': 2}))
         self.assertEqual(response.status_code, 404)
 
-    def test_watch_for_non_authed_user(self):
+    def test_play_for_non_authed_user(self):
         self.game.public = False
         self.game.save()
         c = self.login()
-        response = c.get(reverse('aimmo/watch', kwargs={'id': 1}))
-        self.assertEqual(response.status_code, 404)
-
-    def test_watch_level(self):
-        self._associate_game_as_level_num()
-        c = self.login()
-        response = c.get(reverse('aimmo/watch_level', kwargs={'num': 1}))
-        self.assertEqual(response.status_code, 200)
-        self.assertEqual(response.context['current_user_player_key'], self.user.pk)
-        self.assertEqual(response.context['game_url_base'], 'base 1')
-        self.assertEqual(response.context['game_url_path'], 'path 1')
-
-    def test_watch_level_creates_level(self):
-        if models.Game.objects.filter(levelattempt__user=self.user, levelattempt__level_number=1).exists():
-            self.skipTest('DB polluted, already a level attempt present')
-        c = self.login()
-        response = c.get(reverse('aimmo/watch_level', kwargs={'num': 1}))
-        self.assertEqual(response.status_code, 200)
-        game = models.Game.objects.get(levelattempt__user=self.user, levelattempt__level_number=1)
-        self.assertEqual(list(game.can_play.all()), [self.user], 'Game should be playable by current user')
-        self.assertEqual(game.completed, False, 'Game should not be completed')
-        self.assertEqual(game.main_user, self.user, 'Game should have current user as main user')
-        self.assertEqual(game.generator, 'Level1', 'Game should use "Level1" generator')
-        self.assertEqual(game.levelattempt.user, self.user, 'Game should be an attempt for the current user')
-        self.assertEqual(game.levelattempt.level_number, 1, 'Game should be an attempt at level 1')
-
-    def test_watch_level_too_high(self):
-        c = self.login()
-        # We cause a warning by using a level too high which is expected
-        logging.disable(logging.WARNING)
-        response = c.get(reverse('aimmo/watch_level', kwargs={'num': 1000}))
-        logging.disable(logging.INFO)
+        response = c.get(reverse('aimmo/play', kwargs={'id': 1}))
         self.assertEqual(response.status_code, 404)
 
-    def test_watch_inactive_level(self):
+    def test_play_inactive_level(self):
         c = self.login()
         self.game.completed = True
         if self.game.is_active:
             self.skipTest('Completed game is active')
         self.game.static_data = '{"test": 1}'
         self.game.save()
-        response = c.get(reverse('aimmo/watch', kwargs={'id': 1}))
+        response = c.get(reverse('aimmo/play', kwargs={'id': 1}))
         self.assertEqual(response.status_code, 200)
         self.assertFalse(response.context['active'])
         self.assertEqual(response.context['static_data'], '{"test": 1}')