Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

cleaning up tests and setup

  • Loading branch information...
commit 9fb5600837d12eb263dfa235be2df10e3ba6471e 1 parent 52db5de
@sorl authored
Showing with 76 additions and 425 deletions.
  1. 0  AUTHORS.txt → AUTHORS
  2. +0 −54 CHANGES.rst
  3. +2 −2 LICENSE.txt → LICENSE
  4. +3 −5 MANIFEST.in
  5. +1 −8 README.rst
  6. +0 −121 bootstrap.py
  7. +0 −51 fabfile.py
  8. +0 −9 manage.py
  9. +2 −0  mockups/base.py
  10. +4 −1 mockups/generators.py
  11. 0  {mockups_tests/sample_app → mockups/tests}/__init__.py
  12. 0  {mockups_tests/mockups_test → mockups/tests/generator_test}/__init__.py
  13. 0  {mockups_tests → mockups/tests/generator_test}/models.py
  14. 0  {mockups_tests → mockups/tests}/generator_test/tests.py
  15. 0  {mockups_tests → mockups/tests}/media/emptyfiles/empty.txt
  16. 0  {mockups_tests → mockups/tests}/media/emptyfiles/nofilextension
  17. 0  {mockups_tests → mockups/tests}/media/textfiles/ispum.txt
  18. 0  {mockups_tests → mockups/tests}/media/textfiles/lorem.txt
  19. 0  {mockups_tests → mockups/tests}/mockups_test/.tests.py.swn
  20. 0  {mockups_tests/generator_test → mockups/tests/mockups_test}/__init__.py
  21. 0  {mockups_tests → mockups/tests}/mockups_test/models.py
  22. +4 −5 {mockups_tests → mockups/tests}/mockups_test/tests.py
  23. 0  {mockups_tests/generator_test → mockups/tests}/models.py
  24. +50 −0 mockups/tests/runtests.py
  25. 0  {mockups_tests → mockups/tests/sample_app}/__init__.py
  26. 0  {mockups_tests → mockups/tests}/sample_app/admin.py
  27. 0  {mockups_tests → mockups/tests}/sample_app/models.py
  28. 0  {mockups_tests → mockups/tests}/urls.py
  29. +0 −2  requirements.txt
  30. +0 −25 runtests.py
  31. +0 −101 settings.py
  32. +10 −41 setup.py
