<commit_before>from django.test import TestCase
from . import factories
from games import models


class TestGame(TestCase):
    def test_factory(self):
        game = factories.GameFactory(name="Quake 3 Arena", is_public=False)
        self.assertEqual(game.slug, "quake-3-arena")
        self.assertFalse(game.is_public)

    def test_game_list_filters_game_with_no_installers(self):
        doom = factories.GameFactory(name="Doom")
        game_list = models.Game.objects.with_installer()
        self.assertNotIn(doom, game_list)

    def test_published_games_only_gets_with_installers(self):
        doom = factories.GameFactory(name="Doom")
        factories.InstallerFactory(game=doom, version="test")
        game_list = models.Game.objects.published()
        self.assertIn(doom, game_list)

        game_list = models.Game.objects.published()
        factories.InstallerFactory(game=doom, version="test2")
        self.assertEqual(len(game_list), 1)

    def test_game_can_return_a_default_installer(self):
        snes = factories.PlatformFactory(name='SNES')
        snes.default_installer = {
            'main_file': 'rom',
            'files': [{'rom': 'N/A'}],
            'installer': [{'merge': {'src': 'rom', 'dst': '$GAMEDIR'}}]
        }
        snes.save()
        super_mario_world = factories.GameFactory(name="Super Mario World")
        super_mario_world.platforms.add(snes)
        default_installers = super_mario_world.get_default_installers()
        self.assertTrue(default_installers)
        self.assertEqual(default_installers[0]['slug'],
                         'super-mario-world-snes')
<commit_msg>Add unit tests covering the previously faulty behaviour<commit_after>from django.test import TestCase
from . import factories
from games import models


class TestGame(TestCase):
    def test_factory(self):
        game = factories.GameFactory(name="Quake 3 Arena", is_public=False)
        self.assertEqual(game.slug, "quake-3-arena")
        self.assertFalse(game.is_public)

    def test_website_url_no_protocol_specified(self):
        """Ensures that URLs are uniform if no protocol was specified"""

        # Create a game with a protocol-less website (no http:// or https://)
        game = factories.GameFactory(name='Game Title', website='example.com')

        # If no protocol was specified, it should fall back to http://
        self.assertEqual(game.website_url, 'http://example.com')

        # HR URL should be unchanged
        self.assertEqual(game.website_url_hr, 'example.com')

    def test_website_url_http_specified(self):
        """Ensures that URLs are uniform if http was specified"""

        # Create a game with an http:// website specified
        game = factories.GameFactory(name='Game Title', website='http://example.com')

        # If a protocl was specified, it should be returned unchanged
        self.assertEqual(game.website_url, 'http://example.com')

        # HR URL should strip the http:// part
        self.assertEqual(game.website_url_hr, 'example.com')

    def test_website_url_https_specified(self):
        """Ensures that URLs are uniform if https was specified"""

        # Create a game with an https:// website specified
        game = factories.GameFactory(name='Game Title', website='https://example.com')

        # If a protocl was specified, it should be returned unchanged
        self.assertEqual(game.website_url, 'https://example.com')

        # HR URL should strip the https:// part
        self.assertEqual(game.website_url_hr, 'example.com')

    def test_website_url_strip_trailing_slash(self):
        """Ensures that trailing slashes are stripped for HR website_url"""

        # Create a game with a URL with trailing slash
        game = factories.GameFactory(name='Game Title', website='http://example.com/')

        # If a trailing slash was given, it should not be stripped for website_url
        self.assertEqual(game.website_url, 'http://example.com/')

        # HR URL should strip the http:// part and the trailing slash
        self.assertEqual(game.website_url_hr, 'example.com')

    def test_game_list_filters_game_with_no_installers(self):
        doom = factories.GameFactory(name="Doom")
        game_list = models.Game.objects.with_installer()
        self.assertNotIn(doom, game_list)

    def test_published_games_only_gets_with_installers(self):
        doom = factories.GameFactory(name="Doom")
        factories.InstallerFactory(game=doom, version="test")
        game_list = models.Game.objects.published()
        self.assertIn(doom, game_list)

        game_list = models.Game.objects.published()
        factories.InstallerFactory(game=doom, version="test2")
        self.assertEqual(len(game_list), 1)

    def test_game_can_return_a_default_installer(self):
        snes = factories.PlatformFactory(name='SNES')
        snes.default_installer = {
            'main_file': 'rom',
            'files': [{'rom': 'N/A'}],
            'installer': [{'merge': {'src': 'rom', 'dst': '$GAMEDIR'}}]
        }
        snes.save()
        super_mario_world = factories.GameFactory(name="Super Mario World")
        super_mario_world.platforms.add(snes)
        default_installers = super_mario_world.get_default_installers()
        self.assertTrue(default_installers)
        self.assertEqual(default_installers[0]['slug'],
                         'super-mario-world-snes')

{'fraction_non_alphanumeric': 0.11170704642130572, 'fraction_numerical': 0.0018494544109487702, 'mean_word_length': 3.16, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3595818', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1546, 'n_words': 342}