Support to unique test configuration
This commit is contained in:
parent
c86a0917cb
commit
9601828618
11 changed files with 47 additions and 24 deletions
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# django-pyvows extensions
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# django-pyvows extensions
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# django-pyvows extensions
|
||||
|
@ -20,15 +19,19 @@ from django_pyvows.settings_helpers import SettingsOverrideSupport
|
|||
class DjangoContext(Vows.Context, HttpClientSupport, SettingsOverrideSupport):
|
||||
def __init__(self, parent):
|
||||
super(DjangoContext, self).__init__(parent)
|
||||
|
||||
HttpClientSupport.__init__(self)
|
||||
SettingsOverrideSupport.__init__(self)
|
||||
self.ignore('start_environment', 'settings_module')
|
||||
|
||||
self.ignore('setup_environment', 'settings_module')
|
||||
|
||||
DjangoContext.setup_environment(self.settings_module())
|
||||
|
||||
def settings_module(self):
|
||||
return 'settings'
|
||||
|
||||
@classmethod
|
||||
def start_environment(cls, settings_module):
|
||||
def setup_environment(cls, settings_module):
|
||||
if not settings_module:
|
||||
raise ValueError('The settings_path argument is required.')
|
||||
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# django-pyvows extensions
|
||||
# https://github.com/rafaelcaricio/django-pyvows
|
||||
|
||||
# Licensed under the MIT license:
|
||||
# http://www.opensource.org/licenses/mit-license
|
||||
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
||||
|
||||
|
||||
class HttpClientSupport(object):
|
||||
def __init__(self):
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# django-pyvows extensions
|
||||
# https://github.com/rafaelcaricio/django-pyvows
|
||||
|
||||
# Licensed under the MIT license:
|
||||
# http://www.opensource.org/licenses/mit-license
|
||||
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
||||
|
||||
|
||||
class SettingsOverrideSupport(object):
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# django-pyvows extensions
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# django-pyvows extensions
|
||||
|
@ -10,9 +9,7 @@
|
|||
|
||||
from pyvows import Vows, expect
|
||||
|
||||
from django_pyvows.context import DjangoContext
|
||||
|
||||
DjangoContext.start_environment("sandbox.sandbox.settings")
|
||||
from test_config import ConfiguredVowsContext as DjangoContext
|
||||
|
||||
|
||||
@Vows.batch
|
||||
|
|
|
@ -7,16 +7,10 @@
|
|||
# Licensed under the MIT license:
|
||||
# http://www.opensource.org/licenses/mit-license
|
||||
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
||||
from os.path import abspath, join, dirname
|
||||
|
||||
from pyvows import Vows, expect
|
||||
|
||||
from django_pyvows.context import DjangoContext
|
||||
|
||||
|
||||
TEST_FILE_PATH = abspath(join(dirname(__file__), 'fixtures/the_file.txt'))
|
||||
|
||||
DjangoContext.start_environment("sandbox.sandbox.settings")
|
||||
from test_config import ConfiguredVowsContext as DjangoContext
|
||||
|
||||
|
||||
@Vows.batch
|
||||
|
@ -48,14 +42,14 @@ class DjangoHTTPTestClientCompatibilityVows(DjangoContext):
|
|||
|
||||
class PostFile(DjangoContext):
|
||||
def topic(self):
|
||||
return self.post('/post_file/', {'the_file': open(TEST_FILE_PATH)})
|
||||
return self.post('/post_file/', {'the_file': open(self.TEST_FILE_PATH)})
|
||||
|
||||
def should_be_posted_to_the_server(self, topic):
|
||||
expect(topic.content).to_equal("the contents")
|
||||
|
||||
class WhenNotFound(DjangoContext):
|
||||
def topic(self):
|
||||
return self.post('/post_/', {'the_file': open(TEST_FILE_PATH)})
|
||||
return self.post('/post_/', {'the_file': open(self.TEST_FILE_PATH)})
|
||||
|
||||
def should_be_404(self, topic):
|
||||
expect(topic.status_code).to_equal(404)
|
||||
|
|
|
@ -19,7 +19,7 @@ class ContextTest(Vows.Context):
|
|||
|
||||
@capture_error
|
||||
def topic(self):
|
||||
return DjangoContext.start_environment(None)
|
||||
return DjangoContext.setup_environment(None)
|
||||
|
||||
def should_be_an_error(self, topic):
|
||||
expect(topic).to_be_an_error()
|
||||
|
|
|
@ -11,9 +11,7 @@
|
|||
from pyvows import Vows, expect
|
||||
from django.test.utils import override_settings
|
||||
|
||||
from django_pyvows.context import DjangoContext
|
||||
|
||||
DjangoContext.start_environment("sandbox.sandbox.settings")
|
||||
from test_config import ConfiguredVowsContext as DjangoContext
|
||||
|
||||
|
||||
@Vows.batch
|
||||
|
|
20
vows/test_config.py
Normal file
20
vows/test_config.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# django-pyvows extensions
|
||||
# https://github.com/rafaelcaricio/django-pyvows
|
||||
|
||||
# Licensed under the MIT license:
|
||||
# http://www.opensource.org/licenses/mit-license
|
||||
# Copyright (c) 2011 Rafael Caricio rafael@caricio.com
|
||||
|
||||
from os.path import abspath, join, dirname
|
||||
|
||||
from django_pyvows.context import DjangoContext
|
||||
|
||||
|
||||
class ConfiguredVowsContext(DjangoContext):
|
||||
def settings_module(self):
|
||||
return 'sandbox.sandbox.settings'
|
||||
|
||||
def setup(self):
|
||||
self.TEST_FILE_PATH = abspath(join(dirname(__file__), 'fixtures/the_file.txt'))
|
Reference in a new issue