View
0  AUTHORS.txt → AUTHORS
File renamed without changes
View
54 CHANGES.rst
@@ -1,54 +0,0 @@
-Changelog
-=========
-
-0.4.4
------
-* Rename and remake ChoicesGenerator -> ChoiceGenerator + ChoiceFieldGenerator
-
-0.4.3
------
-* Make generators take empty_value keyword argument
-
-0.4.2
------
-* Make ModelMockup take a factory instance as keyword argument for more
- flexibility
-
-0.4.1
------
-* Just a rename of Mockup to ModelMockup
-
-0.4.0
------
-* Major rewrite to use Factory
-
-0.2.6
------
-* Changing syntax to match Django Models & Forms
-
-* Renaming to django-mockups
-
-
-0.2.5
------
-
-* Fixing issue with ``--generate-fk`` option in management command. Thanks
- Mikko Hellsing for the `report and fix`_.
-
-.. _report and fix: http://github.com/gregmuellegger/django-autofixture/issues/issue/1/
-
-0.2.4
------
-
-* Using ``Autofixture.Values`` for defining initial values in ``Autofixture``
- subclasses.
-
-* Making autodiscover more robust. Don't break if some module can't be
- imported or throws any other exception.
-
-0.2.3
------
-
-* Fixing bug when a ``CharField`` with ``max_length`` smaller than 15 is used.
-
-* ``Mockup.field_generators`` accepts callables as values.
View
4 LICENSE.txt → LICENSE
@@ -1,4 +1,4 @@
-DJANGO MOCKUPS
+django-mockups
==============
Copyright (c) 2010, Mikko Hellsing
All rights reserved.
@@ -27,7 +27,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-DJANGO AUTOFIXTURE
+django-autofixture
==================
Copyright (c) 2010, Gregor Müllegger
All rights reserved.
View
8 MANIFEST.in
@@ -1,5 +1,3 @@
-include AUTHORS.txt
-include CHANGES.rst
-include LICENSE.txt
-include MANIFEST.in
-include README.rst
+include AUTHORS LICENSE README.rst
+recursive-include docs *
+recursive-include mockups/tests/media *
View
9 README.rst
@@ -1,7 +1,6 @@
==============
django-mockups
==============
-
This app aims to provide a simple way of loading masses of randomly generated
test data into your development database. You can use a management command to
load test data through command line.
@@ -18,11 +17,9 @@ actually be spent on hacking.
Installation
============
-
You must make the ``mockups`` package available on your python path. Either
drop it into your project directory or install it from the python package index
-with ``pip install django-mockups``. You can also use ``easy_install
-django-mockups`` if you don't have pip available.
+with ``pip install django-mockups``.
To use the management command you must add ``'mockups'`` to the
``INSTALLED_APPS`` setting in your django settings file. You don't need to do
@@ -31,7 +28,6 @@ this if you want to use the ``mockups`` package only as library.
Management command
==================
-
The ``mockups`` accepts the following syntax::
django-admin.py mockups [options] app.Model:# [app.Model:# ...]
@@ -60,7 +56,6 @@ information::
Using mockups as tool for unittests
========================================
-
It has proofed that mockups have a great use for unittests. It has always
bugged me that creating complex models for testing their behaviour was
complicated. Sometimes models have strict restrictions or many related objects
@@ -102,7 +97,6 @@ All created entry models get one to three new categories assigned.
Setting custom values for fields
--------------------------------
-
However its often necessary to be sure that a specific field must have a
specific value. This is easily achieved with the use of ``Factory``::
@@ -117,7 +111,6 @@ specific value. This is easily achieved with the use of ``Factory``::
More
====
-
There is so much more to explore which might be useful for you and your
projects:
View
121 bootstrap.py
@@ -1,121 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Bootstrap a buildout-based project
-
-Simply run this script in a directory containing a buildout.cfg.
-The script accepts buildout command-line options, so you can
-use the -c option to specify an alternate configuration file.
-
-$Id$
-"""
-
-import os, shutil, sys, tempfile, urllib2
-from optparse import OptionParser
-
-tmpeggs = tempfile.mkdtemp()
-
-is_jython = sys.platform.startswith('java')
-
-# parsing arguments
-parser = OptionParser()
-parser.add_option("-v", "--version", dest="version",
- help="use a specific zc.buildout version")
-parser.add_option("-d", "--distribute",
- action="store_true", dest="distribute", default=False,
- help="Use Disribute rather than Setuptools.")
-
-parser.add_option("-c", None, action="store", dest="config_file",
- help=("Specify the path to the buildout configuration "
- "file to be used."))
-
-options, args = parser.parse_args()
-
-# if -c was provided, we push it back into args for buildout' main function
-if options.config_file is not None:
- args += ['-c', options.config_file]
-
-if options.version is not None:
- VERSION = '==%s' % options.version
-else:
- VERSION = ''
-
-USE_DISTRIBUTE = options.distribute
-args = args + ['bootstrap']
-
-to_reload = False
-try:
- import pkg_resources
- if not hasattr(pkg_resources, '_distribute'):
- to_reload = True
- raise ImportError
-except ImportError:
- ez = {}
- if USE_DISTRIBUTE:
- exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
- ).read() in ez
- ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
- else:
- exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
- ).read() in ez
- ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
-
- if to_reload:
- reload(pkg_resources)
- else:
- import pkg_resources
-
-if sys.platform == 'win32':
- def quote(c):
- if ' ' in c:
- return '"%s"' % c # work around spawn lamosity on windows
- else:
- return c
-else:
- def quote (c):
- return c
-
-cmd = 'from setuptools.command.easy_install import main; main()'
-ws = pkg_resources.working_set
-
-if USE_DISTRIBUTE:
- requirement = 'distribute'
-else:
- requirement = 'setuptools'
-
-if is_jython:
- import subprocess
-
- assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
- quote(tmpeggs), 'zc.buildout' + VERSION],
- env=dict(os.environ,
- PYTHONPATH=
- ws.find(pkg_resources.Requirement.parse(requirement)).location
- ),
- ).wait() == 0
-
-else:
- assert os.spawnle(
- os.P_WAIT, sys.executable, quote (sys.executable),
- '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
- dict(os.environ,
- PYTHONPATH=
- ws.find(pkg_resources.Requirement.parse(requirement)).location
- ),
- ) == 0
-
-ws.add_entry(tmpeggs)
-ws.require('zc.buildout' + VERSION)
-import zc.buildout.buildout
-zc.buildout.buildout.main(args)
-shutil.rmtree(tmpeggs)
View
51 fabfile.py
@@ -1,51 +0,0 @@
-# -*- coding: utf-8 -*-
-import os
-from fabric.api import abort, cd, local, env, run, settings, sudo
-
-
-#################
-# Documentation #
-#################
-
-def packagedocs():
- builddocs('html')
- try:
- os.mkdir('dist')
- except OSError:
- pass
- with cd('docs/_build/html'):
- local('find -print | zip docs.zip -@')
- local('mv docs/_build/html/docs.zip dist')
-
-def builddocs(output='html'):
- with cd('docs'):
- local('make %s' % output, capture=False)
-
-def opendocs(where='index', how='default'):
- '''
- Rebuild documentation and opens it in your browser.
-
- Use the first argument to specify how it should be opened:
-
- `d` or `default`: Open in new tab or new window, using the default
- method of your browser.
-
- `t` or `tab`: Open documentation in new tab.
-
- `n`, `w` or `window`: Open documentation in new window.
- '''
- import webbrowser
- docs_dir = os.path.join(
- os.path.dirname(os.path.abspath(__file__)),
- 'docs')
- index = os.path.join(docs_dir, '_build/html/%s.html' % where)
- builddocs('html')
- url = 'file://%s' % os.path.abspath(index)
- if how in ('d', 'default'):
- webbrowser.open(url)
- elif how in ('t', 'tab'):
- webbrowser.open_new_tab(url)
- elif how in ('n', 'w', 'window'):
- webbrowser.open_new(url)
-
-docs = opendocs
View
9 manage.py
@@ -1,9 +0,0 @@
-#!/usr/bin/env python
-import os
-
-os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
-
-
-if __name__ == '__main__':
- from django.core.management import execute_from_command_line
- execute_from_command_line()
View
2  mockups/base.py
@@ -8,9 +8,11 @@
class IGNORE_FIELD(object):
pass
+
class CreateInstanceError(Exception):
pass
+
class Link(object):
'''
Handles logic of following or generating foreignkeys and m2m relations.
View
5 mockups/generators.py
@@ -165,12 +165,15 @@ def generate(self):
lorem = lorem[:max(1, length)]
return lorem.strip()
+
class LoremSentenceGenerator(LoremGenerator):
method = 's'
+
class LoremHTMLGenerator(LoremGenerator):
method = 'p'
+
class LoremWordGenerator(LoremGenerator):
count = 7
method = 'w'
@@ -417,6 +420,7 @@ def generate(self):
filename = relpath(filename, settings.MEDIA_ROOT)
return filename
+
# TODO: try to get this thing out of here
class InstanceGenerator(Generator):
'''
@@ -607,4 +611,3 @@ def get_generator(self, field, **kwargs):
return IntegerGenerator(min_value=-field.MAX_BIGINT - 1,
max_value=field.MAX_BIGINT)
-
View
0  mockups_tests/sample_app/__init__.py → mockups/tests/__init__.py
File renamed without changes
View
0  mockups_tests/mockups_test/__init__.py → mockups/tests/generator_test/__init__.py
File renamed without changes
View
0  mockups_tests/models.py → mockups/tests/generator_test/models.py
File renamed without changes
View
0  mockups_tests/generator_test/tests.py → mockups/tests/generator_test/tests.py
File renamed without changes
View
0  mockups_tests/media/emptyfiles/empty.txt → mockups/tests/media/emptyfiles/empty.txt
File renamed without changes
View
0  mockups_tests/media/emptyfiles/nofilextension → mockups/tests/media/emptyfiles/nofilextension
File renamed without changes
View
0  mockups_tests/media/textfiles/ispum.txt → mockups/tests/media/textfiles/ispum.txt
File renamed without changes
View
0  mockups_tests/media/textfiles/lorem.txt → mockups/tests/media/textfiles/lorem.txt
File renamed without changes
View
0  mockups_tests/mockups_test/.tests.py.swn → mockups/tests/mockups_test/.tests.py.swn
File renamed without changes
View
0  mockups_tests/generator_test/__init__.py → mockups/tests/mockups_test/__init__.py
File renamed without changes
View
0  mockups_tests/mockups_test/models.py → mockups/tests/mockups_test/models.py
File renamed without changes
View
9 mockups_tests/mockups_test/tests.py → mockups/tests/mockups_test/tests.py
@@ -6,11 +6,10 @@
from mockups import generators
from mockups import Factory
from mockups.base import ModelMockup, CreateInstanceError, Link
-from mockups_tests.mockups_test.models import y2k
-from mockups_tests.mockups_test.models import (
- SimpleModel, OtherSimpleModel, DeepLinkModel1, DeepLinkModel2,
- NullableFKModel, BasicModel, UniqueTestModel, UniqueTogetherTestModel,
- RelatedModel, O2OModel, M2MModel, ThroughModel, M2MModelThrough)
+from mockups_test.models import (y2k, SimpleModel, OtherSimpleModel,
+ DeepLinkModel1, DeepLinkModel2, NullableFKModel, BasicModel,
+ UniqueTestModel, UniqueTogetherTestModel, RelatedModel, O2OModel,
+ M2MModel, ThroughModel, M2MModelThrough)
class SimpleFactory(Factory):
View
0  mockups_tests/generator_test/models.py → mockups/tests/models.py
File renamed without changes
View
50 mockups/tests/runtests.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+from os.path import abspath, dirname, join as pjoin
+from os import pardir
+import sys
+from django.conf import settings
+
+
+TEST_ROOT = abspath(dirname(__file__))
+
+
+if not settings.configured:
+ settings.configure(
+ TEST_ROOT = TEST_ROOT,
+ DATABASE_ENGINE = 'sqlite3',
+ DATABASE_NAME = pjoin(TEST_ROOT, 'test.sqlite'),
+ MEDIA_URL = '/media/',
+ MEDIA_ROOT = pjoin(TEST_ROOT, 'media'),
+ STATIC_URL = '/static/',
+ ADMIN_MEDIA_PREFIX = '/static/admin/',
+ STATIC_ROOT = pjoin(TEST_ROOT, 'static'),
+ ROOT_URLCONF = 'mockups.tests.urls',
+ TEMPLATE_DIRS = (
+ pjoin(TEST_ROOT, 'templates'),
+ ),
+ INSTALLED_APPS = [
+ 'mockups',
+ 'mockups.tests',
+ 'mockups.tests.generator_test',
+ 'mockups.tests.mockups_test',
+ 'mockups.tests.sample_app',
+ ],
+ )
+
+from django.test.simple import run_tests
+
+
+def runtests(*test_labels):
+ test_labels = test_labels or [
+ 'mockups',
+ 'generator_test',
+ 'mockups_test',
+ ]
+ sys.path.insert(0, pjoin(TEST_ROOT, pardir, pardir))
+ failures = run_tests(test_labels , verbosity=1, interactive=True)
+ sys.exit(failures)
+
+
+if __name__ == '__main__':
+ runtests(*sys.argv[1:])
+
View
0  mockups_tests/__init__.py → mockups/tests/sample_app/__init__.py
File renamed without changes
View
0  mockups_tests/sample_app/admin.py → mockups/tests/sample_app/admin.py
File renamed without changes
View
0  mockups_tests/sample_app/models.py → mockups/tests/sample_app/models.py
File renamed without changes
View
0  mockups_tests/urls.py → mockups/tests/urls.py
File renamed without changes
View
2  requirements.txt
@@ -1,2 +0,0 @@
-django
-django-extensions
View
25 runtests.py
@@ -1,25 +0,0 @@
-#!/usr/bin/env python
-import os, sys
-
-os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
-parent = os.path.dirname(os.path.abspath(__file__))
-
-sys.path.insert(0, parent)
-
-from django.test.simple import run_tests
-
-
-def runtests(*args):
- failures = run_tests(
- args or [
- 'mockups',
- 'mockups_tests',
- 'mockups_test',
- 'generator_test',
- 'sample_app',
- ],
- verbosity=1, interactive=True)
- sys.exit(failures)
-
-if __name__ == '__main__':
- runtests(*sys.argv[1:])
View
101 settings.py
@@ -1,101 +0,0 @@
-# Django settings for testsite project.
-import os
-PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
-
-DEBUG = True
-TEMPLATE_DEBUG = DEBUG
-
-ADMINS = (
- # ('Your Name', 'your_email@domain.com'),
-)
-
-MANAGERS = ADMINS
-
-DATABASE_ENGINE = 'sqlite3' # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
-DATABASE_NAME = os.path.join(PROJECT_ROOT, 'db.sqlite') # Or path to database file if using sqlite3.
-DATABASE_USER = '' # Not used with sqlite3.
-DATABASE_PASSWORD = '' # Not used with sqlite3.
-DATABASE_HOST = '' # Set to empty string for localhost. Not used with sqlite3.
-DATABASE_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.
-# 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
-
-# Absolute path to the directory that holds media.
-# Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'mockups_tests', 'media')
-
-# URL that handles the media served from MEDIA_ROOT. Make sure to use a
-# trailing slash if there is a path component (optional in other cases).
-# Examples: "http://media.lawrence.com", "http://example.com/media/"
-MEDIA_URL = '/media/'
-
-# 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/admin/'
-
-# Make this unique, and don't share it with anybody.
-SECRET_KEY = '<REPLACE:SECRET_KEY>'
-
-# List of callables that know how to import templates from various sources.
-TEMPLATE_LOADERS = (
- 'django.template.loaders.filesystem.load_template_source',
- 'django.template.loaders.app_directories.load_template_source',
-# 'django.template.loaders.eggs.load_template_source',
-)
-
-MIDDLEWARE_CLASSES = (
- 'django.middleware.common.CommonMiddleware',
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- 'django.middleware.doc.XViewMiddleware',
-)
-
-ROOT_URLCONF = 'mockups_tests.urls'
-
-TEMPLATE_DIRS = (
- os.path.join(PROJECT_ROOT, 'mockups_tests', 'templates'),
-)
-
-INSTALLED_APPS = (
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.sites',
- 'django.contrib.admin',
-
- 'django_extensions',
-
- 'mockups_tests',
- 'mockups_tests.sample_app',
- 'mockups_tests.mockups_test',
- 'mockups_tests.generator_test',
- 'mockups',
-)
-
-TEMPLATE_CONTEXT_PROCESSORS = (
- "django.core.context_processors.auth",
- "django.core.context_processors.debug",
- "django.core.context_processors.i18n",
- "django.core.context_processors.media",
-)
-
-try:
- from local_settings import *
-except ImportError:
- pass
View
51 setup.py
@@ -1,44 +1,19 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-from setuptools import setup
-
-
-class UltraMagicString(object):
- '''
- Taken from
- http://stackoverflow.com/questions/1162338/whats-the-right-way-to-use-unicode-metadata-in-setup-py
- '''
- def __init__(self, value):
- self.value = value
-
- def __str__(self):
- return self.value
-
- def __unicode__(self):
- return self.value.decode('UTF-8')
-
- def __add__(self, other):
- return UltraMagicString(self.value + str(other))
-
- def split(self, *args, **kw):
- return self.value.split(*args, **kw)
-
-
-long_description = UltraMagicString(u'\n\n'.join((
- file('README.rst').read(),
- file('CHANGES.rst').read(),
-)))
+from setuptools import setup, find_packages
setup(
name = 'django-mockups',
- version = '0.4.4',
- url = 'https://github.com/sorl/django-mockups',
- license = 'BSD',
+ version = '0.4.5',
description = 'Provides tools to auto generate content.',
- long_description = long_description,
- author = UltraMagicString('Mikko Hellsing'),
+ long_description = open('README.rst').read(),
+ author = 'Mikko Hellsing',
author_email = 'mikko@aino.se',
+ url = 'https://github.com/sorl/django-mockups',
+ license = 'BSD',
+ platforms='any',
+ packages=find_packages(),
+ include_package_data=True,
+ zip_safe=False,
classifiers = [
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
@@ -49,10 +24,4 @@ def split(self, *args, **kw):
'Operating System :: OS Independent',
'Programming Language :: Python',
],
- packages = [
- 'mockups',
- 'mockups.management',
- 'mockups.management.commands'],
- install_requires = ['setuptools'],
- test_suite = 'runtests.runtests',
)
Please sign in to comment.
Something went wrong with that request. Please try again.