Beispiel #1
0
def test_content_finder_specific_url_replacements(url,
                                                  content_relative_dirpath,
                                                  filename):
    content = WebsiteContentFactory.build(
        website=WebsiteFactory.build(uuid="website_uuid"),
        dirpath=f"content{content_relative_dirpath}",
        filename=filename,
        text_id="content-uuid",
    )

    with patch_website_contents_all([content]):
        content_lookup = ContentLookup()

        assert content_lookup.find_within_site("website_uuid", url) == content
Beispiel #2
0
def test_legacy_file_lookup_raises_nonunique_for_multiple_matches():
    c1a = WebsiteContentFactory.build(
        website_id="site-uuid-one",
        file=f"/courses/site_one/{string_uuid()}_some_file_name.jpg",
        text_id="content-uuid-1",
    )
    c1b = WebsiteContentFactory.build(
        website_id="site-uuid-one",
        file=f"/courses/site_one/{string_uuid()}_some_file_name.jpg",
        text_id="content-uuid-2",
    )
    contents = [c1a, c1b]
    with patch_website_contents_all(contents):
        legacy_file_lookup = LegacyFileLookup()
        with pytest.raises(legacy_file_lookup.MultipleMatchError):
            assert legacy_file_lookup.find("site-uuid-one",
                                           "some_file_name.jpg")
Beispiel #3
0
def test_content_finder_returns_metadata_for_site(site_uuid, content_index):
    contents = [
        WebsiteContentFactory.build(
            website=WebsiteFactory.build(uuid="website_one"),
            type="sitemetadata",
            text_id="content-1",
        ),
        WebsiteContentFactory.build(
            website=WebsiteFactory.build(uuid="website_two"),
            type="sitemetadata",
            text_id="content-2",
        ),
    ]
    with patch_website_contents_all(contents):
        content_lookup = ContentLookup()
        assert (content_lookup.find_within_site(
            site_uuid, "/") == contents[content_index])
Beispiel #4
0
def test_legacy_file_lookup(site_uuid, filename, expected_index):
    c1a = WebsiteContentFactory.build(
        website_id="site-uuid-one",
        file=f"/courses/site_one/{string_uuid()}_someFileName.jpg",
        text_id="content-uuid-1a",
    )
    c1b = WebsiteContentFactory.build(
        website_id="site-uuid-one",
        file=f"/courses/site_one/{string_uuid()}_somefilename.jpg",
        text_id="content-uuid-1b",
    )
    c2 = WebsiteContentFactory.build(
        website_id="site-uuid-two",
        file=f"/courses/site_two/{string_uuid()}_someFileName.jpg",
        text_id="content-uuid-two",
    )
    contents = [c1a, c1b, c2]
    expected = contents[expected_index]
    with patch_website_contents_all(contents):
        legacy_file_lookup = LegacyFileLookup()
        assert legacy_file_lookup.find(site_uuid, filename) == expected
Beispiel #5
0
def test_content_finder_is_site_specific():
    """Test that ContentLookup is site specific"""
    content_w1 = WebsiteContentFactory.build(
        website=WebsiteFactory.build(uuid="website-uuid-1"),
        dirpath="content/resources/path/to",
        filename="file1",
        text_id="content-uuid-1",
    )
    content_w2 = WebsiteContentFactory.build(
        website=WebsiteFactory.build(uuid="website-uuid-2"),
        dirpath="content/resources/path/to",
        filename="file1",
        text_id="content-uuid-1",
    )

    with patch_website_contents_all([content_w1, content_w2]):
        content_lookup = ContentLookup()

        url = "/resources/path/to/file1"
        assert content_lookup.find_within_site(content_w1.website_id,
                                               url) == content_w1
        assert content_lookup.find_within_site(content_w2.website_id,
                                               url) == content_w2
def get_markdown_cleaner(website_contents):
    """Convenience to get rule-specific markdown cleaner"""
    with patch_website_contents_all(website_contents):
        rule = ResolveUIDRule()
        return WebsiteContentMarkdownCleaner(rule)
Beispiel #7
0
def get_markdown_cleaner(website_contents):
    """Convenience to get rule-specific cleaner"""
    with patch_website_contents_all(website_contents):
        rule = BaseurlReplacementRule()
        return WebsiteContentMarkdownCleaner(rule)
def get_markdown_cleaner(websites, website_contents):
    """Convenience to get rule-specific cleaner"""
    with patch_website_contents_all(website_contents):
        with patch_website_all(websites):
            rule = RootRelativeUrlRule()
            return WebsiteContentMarkdownCleaner(rule)
Beispiel #9
0
def get_markdown_cleaner(website_contents):
    """Convenience to get rule-specific cleaner"""
    with patch_website_contents_all(website_contents):
        rule = MetadataRelativeUrlsFix()
        return WebsiteContentMarkdownCleaner(rule)