Commit b9b6576a by Gabriel Falcao

forcing lettuce to fail when a hook fails. closes #275

parent 615bf9aa
...@@ -138,8 +138,11 @@ class Command(BaseCommand): ...@@ -138,8 +138,11 @@ class Command(BaseCommand):
results.append(result) results.append(result)
if not result or result.steps != result.steps_passed: if not result or result.steps != result.steps_passed:
failed = True failed = True
except SystemExit, e:
failed = e.code
except Exception, e: except Exception, e:
failed = True
import traceback import traceback
traceback.print_exc(e) traceback.print_exc(e)
......
...@@ -86,7 +86,7 @@ def call_hook(situation, kind, *args, **kw): ...@@ -86,7 +86,7 @@ def call_hook(situation, kind, *args, **kw):
except Exception, e: except Exception, e:
traceback.print_exc(e) traceback.print_exc(e)
print print
sys.exit(2) raise SystemExit(2)
def clear(): def clear():
......
Feature: server crashed
Scenario: Crashing from hooks
Given I go to "/"
Then I get a 404
# -*- coding: utf-8 -*-
import urllib2
from nose.tools import assert_equals
from lettuce import step, world
from lettuce.django import django_url
@world.absorb
def get_url(url):
if not url.startswith('http'):
url = django_url(url)
try:
world.last_response = urllib2.urlopen(url)
except Exception, e:
world.last_response = e
return world.last_response
@step(u'Given I go to "([^"]*)"')
def given_i_go_to_group1(step, url):
world.get_url(url)
@step(u'Then I get a 404')
def then_i_get_a_404(step):
assert_equals(world.last_response.code, 404)
#!/usr/bin/env python
from django.core.management import execute_manager
try:
import settings # Assumed to be in the same directory.
except ImportError:
import sys
sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
sys.exit(1)
if __name__ == "__main__":
execute_manager(settings)
# Django settings for chive project.
from os.path import dirname, abspath, join
LOCAL_FILE = lambda *path: abspath(join(dirname(__file__), *path))
DEBUG = False
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@domain.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': '', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': '', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
# although not all choices may be available on all operating systems.
# On Unix systems, a value of None will cause Django to use the same
# timezone as the operating system.
# If running in a Windows environment this must be set to the same as your
# system time zone.
TIME_ZONE = 'America/Chicago'
# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'
SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale
USE_L10N = True
# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
# trailing slash.
# Examples: "http://foo.com/media/", "/media/".
ADMIN_MEDIA_PREFIX = '/media/'
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/home/media/media.lawrence.com/media/"
MEDIA_ROOT = ''
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://media.lawrence.com/media/", "http://example.com/media/"
MEDIA_URL = ''
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = ''
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
# Make this unique, and don't share it with anybody.
SECRET_KEY = 'gw$-1dpq0k8xc+fqkywqr0$c3^fg)x!ym*^46=jmc@ql&z)pr8'
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
# 'django.template.loaders.eggs.Loader',
)
ROOT_URLCONF = 'chive.urls'
TEMPLATE_DIRS = (
LOCAL_FILE('templates'),
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'lettuce.django',
)
LETTUCE_SERVER_PORT = 7000
STATIC_FILES_AT = LOCAL_FILE('static-files')
STATICFILES_DIRS = [
STATIC_FILES_AT,
]
<html><body><h1>404</h1></body></html>
<html><body><h1>500</h1></body></html>
# -*- coding: utf-8 -*-
from lettuce import before
from django.contrib.auth.models import User
@before.each_feature
def cause_exception(variables):
User.objects.create_user(
username='foo',
password='bar',
)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^ouch', 'views.ouch'),
)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def ouch(request):
raise SystemExit(3)
# -*- coding: utf-8 -*-
# <Lettuce - Behaviour Driven Development for python>
# Copyright (C) <2010-2012> Gabriel Falcão <gabriel@nacaolivre.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import commands
from tests.asserts import assert_not_equals
from lettuce.fs import FileSystem
current_directory = FileSystem.dirname(__file__)
lib_directory = FileSystem.join(current_directory, 'lib')
OLD_PYTHONPATH = os.getenv('PYTHONPATH', ':'.join(sys.path))
def teardown():
os.environ['PYTHONPATH'] = OLD_PYTHONPATH
def test_django_admin_media_serving_on_django_13():
'lettuce should serve admin static files properly on Django 1.3'
os.environ['PYTHONPATH'] = "%s:%s" % (
FileSystem.join(lib_directory, 'Django-1.3'),
OLD_PYTHONPATH,
)
FileSystem.pushd(current_directory, "django", "chive")
status, out = commands.getstatusoutput(
"python manage.py harvest --verbosity=2 ./features/")
assert_not_equals(status, 0)
FileSystem.popd()
lines = out.splitlines()
assert u"Preparing to serve django's admin site static files..." in lines
assert u"Django's builtin server is running at 0.0.0.0:7000" in lines
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment