Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For #430: TableListView test with authentication. #506

Merged
merged 2 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions tests/view/tables/test_tables.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,38 @@
import pytest

from http import HTTPStatus
from flask import g, url_for

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)
response = client.get("/tables/")
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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulodamaso Factory provides method for bulk creation:
factories.TableFactory.create_batch(size=3, floor_id=floor.id, name="Table 01")

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"<div><h1>Table 01</h1></div>" in response.data
assert b"<div><h1>Table 02</h1></div>" in response.data
Expand Down
5 changes: 0 additions & 5 deletions timeless/restaurants/tables/views.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down