Ejemplo n.º 1
0
def test_first_page_max_five_entries():
    row = ["Paul", "12"]
    paginator = Paginator(header=[], rows=[row, row, row, row, row, row])

    page = paginator.get_first_page()

    assert len(page.rows) == 5
Ejemplo n.º 2
0
def test_include_page_number():
    row = ["Paul", "12"]
    paginator = Paginator(header=[], rows=[row, row, row, row, row])

    page = paginator.get_first_page()

    assert page.num == 1
    assert page.total == 1
Ejemplo n.º 3
0
def test_multiple_rows_have_index():
    row = ["Paul", "12"]
    paginator = Paginator(header=[], rows=[row, row])

    page = paginator.get_first_page()

    assert len(page.rows) == 2
    for idx, row in enumerate(page.rows):
        assert row[0] == idx + 1
Ejemplo n.º 4
0
def test_reset_index_for_first_page():
    row = ["Paul", "12"]
    paginator = Paginator(header=[], rows=[row, row, row, row, row,
                                           row, row, row, row, row])

    paginator.get_last_page()
    page = paginator.get_first_page()

    assert len(page.rows) == 5
    assert page.rows[0][0] == 1
Ejemplo n.º 5
0
class Commandline:
    def __init__(self, file_name):
        header, rows = read(file_name)
        self.paginator = Paginator(header=header, rows=rows)

    def start(self):
        return self.paginator.get_first_page()

    def execute(self, param):
        command = param.lower()
        if command in commands:
            if command == 'j':
                return self._jump_to_page()
            else:
                return commands[command](self.paginator)
        raise AttributeError("unknown command entered")

    def _jump_to_page(self):
        print("Input page index:")
        user_input = str(input())
        return commands['j'](self.paginator, int(user_input) - 1)
Ejemplo n.º 6
0
def test_first_page_contains_header():
    paginator = Paginator(header=["Name", "Age"], rows=[])

    page = paginator.get_first_page()

    assert page.header == ["No.", "Name", "Age"]
Ejemplo n.º 7
0
def test_first_page_contains_entries():
    paginator = Paginator(header=[], rows=[["Paul", "12"]])

    page = paginator.get_first_page()

    assert len(page.rows) == 1