Beispiel #1
0
def test_stats_container():
    "Tests the Stats container used in the templates"
    # Test basic API and null total count
    ipdata = [{"foo":1}]*100
    s = Stats(ipdata, "foo", "nothing")
    expected_op = [(x, 1) for x in range(0, 140, 5)]
    assert s.get_counts() == expected_op
    assert s.get_summary() == 28
    assert s.total == ""
Beispiel #2
0
def test_status_timerange():
    "Tests the stats container with a time X-axis"
    d = datetime.datetime.now().replace(hour = 0, minute = 0, second = 0, microsecond = 0)
    ipdata = []
    expected_op = []
    for i in range(10):
        doc = MockDoc(_id = d.strftime("counts-%Y-%m-%d"), foo = 1)
        ipdata.append(doc)
        expected_op.append([calendar.timegm(d.timetuple()) * 1000, 1])
        d += datetime.timedelta(days = 1)
    s = Stats(ipdata, "foo", "nothing")
    assert s.get_counts(10, True) == expected_op[:10]
Beispiel #3
0
def test_status_total():
    "Tests the total attribute of the stats container used in the templates"
    ipdata = [{"foo":1, "total": x*2} for x in range(1,100)]
    s = Stats(ipdata, "foo", "total")
    assert s.total == 198
    # Test a total before the last
    ipdata = [{"foo":1, "total": x*2} for x in range(1,100)]
    for i in range(90,99):
        del ipdata[i]["total"]
        ipdata[90]["total"] = 2
    s = Stats(ipdata, "foo", "total")
    assert s.total == 2
Beispiel #4
0
    def test_home_template(self, render_template, mock_site, olconfig,
                           monkeypatch):
        docs = [
            MockDoc(_id=datetime.datetime.now().strftime("counts-%Y-%m-%d"),
                    human_edits=1,
                    bot_edits=1,
                    lists=1,
                    visitors=1,
                    loans=1,
                    members=1,
                    works=1,
                    editions=1,
                    ebooks=1,
                    covers=1,
                    authors=1,
                    subjects=1)
        ] * 100
        stats = dict(human_edits=Stats(docs, "human_edits", "human_edits"),
                     bot_edits=Stats(docs, "bot_edits", "bot_edits"),
                     lists=Stats(docs, "lists", "total_lists"),
                     visitors=Stats(docs, "visitors", "visitors"),
                     loans=Stats(docs, "loans", "loans"),
                     members=Stats(docs, "members", "total_members"),
                     works=Stats(docs, "works", "total_works"),
                     editions=Stats(docs, "editions", "total_editions"),
                     ebooks=Stats(docs, "ebooks", "total_ebooks"),
                     covers=Stats(docs, "covers", "total_covers"),
                     authors=Stats(docs, "authors", "total_authors"),
                     subjects=Stats(docs, "subjects", "total_subjects"))

        mock_site.quicksave("/people/foo/lists/OL1L", "/type/list")
        olconfig.setdefault("home",
                            {})['lending_list'] = "/people/foo/lists/OL1L"

        def spoofed_generic_carousel(*args, **kwargs):
            return [{
                "work":
                None,
                "key":
                "/books/OL1M",
                "url":
                "/books/OL1M",
                "title":
                "The Great Book",
                "authors":
                [web.storage({
                    "key": "/authors/OL1A",
                    "name": "Some Author"
                })],
                "read_url":
                "http://archive.org/stream/foo",
                "borrow_url":
                "/books/OL1M/foo/borrow",
                "inlibrary_borrow_url":
                "/books/OL1M/foo/borrow",
                "cover_url":
                ""
            }]

        monkeypatch.setattr(web.ctx, "library", {"name": "IA"}, raising=False)
        html = unicode(render_template("home/index", stats=stats, test=True))

        headers = [
            "Books We Love", "Recently Returned", "Success", "Thrillers",
            "Romance", "Technical Books", "Classic Literature", "Textbooks"
        ]
        for h in headers:
            assert h in html

        assert "Around the Library" in html
        assert "About the Project" in html
