Example #1
0
    def test_add_del_text_bases(self):
        """Tests methods that alter text_bases."""
        # Before testing add/del, confirm expected text bases.
        self.assertEqual(TEXT_ONLY, asset_paths.AllowedBases.text_bases())

        asset_paths.AllowedBases.add_text_bases([])
        self.assertEqual(TEXT_ONLY, asset_paths.AllowedBases.text_bases())
        self.assertEqual(ALL_ALLOWED, asset_paths.AllowedBases.all_bases())

        # New text asset bases, all missing canonical /.../ delimiters.
        new_malformed_bases = ["assets/text", "assets/dart/", "/assets/sgml"]
        new_text_bases = frozenset(asset_paths.as_bases(new_malformed_bases))

        # Add one new text asset base.
        some_new_text_base = random.choice(new_malformed_bases)
        asset_paths.AllowedBases.add_text_base(some_new_text_base)
        self.assertEqual(
            len(TEXT_ONLY) + 1, len(asset_paths.AllowedBases.text_bases()))
        self.assertEqual(
            TEXT_ONLY.union([asset_paths.as_base(some_new_text_base)]),
            asset_paths.AllowedBases.text_bases())
        # Should also update all_bases superset with one new base.
        self.assertEqual(
            len(ALL_ALLOWED) + 1, len(asset_paths.AllowedBases.all_bases()))
        self.assertEqual(
            ALL_ALLOWED.union([asset_paths.as_base(some_new_text_base)]),
            asset_paths.AllowedBases.all_bases())

        # Add multiple new text asset bases (some are already present).
        asset_paths.AllowedBases.add_text_bases(new_malformed_bases)
        self.assertEqual(TEXT_ONLY.union(new_text_bases),
                         asset_paths.AllowedBases.text_bases())
        # Should also update all_bases superset with new bases.
        self.assertEqual(ALL_ALLOWED.union(new_text_bases),
                         asset_paths.AllowedBases.all_bases())

        # Delete previously-added text asset base.
        another_new_text_base = random.choice(new_malformed_bases)
        asset_paths.AllowedBases.del_text_base(another_new_text_base)
        new_remaining = frozenset(
            new_text_bases.difference(
                [asset_paths.as_base(another_new_text_base)]))
        self.assertEqual(TEXT_ONLY.union(new_remaining),
                         asset_paths.AllowedBases.text_bases())
        # Should also remove that base from all_bases superset.
        self.assertEqual(ALL_ALLOWED.union(new_remaining),
                         asset_paths.AllowedBases.all_bases())

        # Delete multiple new text asset bases (some may already be gone).
        asset_paths.AllowedBases.del_text_bases(new_malformed_bases)
        self.assertEqual(TEXT_ONLY, asset_paths.AllowedBases.text_bases())
        # Should also remove those bases from all_bases superset.
        self.assertEqual(ALL_ALLOWED, asset_paths.AllowedBases.all_bases())

        # Can delete an original allowed text base (but, *please*, do not).
        some_original_text_base = random.choice([tb for tb in TEXT_ONLY])
        asset_paths.AllowedBases.del_text_base(some_original_text_base)
        self.assertEqual(
            len(TEXT_ONLY) - 1, len(asset_paths.AllowedBases.text_bases()))
        asset_paths.AllowedBases.del_text_base(some_original_text_base)
 def test_asset_paths_as_base(self):
     """Tests the asset_paths.as_base function."""
     self.assertEqual(
         "/both/delims/",
         asset_paths.as_base(BOTH_DELIMS))
     self.assertEqual(
         "/end/delim/",
         asset_paths.as_base(END_DELIM))
     self.assertEqual(
         "/start/delim/",
         asset_paths.as_base(START_DELIM))
 def test_asset_paths_as_bases(self):
     """Tests the asset_paths.as_bases function."""
     bases = [ab for ab in asset_paths.as_bases(ALL_BASES)]
     golden = ["/both/delims/", "/end/delim/", "/start/delim/"]
     self.assertEqual(golden, bases)
     generated = (asset_paths.as_base(b) for b in ALL_BASES)
     self.assertEqual([gb for gb in generated], bases)
