Example #1
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
Example #2
0
def test_visitor_does_not_see_admin_panel_navigation(web_server: str,
                                                     browser: DriverAPI,
                                                     dbsession: Session):
    """Admin actions are shown to logged in visitors only."""

    browser.visit(web_server + "/blog/")
    assert not browser.is_text_present("Admin actions")
Example #3
0
def test_empty_tag_roll(web_server: str, browser: DriverAPI,
                        dbsession: Session):
    """We can render empty tag list."""

    # Direct Splinter browser to the website
    browser.visit(web_server + "/blog/tag/xxx")

    assert browser.is_element_present_by_css("#blog-no-posts")
Example #4
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)
Example #5
0
def test_blog_roll_pagination(web_server: str, browser: DriverAPI,
                              dbsession: Session, fakefactory):
    """When posts exceed batch size, pagination is activated. Test that it's sane."""

    posts_per_page = 20
    with transaction.manager:
        posts = fakefactory.PostFactory.create_batch(100, public=True)[::-1]
        dbsession.expunge_all()

    browser.visit(web_server + "/blog/")
    pagination_test(browser, posts, posts_per_page, ".post h2")
Example #6
0
def test_no_unpublished_posts_in_blog_roll(web_server: str, browser: DriverAPI,
                                           dbsession: Session, fakefactory):
    """Visitors sees no unpublished posts in blog-roll."""

    # creating a private post, it should not be listed in roll for a visitor
    with transaction.manager:
        fakefactory.PostFactory(private=True)

    # after navigating to blog-roll there are no posts displayed
    browser.visit(web_server + "/blog/")
    assert browser.is_element_visible_by_css("#blog-no-posts")
Example #7
0
def test_tag_roll_pagination(web_server: str, browser: DriverAPI,
                             dbsession: Session, fakefactory):
    """When posts exceed batch size, pagination is activated. Test that it's sane."""
    posts_per_page = 20
    with transaction.manager:
        tag = fakefactory.TagFactory()
        posts = fakefactory.PostFactory.create_batch(100,
                                                     public=True,
                                                     tags=[tag])
        dbsession.expunge_all()

    browser.visit(web_server + "/blog/tag/{}".format(tag))
    pagination_test(browser, posts, posts_per_page, ".post h2")
Example #8
0
def test_visitor_sees_only_published_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()
        fakefactory.PostFactory(private=True, tags=[tag])
        dbsession.expunge_all()

    browser.visit(web_server + "/blog/tag/{}".format(tag.title))
    assert browser.is_element_visible_by_css("#blog-no-posts")
Example #9
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)
Example #10
0
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()
Example #11
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)
Example #12
0
def test_user_see_admin_panel_navigation(web_server: str, browser: DriverAPI,
                                         dbsession: Session, fakefactory,
                                         login_user):
    """Logged in user sees navigation link to admin panel on blog-roll."""

    with transaction.manager:
        user = fakefactory.UserFactory(admin=True)
        dbsession.expunge_all()
    login_user(user)
    browser.visit(web_server + "/blog/")

    # admin action menu is present
    assert browser.is_text_present("Admin actions")

    # after clicking on "Manage posts" user is redirected to posts-listing on admin panel
    browser.find_by_xpath('//a[text()[contains(.,"Manage posts")]]').click()
    assert browser.url.endswith('/admin/models/blog-posts/listing')
Example #13
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
Example #14
0
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")
Example #15
0
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")
Example #16
0
def test_empty_blog(web_server: str, dbsession: Session, browser: DriverAPI):
    """We can render empty blog."""

    browser.visit(web_server + "/blog/")
    # After login we see a profile link to our profile
    assert browser.is_element_visible_by_css("#blog-no-posts")