Beispiel #5
0
    def test_home_template(self, render_template, mock_site, olconfig, monkeypatch):
        docs = [MockDoc(_id = datetime.datetime.now().strftime("counts-%Y-%m-%d"),
                        human_edits = 1, bot_edits = 1, lists = 1,
                        visitors = 1, loans = 1, members = 1,
                        works = 1, editions = 1, ebooks = 1,
                        covers = 1, authors = 1, subjects = 1)]* 100
        stats = dict(human_edits = Stats(docs, "human_edits", "human_edits"),
                     bot_edits   = Stats(docs, "bot_edits", "bot_edits"),
                     lists       = Stats(docs, "lists", "total_lists"),
                     visitors    = Stats(docs, "visitors", "visitors"),
                     loans       = Stats(docs, "loans", "loans"),
                     members     = Stats(docs, "members", "total_members"),
                     works       = Stats(docs, "works", "total_works"),
                     editions    = Stats(docs, "editions", "total_editions"),
                     ebooks      = Stats(docs, "ebooks", "total_ebooks"),
                     covers      = Stats(docs, "covers", "total_covers"),
                     authors     = Stats(docs, "authors", "total_authors"),
                     subjects    = Stats(docs, "subjects", "total_subjects"))

        mock_site.quicksave("/people/foo/lists/OL1L", "/type/list")
        olconfig.setdefault("home", {})['lending_list'] = "/people/foo/lists/OL1L"

        monkeypatch.setattr(home, "get_returncart", lambda limit: [])

        html = unicode(render_template("home/index",
            stats=stats,
            lending_list="/people/foo/lists/OL1L"))
        assert '<div class="homeSplash"' in html
        #assert "Books to Read" in html
        assert "Return Cart" in html
        assert "Around the Library" in html
        assert "About the Project" in html
Beispiel #6
0
    def test_home_template(self, render_template, mock_site, monkeypatch):
        docs = [
            MockDoc(_id=datetime.datetime.now().strftime("counts-%Y-%m-%d"),
                    human_edits=1,
                    bot_edits=1,
                    lists=1,
                    visitors=1,
                    loans=1,
                    members=1,
                    works=1,
                    editions=1,
                    ebooks=1,
                    covers=1,
                    authors=1,
                    subjects=1)
        ] * 100
        stats = dict(human_edits=Stats(docs, "human_edits", "human_edits"),
                     bot_edits=Stats(docs, "bot_edits", "bot_edits"),
                     lists=Stats(docs, "lists", "total_lists"),
                     visitors=Stats(docs, "visitors", "visitors"),
                     loans=Stats(docs, "loans", "loans"),
                     members=Stats(docs, "members", "total_members"),
                     works=Stats(docs, "works", "total_works"),
                     editions=Stats(docs, "editions", "total_editions"),
                     ebooks=Stats(docs, "ebooks", "total_ebooks"),
                     covers=Stats(docs, "covers", "total_covers"),
                     authors=Stats(docs, "authors", "total_authors"),
                     subjects=Stats(docs, "subjects", "total_subjects"))

        mock_site.quicksave("/people/foo/lists/OL1L", "/type/list")

        def spoofed_generic_carousel(*args, **kwargs):
            return [{
                "work":
                None,
                "key":
                "/books/OL1M",
                "url":
                "/books/OL1M",
                "title":
                "The Great Book",
                "authors":
                [web.storage({
                    "key": "/authors/OL1A",
                    "name": "Some Author"
                })],
                "read_url":
                "http://archive.org/stream/foo",
                "borrow_url":
                "/books/OL1M/foo/borrow",
                "inlibrary_borrow_url":
                "/books/OL1M/foo/borrow",
                "cover_url":
                ""
            }]

        monkeypatch.setattr(home, 'get_cachable_sponsorable_editions',
                            lambda: [])
        html = six.text_type(
            render_template("home/index", stats=stats, test=True))
        headers = [
            "Books We Love", "Recently Returned", "Kids", "Books to Sponsor",
            "Thrillers", "Romance", "Classic Books", "Textbooks"
        ]
        for h in headers:
            assert h in html

        assert "Around the Library" in html
        assert "About the Project" in html