|
1 | 1 | import pytest |
2 | 2 | from kirovy import typing as t, constants |
3 | | -from kirovy.models.cnc_game import CncGame |
| 3 | +from kirovy.models.cnc_game import CncGame, CncFileExtension |
4 | 4 |
|
5 | 5 |
|
6 | 6 | @pytest.fixture |
@@ -73,3 +73,66 @@ def game_red_alert(db) -> CncGame: |
73 | 73 | The game object for Red Alert. |
74 | 74 | """ |
75 | 75 | return CncGame.objects.get(slug__iexact=constants.GameSlugs.red_alert) |
| 76 | + |
| 77 | + |
| 78 | +@pytest.fixture |
| 79 | +def create_cnc_game(db, extension_map, extension_mix): |
| 80 | + """Return a function to create a CNC game.""" |
| 81 | + |
| 82 | + def _inner( |
| 83 | + slug: str = "ra2remaster", |
| 84 | + full_name: str = "Command & Conquer: Red Alert 2 - Remastered", |
| 85 | + is_visible: bool = True, |
| 86 | + allow_public_uploads: bool = True, |
| 87 | + compatible_with_parent_maps: bool = False, |
| 88 | + parent_game: CncGame | None = None, |
| 89 | + is_mod: bool = False, |
| 90 | + allowed_extensions: t.List[CncFileExtension] | None = None, |
| 91 | + ) -> CncGame: |
| 92 | + """Create a CNC game. |
| 93 | +
|
| 94 | + :param slug: |
| 95 | + The slug for the game. |
| 96 | + :param full_name: |
| 97 | + The full name of the game. |
| 98 | + :param is_visible: |
| 99 | + If the game is visible on the website. |
| 100 | + :param allow_public_uploads: |
| 101 | + If users can upload maps for this game. |
| 102 | + :param compatible_with_parent_maps: |
| 103 | + If maps from the parent game work in this game. |
| 104 | + :param parent_game: |
| 105 | + The parent game if this is a mod or expansion. |
| 106 | + :param is_mod: |
| 107 | + If this is a mod. |
| 108 | + :return: |
| 109 | + A CNC game object. |
| 110 | + """ |
| 111 | + if allowed_extensions is None: |
| 112 | + allowed_extensions = [extension_mix, extension_map] |
| 113 | + game = CncGame( |
| 114 | + slug=slug, |
| 115 | + full_name=full_name, |
| 116 | + is_visible=is_visible, |
| 117 | + allow_public_uploads=allow_public_uploads, |
| 118 | + compatible_with_parent_maps=compatible_with_parent_maps, |
| 119 | + parent_game=parent_game, |
| 120 | + is_mod=is_mod, |
| 121 | + ) |
| 122 | + game.save() |
| 123 | + game.allowed_extensions.add(*allowed_extensions) |
| 124 | + game.refresh_from_db() |
| 125 | + return game |
| 126 | + |
| 127 | + return _inner |
| 128 | + |
| 129 | + |
| 130 | +@pytest.fixture |
| 131 | +def cnc_game(create_cnc_game) -> CncGame: |
| 132 | + """Convenience wrapper to make a CncGame for a test.""" |
| 133 | + return create_cnc_game() |
| 134 | + |
| 135 | + |
| 136 | +@pytest.fixture |
| 137 | +def game_uploadable(create_cnc_game) -> CncGame: |
| 138 | + return create_cnc_game(is_visible=True, allow_public_uploads=True) |
0 commit comments