def test_game_name_is_unique(self) -> None:
        game_data = {
            "name": "a unique name",
            "platforms": [self.platform_1.id],
            "publish_date": datetime.now().year,
        }  # type: Dict[str, Any]

        create_game(platforms=game_data["platforms"], name=game_data["name"])

        game_form = GameForm(game_data)
        self.assertFalse(game_form.is_valid())
        self.assertTrue("name" in game_form.errors.keys())
    def test_game_name_uniqueness_is_case_insensitive(self) -> None:
        game_data = {
            "name": "A Case Sensitive Unique Name",
            "platforms": [self.platform_1.id],
            "publish_date": datetime.now().year,
        }  # type: Dict[str, Any]

        create_game(platforms=game_data["platforms"], name=game_data["name"])

        game_data["name"] = game_data["name"].lower()
        game_form = GameForm(game_data)

        with self.assertRaises(ValidationError) as error:
            game_form.is_valid()
        self.assertTrue("already exists" in str(error.exception))
    def test_game_dlc_platform_must_be_subset_of_parent_game(self) -> None:
        platform_2 = create_platform()
        platform_3 = create_platform()

        game_1 = create_game(platforms=[self.platform_1, platform_2])

        # subset = superset
        game_data = {
            "name": "an irrelevant name",
            "platforms": (platform.id for platform in game_1.platforms.all()),
            "publish_date": datetime.now().year,
            "dlc_or_expansion": True,
            "parent_game": game_1.id,
        }  # type: Dict[str, Any]
        game_form = GameForm(game_data)
        self.assertTrue(game_form.is_valid(), game_form.errors)

        # subset < superset
        game_data["platforms"] = [self.platform_1]
        game_form = GameForm(game_data)
        self.assertTrue(game_form.is_valid(), game_form.errors)

        # subset != superset
        game_data["platforms"] = [self.platform_1, platform_3]
        game_form = GameForm(game_data)
        self.assertFalse(game_form.is_valid())
        self.assertTrue("platforms" in game_form.errors.keys())
        self.assertTrue("subset/all of parent game platforms" in game_form.errors["platforms"][0])

        game_data["platforms"] = [platform_3]
        game_form = GameForm(game_data)
        self.assertFalse(game_form.is_valid())
        self.assertTrue("platforms" in game_form.errors.keys())
        self.assertTrue("subset/all of parent game platforms" in game_form.errors["platforms"][0])
    def test_game_dlc_parent_cannot_be_also_a_dlc(self) -> None:
        game_1 = create_game(platforms=[self.platform_1])
        game_1_dlc = create_game(platforms=[self.platform_1], dlc_or_expansion=True, parent_game=game_1.id)

        game_data = {
            "name": "an irrelevant name",
            "platforms": [self.platform_1.id],
            "publish_date": datetime.now().year,
            "dlc_or_expansion": True,
            "parent_game": game_1_dlc.id,
        }  # type: Dict[str, Any]

        game_form = GameForm(game_data)
        self.assertFalse(game_form.is_valid())
        self.assertTrue("parent_game" in game_form.errors.keys())
        self.assertTrue("cannot have as parent another game DLC" in game_form.errors["parent_game"][0])
Beispiel #5
0
    def test_remove_game_from_user_catalog(self) -> None:
        another_platform = create_platform()
        another_game = create_game(platforms=[self.platform, another_platform])
        another_user = create_user()
        CatalogManager.add_to_catalog(self.user, another_game.id,
                                      self.platform.id)
        CatalogManager.add_to_catalog(self.user, another_game.id,
                                      another_platform.id)
        CatalogManager.add_to_catalog(another_user, another_game.id,
                                      self.platform.id)

        CatalogManager.remove_from_catalog(self.user, another_game.id,
                                           self.platform.id)

        with self.assertRaises(UserGame.DoesNotExist) as error:
            UserGame.objects.get(user=self.user.id,
                                 game_id=another_game.id,
                                 platform_id=self.platform.id)
        self.assertTrue("does not exist" in str(error.exception))

        # but other associations still exist/not removed by accident
        UserGame.objects.get(user=self.user.id,
                             game_id=self.game.id,
                             platform_id=self.platform.id)
        UserGame.objects.get(user=self.user.id,
                             game_id=another_game.id,
                             platform_id=another_platform.id)
        # and similar association but for other users also still exists
        UserGame.objects.get(user=another_user.id,
                             game_id=another_game.id,
                             platform_id=self.platform.id)
