From 09d22bfbfbf864d8a3122b32c04ac25abadd53b7 Mon Sep 17 00:00:00 2001 From: Paulo Lobo Date: Fri, 8 Mar 2019 15:00:40 -0300 Subject: [PATCH 1/2] For #430: TableListView test with authentication. --- tests/view/tables/test_tables.py | 34 ++++++++++++++++++++-------- timeless/restaurants/tables/views.py | 5 ---- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/tests/view/tables/test_tables.py b/tests/view/tables/test_tables.py index b17f4052..439bf58e 100644 --- a/tests/view/tables/test_tables.py +++ b/tests/view/tables/test_tables.py @@ -1,23 +1,39 @@ import pytest from http import HTTPStatus +from flask import g -from timeless.restaurants.models import Table -from timeless.restaurants.tables.views import TableListView +from timeless.roles.models import RoleType from tests import factories -""" Tests for the Table views.""" +""" Tests for the Table views. +@todo #430:30min Fix TableListView problem of returning empty list. + TableListView is returning an empty list when it should return valid values. + Test below is valid, it calls TableListViews with an authenticated user but it + isn't retrieving the tables. Fix the TableListView class and then uncomment the + test below. +""" -@pytest.mark.skip(reason="Inject authentication for tables/list") + +@pytest.mark.skip(reason="TableListView is not behaving correctly") def test_list(client): """ Test list is okay """ - floor = factories.FloorFactory() - factories.TableFactory(floor_id=floor.id) - factories.TableFactory(floor_id=floor.id) - factories.TableFactory(floor_id=floor.id) - factories.TableFactory(floor_id=floor.id) + role = factories.RoleFactory(name=RoleType.Intern.name) + company = factories.CompanyFactory() + employee = factories.EmployeeFactory( + company=company, role_id=role.id + ) + location = factories.LocationFactory(company=company) + floor = factories.FloorFactory(location=location) + with client.session_transaction() as session: + session["user_id"] = employee.id + g.user = employee + factories.TableFactory(floor_id=floor.id, name="Table 01") + factories.TableFactory(floor_id=floor.id, name="Table 01") + factories.TableFactory(floor_id=floor.id, name="Table 01") response = client.get("/tables/") + print(response.data) assert response.status_code == HTTPStatus.OK assert b"

Table 01

" in response.data assert b"

Table 02

" in response.data diff --git a/timeless/restaurants/tables/views.py b/timeless/restaurants/tables/views.py index 5df2d7b2..4cd9db29 100644 --- a/timeless/restaurants/tables/views.py +++ b/timeless/restaurants/tables/views.py @@ -1,9 +1,4 @@ """tables views module. -@todo #309:30min Add mock authentication to TableListView. Currently - TabeListView test is not working because it requires an authenticated user - with permissions to show list tables. it is currently showing login screen. - Add an mocked authenticated user so we can run the test, the remove skip - annotation from it. """ from flask import Blueprint From db32739330dad519fa598eaaece6f06da626ad90 Mon Sep 17 00:00:00 2001 From: Paulo Lobo Date: Mon, 11 Mar 2019 00:52:53 -0300 Subject: [PATCH 2/2] For #430: Review corrections --- tests/view/tables/test_tables.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/view/tables/test_tables.py b/tests/view/tables/test_tables.py index 439bf58e..df194e8a 100644 --- a/tests/view/tables/test_tables.py +++ b/tests/view/tables/test_tables.py @@ -1,7 +1,7 @@ import pytest from http import HTTPStatus -from flask import g +from flask import g, url_for from timeless.roles.models import RoleType from tests import factories @@ -30,10 +30,9 @@ def test_list(client): session["user_id"] = employee.id g.user = employee factories.TableFactory(floor_id=floor.id, name="Table 01") - factories.TableFactory(floor_id=floor.id, name="Table 01") - factories.TableFactory(floor_id=floor.id, name="Table 01") - response = client.get("/tables/") - print(response.data) + factories.TableFactory(floor_id=floor.id, name="Table 02") + factories.TableFactory(floor_id=floor.id, name="Table 03") + response = client.get(url_for("/tables/")) assert response.status_code == HTTPStatus.OK assert b"

Table 01

" in response.data assert b"

Table 02

" in response.data