示例#1
0
    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])
示例#2
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)
示例#3
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)
    def test_platform_names_are_unique(self) -> None:
        platform_data = {
            "name": "a unique name",
            "shortname": "a unique shortname",
            "publish_date": datetime.now().year,
        }  # type: Dict[str, Any]
        create_platform(name=platform_data["name"],
                        shortname=platform_data["shortname"])

        platform_form = PlatformForm(platform_data)
        self.assertFalse(platform_form.is_valid())
        self.assertTrue("name" in platform_form.errors.keys())
        self.assertTrue("already exists" in platform_form.errors["name"][0])
        self.assertTrue("shortname" in platform_form.errors.keys())
        self.assertTrue(
            "already exists" in platform_form.errors["shortname"][0])
示例#5
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()
示例#6
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()
    def test_cannot_wishlist_game_on_unavailable_platform(self) -> None:
        platform_3 = create_platform()

        wishlist_game_data = {
            "user_id": self.user.id,
            "game_id": self.game_1.id,
            "platform_id": platform_3.id,
        }

        wishlist_game = WishlistedUserGame(**wishlist_game_data)
        with self.assertRaises(ValidationError) as error:
            wishlist_game.full_clean()
        self.assertTrue("not available in platform" in str(error.exception))
    def test_platform_name_uniqueness_is_case_insensitive(self) -> None:
        platform_data = {
            "name": "A Case Sensitive Unique Name",
            "shortname": "A Case Sensitive Unique Shortname",
            "publish_date": datetime.now().year,
        }  # type: Dict[str, Any]
        create_platform(name=platform_data["name"],
                        shortname=platform_data["shortname"])

        platform_2_data = platform_data.copy()
        platform_2_data["name"] = platform_2_data["name"].lower()
        platform_form = PlatformForm(platform_2_data)
        with self.assertRaises(ValidationError) as error:
            platform_form.is_valid()
        self.assertTrue("already exists" in str(error.exception))

        platform_2_data = platform_data.copy()
        platform_2_data["shortname"] = platform_2_data["shortname"].lower()
        platform_form = PlatformForm(platform_2_data)
        with self.assertRaises(ValidationError) as error:
            platform_form.is_valid()
        self.assertTrue("already exists" in str(error.exception))
 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()
示例#10
0
 def setUp(self) -> None:
     self.platform_1 = create_platform()