def test_char_overlay_toggle_elite_smash(self):
        """ If a character image is clicked, its elite smash status is toggled, and the image is displayed
            in full colour/greyscale, depending on elite smash status."""
        s = self.selenium
        server_url = self.live_server_url
        game = self.game

        # Create characters:
        chars = create_characters(game, 5)
        first_char = chars[0]

        # Login and nav to char overlay page:
        login(s, server_url, self.user.username)
        s.get(server_url + reverse('mentor:char_overlay', args=[game.id]))

        # Note: Since character has just been created, no UserCharacter record will exist for this user and char.
        # Check that first character image is greyscale, since not in elite smash by default:
        first_char_imgs = s.find_elements_by_css_selector(
            "img#" + snakify(first_char.name) + ".grayscale")
        self.assertEqual(len(first_char_imgs), 1)

        # Check that no colour img for first character exists (no grayscale CSS class):
        first_char_coloured = s.find_elements_by_css_selector(
            "img#" + snakify(first_char.name) + ":not(.grayscale)")
        self.assertEqual(len(first_char_coloured), 0)

        # Click img:
        first_char_imgs[0].click()

        # Wait for page to refresh:
        time.sleep(0.5)

        # Test that character is full colour after reload:
        first_char_imgs = s.find_elements_by_css_selector(
            "img#" + snakify(first_char.name) + ":not(.grayscale)")
        self.assertEqual(len(first_char_imgs), 1)

        # Click img again to toggle to true:
        first_char_imgs[0].click()
        time.sleep(0.5)

        # Check for grayscale after reload:
        first_char_imgs = s.find_elements_by_css_selector(
            "img#" + snakify(first_char.name) + ".grayscale")
        self.assertEqual(len(first_char_imgs), 1)
    def test_elite_smash_status_persistence(self):
        """The elite smash status of all characters are kept after leaving the page and returning."""
        s = self.selenium
        game = self.game
        login(s, self.live_server_url, self.user.username)

        chars = create_characters(game, 5)
        s.get(self.live_server_url +
              reverse('mentor:char_overlay', args=[game.id]))

        s.find_element_by_id(snakify(chars[0].name)).click()
        time.sleep(0.2)
        s.find_element_by_id(snakify(chars[2].name)).click()
        time.sleep(0.2)
        s.find_element_by_id(snakify(chars[3].name)).click()
        time.sleep(0.5)

        # Check that clicked character imgs are not grayscale:
        char_imgs = s.find_elements_by_css_selector("img#" +
                                                    snakify(chars[0].name) +
                                                    ":not(.grayscale)")
        self.assertEqual(len(char_imgs), 1)
        char_imgs = s.find_elements_by_css_selector("img#" +
                                                    snakify(chars[2].name) +
                                                    ":not(.grayscale)")
        self.assertEqual(len(char_imgs), 1)
        char_imgs = s.find_elements_by_css_selector("img#" +
                                                    snakify(chars[3].name) +
                                                    ":not(.grayscale)")
        self.assertEqual(len(char_imgs), 1)

        s.get(self.live_server_url + reverse('mentor:index'))
        s.get(self.live_server_url +
              reverse('mentor:char_overlay', args=[game.id]))

        # Check that clicked character imgs are not grayscale:
        char_imgs = s.find_elements_by_css_selector("img#" +
                                                    snakify(chars[0].name) +
                                                    ":not(.grayscale)")
        self.assertEqual(len(char_imgs), 1)
        char_imgs = s.find_elements_by_css_selector("img#" +
                                                    snakify(chars[2].name) +
                                                    ":not(.grayscale)")
        self.assertEqual(len(char_imgs), 1)
        char_imgs = s.find_elements_by_css_selector("img#" +
                                                    snakify(chars[3].name) +
                                                    ":not(.grayscale)")
        self.assertEqual(len(char_imgs), 1)
Ejemplo n.º 3
0
def serve_char_img(x):
    """ Create and return an img tag for the given character, the image url and CSS classes; depending
        on existence of character img and elite smash status."""
    char, elite_smash = x
    s_name = snakify(char.name)

    # Get img url (char or placeholder)
    # Elite smash check (grayscale)
    # Return complete img HTML tag

    img_url = img_exists(char)

    if elite_smash:
        grayscale_str = ''
    else:
        grayscale_str = ' grayscale'

    return mark_safe(
        '<a href="' + reverse("mentor:elite_smash_toggle", args=[char.game.id]) + '?char_id=' + str(char.id) + '">'
            '<img id="' + snakify(char.name) + '" class="char_overlay_img img-fluid' + grayscale_str +
                    '" type="image" src="' + img_url + '" alt="' + char.name + '">'
        '</a>')
 def test_snakify_with_no_punctuation(self):
     """Returns correctly formatted string, which originally contained no punctuation"""
     new_str = snakify('What a Wonderful World')
     self.assertEqual(new_str, 'what_a_wonderful_world')
 def test_snakify_with_safe_punctuation(self):
     """Returns formatted string, which removes unwanted punctuation whilst keeping 'safe' punctuation."""
     new_str = snakify('Ros(^*ali%na &$( L+um"a')
     self.assertEqual(new_str, 'rosalina_&_luma')
 def test_snakify_with_unwanted_punctuation(self):
     """Returns correctly formatted string, removing unwanted punctuation."""
     new_str = snakify('Wh,,a.t a/ Wo/n,d..e!r,f//u?l/ /,W//orld')
     self.assertEqual(new_str, 'what_a_wonderful_world')