Example #4
0
 def test_asset_paths_as_bases(self):
     """Tests the asset_paths.as_bases function."""
     bases = [ab for ab in asset_paths.as_bases(ALL_BASES)]
     golden = ["/both/delims/", "/end/delim/", "/start/delim/"]
     self.assertEqual(golden, bases)
     generated = (asset_paths.as_base(b) for b in ALL_BASES)
     self.assertEqual([gb for gb in generated], bases)
    def test_add_del_text_bases(self):
        """Tests methods that alter text_bases."""
        # Before testing add/del, confirm expected text bases.
        self.assertEqual(
            TEXT_ONLY,
            asset_paths.AllowedBases.text_bases())

        asset_paths.AllowedBases.add_text_bases([])
        self.assertEqual(
            TEXT_ONLY,
            asset_paths.AllowedBases.text_bases())
        self.assertEqual(
            ALL_ALLOWED,
            asset_paths.AllowedBases.all_bases())

        # New text asset bases, all missing canonical /.../ delimiters.
        new_malformed_bases = ["assets/text", "assets/dart/", "/assets/sgml"]
        new_text_bases = frozenset(asset_paths.as_bases(new_malformed_bases))

        # Add one new text asset base.
        some_new_text_base = random.choice(new_malformed_bases)
        asset_paths.AllowedBases.add_text_base(some_new_text_base)
        self.assertEqual(
            len(TEXT_ONLY) + 1,
            len(asset_paths.AllowedBases.text_bases()))
        self.assertEqual(
            TEXT_ONLY.union([asset_paths.as_base(some_new_text_base)]),
            asset_paths.AllowedBases.text_bases())
        # Should also update all_bases superset with one new base.
        self.assertEqual(
            len(ALL_ALLOWED) + 1,
            len(asset_paths.AllowedBases.all_bases()))
        self.assertEqual(
            ALL_ALLOWED.union([asset_paths.as_base(some_new_text_base)]),
            asset_paths.AllowedBases.all_bases())

        # Add multiple new text asset bases (some are already present).
        asset_paths.AllowedBases.add_text_bases(new_malformed_bases)
        self.assertEqual(
            TEXT_ONLY.union(new_text_bases),
            asset_paths.AllowedBases.text_bases())
        # Should also update all_bases superset with new bases.
        self.assertEqual(
            ALL_ALLOWED.union(new_text_bases),
            asset_paths.AllowedBases.all_bases())

        # Delete previously-added text asset base.
        another_new_text_base = random.choice(new_malformed_bases)
        asset_paths.AllowedBases.del_text_base(another_new_text_base)
        new_remaining = frozenset(new_text_bases.difference(
            [asset_paths.as_base(another_new_text_base)]))
        self.assertEqual(
            TEXT_ONLY.union(new_remaining),
            asset_paths.AllowedBases.text_bases())
        # Should also remove that base from all_bases superset.
        self.assertEqual(
            ALL_ALLOWED.union(new_remaining),
            asset_paths.AllowedBases.all_bases())

        # Delete multiple new text asset bases (some may already be gone).
        asset_paths.AllowedBases.del_text_bases(new_malformed_bases)
        self.assertEqual(
            TEXT_ONLY,
            asset_paths.AllowedBases.text_bases())
        # Should also remove those bases from all_bases superset.
        self.assertEqual(
            ALL_ALLOWED,
            asset_paths.AllowedBases.all_bases())

        # Can delete an original allowed text base (but, *please*, do not).
        some_original_text_base = random.choice([tb for tb in TEXT_ONLY])
        asset_paths.AllowedBases.del_text_base(some_original_text_base)
        self.assertEqual(
            len(TEXT_ONLY) - 1,
            len(asset_paths.AllowedBases.text_bases()))
        asset_paths.AllowedBases.del_text_base(some_original_text_base)
Example #6
0
 def test_asset_paths_as_base(self):
     """Tests the asset_paths.as_base function."""
     self.assertEqual("/both/delims/", asset_paths.as_base(BOTH_DELIMS))
     self.assertEqual("/end/delim/", asset_paths.as_base(END_DELIM))
     self.assertEqual("/start/delim/", asset_paths.as_base(START_DELIM))