Esempio n. 1
0
    def test_pagination_hidden(self):
        NotesService.upsert_note(VALID_ID, "Test", utils.now())
        pagination = NotesService.paginate_notes(page=1)
        self.assertEqual(len(pagination.items), 1)

        NotesService.hide_note(VALID_ID)
        pagination = NotesService.paginate_notes(page=1)
        self.assertEqual(len(pagination.items), 0)
Esempio n. 2
0
def get_notes():
    page = args_int("page", 1)
    query = args_str("q")

    pagination = NotesService.paginate_notes(page, query=query)

    url_page_1 = url_for(".get_notes")
    url_previous = url_for(".get_notes")
    if pagination.prev_num and pagination.prev_num > 1:
        url_previous += "?page={}".format(pagination.prev_num)
    url_next = "{}?page={}".format(url_for(".get_notes"), pagination.next_num)

    if query:
        param = "q={}".format(query)

        url_page_1 += "?" + param
        url_previous += ("&" if "?" in url_previous else "?") + param
        url_next += "&" + param

    return render_template(
        "notes.html",
        pagination=pagination,
        url_page_1=url_page_1,
        url_previous=url_previous,
        url_next=url_next,
        query=query or "",
        t=t,
    )
Esempio n. 3
0
    def test_notes_search(self):
        note_1_id = NotesService.generate_note_id()
        note_2_id = NotesService.generate_note_id()
        note_3_id = NotesService.generate_note_id()
        NotesService.upsert_note(note_1_id, "hello world", utils.now())
        NotesService.upsert_note(note_2_id, "hello there", utils.now(1))
        NotesService.upsert_note(note_3_id, "aaaaaaaaaa", utils.now(2))

        notes = NotesService.paginate_notes(1, query="hello world")
        self.assertEqual(notes.total, 1)
        self.assertEqual(notes.items[0].contents, "hello world")

        notes = NotesService.paginate_notes(1, query="hello")
        self.assertEqual(notes.total, 2)
        self.assertEqual(notes.items[1].contents, "hello world")
        self.assertEqual(notes.items[0].contents, "hello there")

        notes = NotesService.paginate_notes(1, query="aa")
        self.assertEqual(notes.total, 1)
        self.assertEqual(notes.items[0].contents, "aaaaaaaaaa")

        notes = NotesService.paginate_notes(1, query="foobarfoobar")
        self.assertEqual(notes.total, 0)
Esempio n. 4
0
    def test_previews_pagination(self):
        total_notes = random.randint(20, 50)
        page_size = 15

        for _ in range(total_notes):
            NotesService.upsert_note(
                NotesService.generate_note_id(), "Test", utils.now()
            )

        ids = set()

        for i in range(1, 1 + total_notes // page_size):
            pagination = NotesService.paginate_notes(page=i, page_size=page_size)
            self.assertLessEqual(len(pagination.items), page_size)
            self.assertGreater(len(pagination.items), 0)

            page_ids_set = {note.id for note in pagination.items}
            self.assertEqual(len(page_ids_set), len(pagination.items))

            previous_len = len(ids)
            ids |= page_ids_set

            self.assertEqual(len(ids), previous_len + len(page_ids_set))