コード例 #1
0
def test_title_and_breadcrumbs(web_server: str, browser: DriverAPI,
                               dbsession: Session):
    """Checking that breadcrumbs and post-roll title are displayed correctly."""

    blog_title = 'My little Websauna blog'

    browser.visit(web_server + "/blog/")
    assert browser.find_by_css('h1').text == blog_title
    assert browser.find_by_css('.breadcrumb').text.endswith(blog_title)
コード例 #2
0
def test_title_and_breadcrumbs(web_server: str, browser: DriverAPI,
                               dbsession: Session, fakefactory):
    """Checking that breadcrumbs and post-roll title are displayed correctly."""

    with transaction.manager:
        tag = fakefactory.TagFactory()
        fakefactory.PostFactory(public=True, tags=[tag])
        dbsession.expunge_all()

    blog_title = 'Posts tagged {}'.format(tag)
    browser.visit(web_server + "/blog/tag/{}".format(tag))

    assert browser.find_by_css('h1').text == blog_title
    assert browser.find_by_css('.breadcrumb').text.endswith(blog_title)
コード例 #3
0
ファイル: testing.py プロジェクト: Likvidi/websauna.blog
def pagination_test(browser: DriverAPI, items: Iterable[object],
                    items_per_page: int, title_selector: str):
    """Checks if pagination works correctly."""
    def pagination_element(text: str, disabled=False):
        return browser.find_by_xpath(
            '//div[@class="pagination-wrapper"]//li[@class="{disabled}"]/a[text()[contains(.,"{text}")]]'
            .format(text=text, disabled="disabled" if disabled else ""))

    # checking disabled buttons (First and Previous)
    assert pagination_element("First", disabled=True)
    assert pagination_element("Previous", disabled=True)

    # checking not disabled buttons (Next and Last)
    assert pagination_element("Next")
    assert pagination_element("Last")

    # navigating to the last page (checking that Last works correctly)
    pagination_element("Last").click()

    # checking not disabled buttons (First and Previous)
    assert pagination_element("First")
    assert pagination_element("Previous")

    # checking disabled buttons (Next and Last)
    assert pagination_element("Next", disabled=True)
    assert pagination_element("Last", disabled=True)

    # navigating to the first page (checking that First works correctly)
    pagination_element("First").click()

    # checking if "next" works correctly
    posts_titles = set(i.title for i in items)
    for page in range(0, len(items), items_per_page):
        rendered_posts_titles = set(
            i.text for i in browser.find_by_css(title_selector))
        assert rendered_posts_titles.issubset(posts_titles)
        posts_titles -= rendered_posts_titles
        if page < len(items) - items_per_page:
            pagination_element("Next").click()

    # checking if "prev" works correctly
    posts_titles = set(i.title for i in items)
    for page in range(0, len(items), items_per_page):
        rendered_posts_titles = set(
            i.text for i in browser.find_by_css(title_selector))
        assert rendered_posts_titles.issubset(posts_titles)
        posts_titles -= rendered_posts_titles
        if page < len(items) - items_per_page:
            pagination_element("Previous").click()
コード例 #4
0
def test_posts_are_listed_in_publication_order(web_server: str,
                                               browser: DriverAPI,
                                               dbsession: Session,
                                               fakefactory):
    """Post are listed in publication order on tag-roll."""

    dates_span = arrow.Arrow.range("hour", arrow.get(2013, 5, 5, 0, 0),
                                   arrow.get(2013, 5, 5, 19, 0))[::-1]
    with transaction.manager:
        tag = fakefactory.TagFactory()
        posts = fakefactory.PostFactory.create_batch(len(dates_span),
                                                     public=True,
                                                     tags=[tag])
        random.shuffle(
            posts
        )  # make sure that creation order is not the same as publication order
        for post, date in zip(posts, dates_span):
            post.published_at = date.datetime
        dbsession.flush()
        dbsession.expunge_all()

    expected_posts_titles = [i.title for i in posts]
    browser.visit(web_server + "/blog/tag/{}".format(tag))

    rendered_posts_titles = [i.text for i in browser.find_by_css(".post h2")]

    assert expected_posts_titles == rendered_posts_titles
コード例 #5
0
def test_published_posts_in_blog_roll(web_server: str, browser: DriverAPI,
                                      dbsession: Session, fakefactory):
    """When posts are published they become visible in blog roll."""

    # creating a published post
    with transaction.manager:
        post = fakefactory.PostFactory(public=True)
        dbsession.expunge_all()

    # after navigating to blog-roll the post are displayed
    browser.visit(web_server + "/blog/")
    assert len(browser.find_by_css("div.post")) == 1
    post_line = browser.find_by_css("div.post")[0]
    assert post_line.find_by_css('h2').text == post.title
    assert post_line.find_by_css('.excerpt').text == post.excerpt
    assert (post_line.find_by_css('.text-muted').text ==
            'By {} just now. Tagged under {}.'.format(
                post.author, ', '.join(map(str, post.tags))))

    # user can navigate to post by clicking on its title on blog-roll page
    post_line.find_by_css('.post-link').click()
    assert browser.find_by_css("h1#heading-post").text == post.title
コード例 #6
0
def test_visitor_sees_only_relevant_posts_in_tag_roll(web_server: str,
                                                      browser: DriverAPI,
                                                      dbsession: Session,
                                                      fakefactory):
    """Visitors should not see unpublished posts in blog roll."""

    with transaction.manager:
        tag = fakefactory.TagFactory()
        post = fakefactory.PostFactory(public=True, tags=[tag])
        fakefactory.PostFactory()
        dbsession.expunge_all()

    browser.visit(web_server + "/blog/tag/{}".format(tag))
    assert len(browser.find_by_css("div.post")) == 1
    assert browser.is_text_present(post.title)
コード例 #7
0
ファイル: utils.py プロジェクト: debonzi/websauna
def logout(web_server:str, browser:DriverAPI):
    """Log out the current user from the test browser."""
    browser.find_by_css("#nav-logout").click()
    assert browser.is_element_present_by_css("#msg-logged-out")
コード例 #8
0
ファイル: utils.py プロジェクト: gitter-badger/websauna
def logout(web_server: str, browser: DriverAPI):
    """Log out the current user from the test browser."""
    browser.find_by_css("#nav-logout").click()
    assert browser.is_element_present_by_css("#msg-logged-out")