Exemple #1
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)
Exemple #2
0
    def test_mark_user_game_as_wishlisted(self) -> None:
        CatalogManager.mark_as_wishlisted(self.user, self.game.id,
                                          self.platform.id)

        wishlisted_user_game = WishlistedUserGame.objects.get(
            user=self.user.id,
            game_id=self.game.id,
            platform_id=self.platform.id)
        self.assertTrue(wishlisted_user_game is not None)
Exemple #3
0
    def test_unmark_as_abandoned_sets_proper_field(self) -> None:
        CatalogManager.mark_as_abandoned(self.user, self.game.id,
                                         self.platform.id)

        CatalogManager.unmark_as_abandoned(self.user, self.game.id,
                                           self.platform.id)

        self.user_game.refresh_from_db()
        self.assertFalse(self.user_game.abandoned)
Exemple #4
0
    def test_unmark_user_game_as_currently_playing_unsets_proper_field(
            self) -> None:
        CatalogManager.mark_as_currently_playing(self.user, self.game.id,
                                                 self.platform.id)

        CatalogManager.unmark_as_currently_playing(self.user, self.game.id,
                                                   self.platform.id)

        self.user_game.refresh_from_db()
        self.assertFalse(self.user_game.currently_playing)
Exemple #5
0
    def test_unmark_user_game_as_no_longer_owner_unsets_proper_field(
            self) -> None:
        CatalogManager.mark_as_no_longer_owned(self.user, self.game.id,
                                               self.platform.id)

        CatalogManager.unmark_as_no_longer_owned(self.user, self.game.id,
                                                 self.platform.id)

        self.user_game.refresh_from_db()
        self.assertFalse(self.user_game.no_longer_owned)
Exemple #6
0
    def test_unmark_user_game_as_finished_unsets_proper_field(self) -> None:
        an_irrelevant_year = 2000
        CatalogManager.mark_as_finished(self.user, self.game.id,
                                        self.platform.id, an_irrelevant_year)

        CatalogManager.unmark_as_finished(self.user, self.game.id,
                                          self.platform.id)

        self.user_game.refresh_from_db()
        self.assertFalse(self.user_game.finished)
        self.assertEqual(self.user_game.year_finished, None)
Exemple #7
0
    def test_remove_user_game_from_wishlisted(self) -> None:
        CatalogManager.mark_as_wishlisted(self.user, self.game.id,
                                          self.platform.id)

        CatalogManager.unmark_as_wishlisted(self.user, self.game.id,
                                            self.platform.id)

        with self.assertRaises(WishlistedUserGame.DoesNotExist) as error:
            WishlistedUserGame.objects.get(user=self.user.id,
                                           game_id=self.game.id,
                                           platform_id=self.platform.id)
        self.assertTrue("does not exist" in str(error.exception))
Exemple #8
0
    def test_mark_user_game_as_currently_playing_sets_and_unsets_proper_fields(
            self) -> None:
        self.user_game.no_longer_owned = True
        self.user_game.abandoned = True
        self.user_game.save()

        CatalogManager.mark_as_currently_playing(self.user, self.game.id,
                                                 self.platform.id)

        self.user_game.refresh_from_db()
        self.assertTrue(self.user_game.currently_playing)
        self.assertFalse(self.user_game.no_longer_owned)
        self.assertFalse(self.user_game.abandoned)
Exemple #9
0
    def test_mark_as_abandoned_sets_and_unsets_proper_fields(self) -> None:
        an_irrelevant_year = 2000
        self.user_game.currently_playing = True
        self.user_game.year_finished = an_irrelevant_year
        self.user_game.save()

        CatalogManager.mark_as_abandoned(self.user, self.game.id,
                                         self.platform.id)

        self.user_game.refresh_from_db()
        self.assertTrue(self.user_game.abandoned)
        self.assertFalse(self.user_game.currently_playing)
        self.assertFalse(self.user_game.finished)
Exemple #10
0
    def post(self, request: HttpRequest, username: str, *args: Any, **kwargs: Any) -> HttpResponse:
        if username != request.user.get_username() or request.method != "POST":
            raise Http404("Invalid URL")

        if request.POST.get("_method") == constants.FORM_METHOD_DELETE:
            CatalogManager.unmark_as_currently_playing(
                user=request.user, game_id=int(request.POST["game"]), platform_id=int(request.POST["platform"])
            )
        else:
            CatalogManager.mark_as_currently_playing(
                user=request.user, game_id=int(request.POST["game"]), platform_id=int(request.POST["platform"])
            )

        return HttpResponse(status=204)
Exemple #11
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)
Exemple #12
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))
Exemple #13
0
    def different_users_can_add_same_game_to_their_catalog(self) -> None:
        another_user = create_user()

        CatalogManager.add_to_catalog(another_user, self.game.id,
                                      self.platform.id)

        another_user_game = UserGame.objects.get(user=another_user.id,
                                                 game_id=self.game.id,
                                                 platform_id=self.platform.id)
        self.assertNotEqual(self.user_game.id, another_user_game.id)
        self.assertNotEqual(self.user_game.user.id, another_user_game.user.id)
        self.assertEqual(self.user_game.game.id, another_user_game.game.id)
        self.assertEqual(self.user_game.platform.id,
                         another_user_game.platform.id)
Exemple #14
0
    def post(self, request: HttpRequest, username: str, *args: Any, **kwargs: Any) -> HttpResponse:
        if username != request.user.get_username() or request.method != "POST":
            raise Http404("Invalid URL")

        if request.POST.get("_method") == constants.FORM_METHOD_DELETE:
            CatalogManager.remove_from_catalog(
                user=request.user, game_id=int(request.POST["game"]), platform_id=int(request.POST["platform"])
            )
        else:
            if int(request.POST["user"]) == request.user.id:
                CatalogManager.add_to_catalog(
                    user=request.user, game_id=int(request.POST["game"]), platform_id=int(request.POST["platform"]),
                )

        return HttpResponse(status=204)
Exemple #15
0
 def test_cant_add_twice_same_game_to_user_catalog(self) -> None:
     # setup() already added this without the CatalogManager
     with self.assertRaises(ValidationError) as error:
         CatalogManager.add_to_catalog(self.user, self.game.id,
                                       self.platform.id)
     self.assertTrue("already exists" in str(error.exception))