def popular_category(): sales = spaza_shop.get_sales() most_pop_cat = spaza_shop.get_most_pop_cat(sales) cursor.execute( "SELECT cat_name, SUM(no_sold) AS no_sold FROM sales_history INNER JOIN categories ON category_name=categories.cat_name GROUP BY cat_name ORDER BY no_sold DESC" ) data = cursor.fetchall() if len(data) is 0: return render_template("popular_category.html", result=most_pop_cat) return render_template("popular_category.html", result=data)
def test_get_most_pop_cat(self): sales = spaza_shop.get_sales("Nelisa.csv") most_pop_cat = spaza_shop.get_most_pop_cat(sales) expected = {"dairy" : 310} self.assertEquals(expected, most_pop_cat)