Beispiel #6
0
    def test_add_game_to_user_catalog(self) -> None:
        another_platform = create_platform()
        another_game = create_game(platforms=[self.platform, another_platform])

        with self.assertRaises(UserGame.DoesNotExist) as error:
            UserGame.objects.get(user=self.user.id,
                                 game_id=another_game.id,
                                 platform_id=another_platform.id)
        self.assertTrue("does not exist" in str(error.exception))

        # Add new game, new platform
        CatalogManager.add_to_catalog(self.user, another_game.id,
                                      another_platform.id)

        user_game_1 = UserGame.objects.get(user=self.user.id,
                                           game_id=another_game.id,
                                           platform_id=another_platform.id)
        self.assertTrue(user_game_1 is not None)
        self.assertEqual(user_game_1.game.id, another_game.id)
        self.assertEqual(user_game_1.platform.id, another_platform.id)

        # Can also add it with the other platform, and it's a different association
        CatalogManager.add_to_catalog(self.user, another_game.id,
                                      self.platform.id)

        user_game_2 = UserGame.objects.get(user=self.user.id,
                                           game_id=another_game.id,
                                           platform_id=self.platform.id)
        self.assertTrue(user_game_2 is not None)
        self.assertEqual(user_game_2.game.id, another_game.id)
        self.assertEqual(user_game_2.platform.id, self.platform.id)
        self.assertNotEqual(user_game_1, user_game_2)
Beispiel #7
0
    def setUp(self):
        self.platform = create_platform()
        self.game = create_game(platforms=[self.platform])
        self.user = create_user()

        self.fetched_game = FetchedGame(publish_date=AN_IRRELEVANT_YEAR,
                                        name=self.game.name)
        self.fetched_game.fg_game = self.game
        self.fetched_game.save()
Beispiel #8
0
    def setUp(self) -> None:
        self.platform = create_platform()
        self.game = create_game(platforms=[self.platform])
        self.user = create_user()

        user_game_data = {
            "user_id": self.user.id,
            "game_id": self.game.id,
            "platform_id": self.platform.id,
        }
        self.user_game = UserGame(**user_game_data)
        self.user_game.save()
Beispiel #9
0
    def test_adding_game_to_catalog_removes_from_wishlisted_if_present(
            self) -> None:
        another_game = create_game(platforms=[self.platform])
        CatalogManager.mark_as_wishlisted(self.user, another_game.id,
                                          self.platform.id)

        CatalogManager.add_to_catalog(self.user, another_game.id,
                                      self.platform.id)

        with self.assertRaises(WishlistedUserGame.DoesNotExist) as error:
            WishlistedUserGame.objects.get(user=self.user.id,
                                           game_id=another_game.id,
                                           platform_id=self.platform.id)
        self.assertTrue("does not exist" in str(error.exception))
    def test_game_dlc_needs_parent_game(self) -> None:
        game_1 = create_game(platforms=[self.platform_1])

        game_data = {
            "name": "an irrelevant name",
            "platforms": [self.platform_1.id],
            "publish_date": datetime.now().year,
            "dlc_or_expansion": True,
            "parent_game": None,
        }  # type: Dict[str, Any]

        game_form = GameForm(game_data)
        self.assertFalse(game_form.is_valid())
        self.assertTrue("parent_game" in game_form.errors.keys())
        self.assertTrue("must specify a parent game" in game_form.errors["parent_game"][0])

        game_data["parent_game"] = game_1.id
        game_form = GameForm(game_data)
        self.assertTrue(game_form.is_valid(), game_form.errors)
 def setUp(self) -> None:
     self.platform_1 = create_platform()
     self.platform_2 = create_platform()
     self.game_1 = create_game(platforms=[self.platform_1, self.platform_2])
     self.user = create_user()