Ejemplo n.º 1
0
def pick_at_random():
    categories = get_all_categories(BOOKS, ordered=True)
    template_get_file = 'random_picker_get.html'
    template_post_file = 'random_picker_post.html'

    if request.method == POST:
        desired_category = request.form['category']

        try:
            book = get_random_unread_book(BOOKS, desired_category)
        except TypeError:
            return render_template(template_get_file, categories=categories)
        else:
            if book:
                return render_template(
                    template_post_file,
                    title=book.title,
                    author=book.author,
                    tags=book.tags,
                    categories=categories,
                    desired_category=desired_category,
                    no_unread_books=False,
                )
            else:
                return render_template(template_post_file,
                                       no_unread_books=True)

    return render_template(template_get_file, categories=categories)
Ejemplo n.º 2
0
    def test_return_ordered_list_of_deduplicated_categories(self):
        df = pd.DataFrame(
            data={
                'read': [1, 0],
                'author': ['author1', 'author2'],
                'tags': ['sci-fi', 'novel, sci-fi'],
            })

        actual_categories = get_all_categories(df, ordered=True)
        assert actual_categories == ['novel', 'sci-fi']
Ejemplo n.º 3
0
    def test_return_empty_list_if_no_categories(self):
        df = pd.DataFrame(
            data={
                'read': [1, 0],
                'author': ['author1', 'author2'],
                'tags': ['', np.nan],
            })

        actual_categories = get_all_categories(df)
        assert actual_categories == []
Ejemplo n.º 4
0
    def test_return_list_of_deduplicated_categories(self):
        df = pd.DataFrame(
            data={
                'read': [1, 0],
                'author': ['author1', 'author2'],
                'tags': ['sci-fi', 'novel, sci-fi'],
            })

        actual_categories = get_all_categories(df)
        assert isinstance(actual_categories, list)
        assert sorted(actual_categories) == ['novel', 'sci-fi']
Ejemplo n.º 5
0
 def test_return_empty_list_if_no_books(self):
     df = pd.DataFrame(columns=['read', 'author', 'tags'])
     actual_categories = get_all_categories(df)
     assert actual_categories == []