def test_invalid_location_code_of_invalid_game(self): user_middleware = GamePlayerMiddleware(self.david.username) try: result = user_middleware.visit_location('V444-GFEN', 'W2Z0-8888') # Invalid game and location codes except Exception as e: self.assertTrue(e.__class__ == AmazingRaceApp.models.Game.DoesNotExist, "ERROR! User cannot add an invalid " "game location of a an invalud game") return self.assertFalse(True, "ERROR! Invalid game is somehow validated...")
def test_valid_but_wrong_order_location_code_of_non_joined_game(self): user_middleware = GamePlayerMiddleware(self.david.username) # Juhu Beach location of Jewel of India game result = user_middleware.visit_location('6VK7-IG74', 'RIPM-VKBR') self.assertFalse(result, "ERROR! User can add a valid game location of wrong order to a non-joined game")
def test_invalid_location_code_of_non_joined_game(self): user_middleware = GamePlayerMiddleware(self.david.username) result = user_middleware.visit_location('9999-GFEN', 'RIPM-VKBR') self.assertFalse(result, "ERROR! User can add a invalid game location of a mon-joined game")
def test_non_conventional_location_code_of_joined_game(self): user_middleware = GamePlayerMiddleware(self.david.username) result = user_middleware.visit_location('Non conventional code format....', 'WS30-8FA3') self.assertFalse(result, "ERROR! User can add a invalid game location code format of a joined game")
def test_valid_location_code_of_wrong_non_joined_game(self): user_middleware = GamePlayerMiddleware(self.david.username) result = user_middleware.visit_location('V4H7-GFEN', 'RIPM-VKBR') self.assertFalse(result, "ERROR! User cannot add a valid game location of a joined game")
def test_valid_but_wrong_order_location_code_of_joined_game(self): user_middleware = GamePlayerMiddleware(self.david.username) result = user_middleware.visit_location('UFQ7-XMJO', 'WS30-8FA3') self.assertFalse(result, "ERROR! User can add a valid game location in the wrong order of a joined game")
def test_valid_but_wrong_order_location_code_of_created_game(self): user_middleware = GamePlayerMiddleware(self.david.username) # Deloitte location, Canva game result = user_middleware.visit_location('4GL4-BHJ3', '13T2-JFRN') self.assertFalse(result, "ERROR! User can add an out of order game location of a created game")
def test_invalid_location_code_of_joined_game(self): user_middleware = GamePlayerMiddleware(self.david.username) result = user_middleware.visit_location('V4H7-EEEN', 'WS30-8FA3') self.assertFalse(result, "ERROR! User can add an invalid game location of a joined game")
class GamePlayingListView(LoginRequiredMixin, generic.TemplateView): template_name = 'play-games.html' login_url = '/start' player = None def get(self, request, code, *args, **kwargs): self.game = _GameMiddleware(code) if not self.game: return handler(request, 404) self.player = GamePlayerMiddleware(request.user.username) if not self.player.is_authorized_to_access_game(code): return handler(request, 404) self.maps = MapsMiddleware() lat_long = [] visited = self.player.locations_visited(code) for location in visited: if location[1] != "???": temp = [] latitude, longitude = self.maps.get_coordinate(location[1]) temp.append(float(latitude)) temp.append(float(longitude)) temp.append(location[1]) lat_long.append(temp) return render(request, self.template_name, context={ 'game_details': self.game.get_code_and_name(), 'visited': self.player.locations_visited(code), 'lat_long': lat_long }) # Handling of when a game player inputs a location code within a game # Post Request Values: # game_code: game code retrieved from a hidden input in the form # location_code: location code inputed by a user def post(self, request, *args, **kwargs): self.game = _GameMiddleware(request.POST['game_code']) if not self.game: return handler(request, 404) self.player = GamePlayerMiddleware(request.user.username) if not self.player.is_authorized_to_access_game( request.POST['game_code']): return handler(request, 404) error = "" if len(request.POST['location_code']) == 9: result = self.player.visit_location(request.POST['location_code'], request.POST['game_code']) if not result: error = "Invalid Location Code" else: error = "Invalid Location Code" self.maps = MapsMiddleware() lat_long = [] visited = self.player.locations_visited(request.POST['game_code']) for location in visited: if location[1] != "???": temp = [] latitude, longitude = self.maps.get_coordinate(location[1]) temp.append(float(latitude)) temp.append(float(longitude)) temp.append(location[1]) lat_long.append(temp) return render(request, self.template_name, context={ 'game_details': self.game.get_code_and_name(), 'visited': self.player.locations_visited( request.POST['game_code']), 'lat_long': lat_long, 'error': error })