Browse Source

Migra e corrige restante dos testes do crud

pull/216/head
Marcio Mazza 9 years ago
committed by Eduardo Edson Batista Cordeiro Alves
parent
commit
fca5602e37
  1. 33
      crud_tests/settings.py
  2. 43
      crud_tests/templates/base.html
  3. 25
      crud_tests/test_flux.py
  4. 2
      pytest.ini
  5. 3
      test_and_check_qa.sh

33
crud_tests/settings.py

@ -1,7 +1,12 @@
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DATABASES = { DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.sqlite3', 'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:', # 'NAME': ':memory:',
'NAME': '/tmp/db',
}, },
} }
@ -9,6 +14,7 @@ INSTALLED_APPS = (
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.sessions',
'crud_tests', 'crud_tests',
'crispy_forms', 'crispy_forms',
) )
@ -21,9 +27,34 @@ SECRET_KEY = 'zzz...'
TEMPLATES = [{ TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'crud_tests/templates'), os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
"django.core.context_processors.media",
"django.core.context_processors.static",
'django.contrib.messages.context_processors.messages',
],
},
}] }]
STATIC_URL = '/static/'
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.middleware.locale.LocaleMiddleware',
# 'django.middleware.common.CommonMiddleware',
# 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
# 'django.middleware.security.SecurityMiddleware',
)
SILENCED_SYSTEM_CHECKS = [ SILENCED_SYSTEM_CHECKS = [
'1_7.W001', # Unset MIDDLEWARE_CLASSES warning '1_7.W001', # Unset MIDDLEWARE_CLASSES warning
] ]

43
crud_tests/templates/base.html

@ -0,0 +1,43 @@
{% load i18n %}
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="pt-br">
<!--<![endif]-->
<body>
<main id="content" class="content page__row">
<div class="container">
{# Feedback messages #}
{% for message in messages %}
<div class="alert alert-{% if message.tags == 'error' %}danger{% else %}{{ message.tags }}{% endif %} alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
{{ message|safe }}
</div>
{% endfor %}
{# Content header #}
{% block base_header %}
<div class="clearfix">
{% block title %}
{% if view.title %}
<h1 class="page-header">{{ view.title|linebreaksbr }}</h1>
{% endif %}
{% endblock %}
</div>
{% endblock base_header %}
{# Content per se #}
{% block base_content %}{% endblock %}
</div>
</main>
</body>
</html>

25
crud_tests/test_flux.py

@ -160,7 +160,6 @@ def assert_on_detail_page(res, stub_name):
assert 'Excluir' in res assert 'Excluir' in res
@pytest.mark.urls('sapl.teststubs.urls_for_list_test')
@pytest.mark.parametrize("num_entries, page_size, ranges, page_list", [ @pytest.mark.parametrize("num_entries, page_size, ranges, page_list", [
(0, 6, [], []), (0, 6, [], []),
(5, 5, [(0, 5)], []), (5, 5, [(0, 5)], []),
@ -172,13 +171,17 @@ def test_flux_list_paginate_detail(
entries_labels = [] entries_labels = []
for i in range(num_entries): for i in range(num_entries):
# letter = next(letters)
name, continent = 'name %s' % i, 'continent %s' % i name, continent = 'name %s' % i, 'continent %s' % i
entries_labels.append([name, continent]) population, is_cold = i, i % 2 == 0
mommy.make(Country, name=name, continent__name=continent) entries_labels.append([
name, continent, str(population), 'Yes' if is_cold else 'No'])
mommy.make(Country,
name=name,
continent__name=continent,
population=population,
is_cold=is_cold)
from .teststubs.urls_for_list_test import crud country_crud.CrudListView.paginate_by = page_size
crud.CrudListView.paginate_by = page_size
res = app.get('/countries/') res = app.get('/countries/')
@ -195,8 +198,8 @@ def test_flux_list_paginate_detail(
table = res.html.find('table') table = res.html.find('table')
assert table assert table
header, *trs = table.findAll('tr') header, *trs = table.findAll('tr')
assert header.text.strip().split() == [ assert [c.text for c in header.findChildren('th')] == [
'name', 'Sigla', 'continent'] 'name', 'continent', 'population', 'is cold']
rows = [[td.text.strip() for td in tr.findAll('td')] rows = [[td.text.strip() for td in tr.findAll('td')]
for tr in trs] for tr in trs]
@ -264,11 +267,11 @@ def test_flux_list_create_detail(app, cancel, make_invalid_submit):
# now fill out some fields # now fill out some fields
form = res.form form = res.form
stub_name = '### name Especial ###' stub_name = '### name ###'
form['name'] = stub_name form['name'] = stub_name
form['sigla'] = 'SIGLA'
form['continent'] = stub_continent.id form['continent'] = stub_continent.id
form['data_criacao'] = '1/1/2001' form['population'] = 23000
form['is_cold'] = True
res = form.submit() res = form.submit()
# on redirect to detail page # on redirect to detail page

2
pytest.ini

@ -1,6 +1,6 @@
[pytest] [pytest]
DJANGO_SETTINGS_MODULE=sapl.settings DJANGO_SETTINGS_MODULE=sapl.settings
norecursedirs = legacy norecursedirs = legacy crud_tests
# REUSING DATABASE BY DEFAULT (as a performance optimization) # REUSING DATABASE BY DEFAULT (as a performance optimization)
# http://pytest-django.readthedocs.org/en/latest/database.html#example-work-flow-with-reuse-db-and-create-db # http://pytest-django.readthedocs.org/en/latest/database.html#example-work-flow-with-reuse-db-and-create-db

3
test_and_check_qa.sh

@ -3,4 +3,5 @@
# QA checks: run this before every commit # QA checks: run this before every commit
py.test py.test
./qa_check.sh py.test --ds=crud_tests.settings crud_tests
./check_qa.sh

Loading…
Cancel
Save