Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request from 'codeinthehole/app-to-library'

  • Loading branch information...
commit 2106372836d66bb57727837b1f549068fc9884c2 2 parents a0173ae + 4598714
anthony-tresontani authored
1  .gitignore
View
@@ -1,2 +1,3 @@
*.pyc
.idea/*
+dist
5 adaptor/fields.py
View
@@ -67,8 +67,9 @@ def get_prep_value(self, value, instance=None):
if hasattr(self, "transform"):
value = self.transform(value)
else:
- transform = getattr(instance, "transform_" + self.fieldname, lambda inst, val:val)
- value = transform(value)
+ if hasattr(self, "fieldname") and instance:
+ transform = getattr(instance, "transform_" + self.fieldname, lambda val: val)
+ value = transform(value)
if hasattr(self, "validator"):
validator = self.validator()
if not validator.validate(value):
1  adaptor/model.py
View
@@ -66,6 +66,7 @@ def get_fields(cls):
Field)]
for fieldname, field in attributes:
field.fieldname = fieldname
+
sorted_field = sorted(attributes, key=lambda attrs: attrs[1].position)
return sorted_field
0  adaptor/models.py
View
No changes.
2  makefile
View
@@ -1,7 +1,7 @@
.PHONY: test
test:
- python manage.py test --settings=test_settings
+ ./runtests.py
performance:
echo "from performance import *; test_performance()"| python manage.py shell
14 manage.py
View
@@ -1,14 +0,0 @@
-#!/usr/bin/env python
-from django.core.management import execute_manager
-import imp
-try:
- imp.find_module('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" % __file__)
- sys.exit(1)
-
-import settings
-
-if __name__ == "__main__":
- execute_manager(settings)
16 myTestModel/tests.py
View
@@ -1,16 +0,0 @@
-"""
-This file demonstrates writing tests using the unittest module. These will pass
-when you run "manage.py test".
-
-Replace this with more appropriate tests for your application.
-"""
-
-from django.test import TestCase
-
-
-class SimpleTest(TestCase):
- def test_basic_addition(self):
- """
- Tests that 1 + 1 always equals 2.
- """
- self.assertEqual(1 + 1, 2)
1  myTestModel/views.py
View
@@ -1 +0,0 @@
-# Create your views here.
2  requirements.txt
View
@@ -1,6 +1,4 @@
-Django==1.4
argparse==1.2.1
django-nose==1.1
-lxml==2.3.4
nose==1.1.2
wsgiref==0.1.2
34 runtests.py
View
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+import sys
+from optparse import OptionParser
+
+from django.conf import settings
+
+if not settings.configured:
+ settings.configure(
+ DATABASES={
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ }
+ },
+ INSTALLED_APPS=[
+ 'tests.test_app',
+ ],
+ )
+
+from django_nose import NoseTestSuiteRunner
+
+
+def run_tests(nose_options, test_args):
+ if not test_args:
+ test_args = ['tests']
+ test_runner = NoseTestSuiteRunner(verbosity=nose_options.verbosity)
+ failures = test_runner.run_tests(test_args)
+ sys.exit(failures)
+
+if __name__ == '__main__':
+ parser = OptionParser()
+ parser.add_option('-v', '--verbose', dest='verbosity', default=1, type=int)
+ (options, args) = parser.parse_args()
+
+ run_tests(options, args)
0  settings.py
View
No changes.
12 setup.py
View
@@ -10,13 +10,17 @@ def read(fname):
description='Convert CSV/XML files into python object or django model',
author='Anthony Tresontani',
author_email='dev.tresontani@gmail.com',
- long_description =read('README.txt'),
- license = "BSD",
- keywords = "CSV XML Django adaptor",
+ long_description=read('README.txt'),
+ license="BSD",
+ keywords="CSV XML Django adaptor",
packages=['adaptor'],
+ install_requires=[
+ 'lxml==2.3.4',
+ 'Django==1.4',
+ ],
classifiers=[
"Development Status :: 3 - Alpha",
"Topic :: Utilities",
"License :: OSI Approved :: BSD License",
],
- )
+)
149 test_settings.py
View
@@ -1,149 +0,0 @@
-# Django settings for adaptor project.
-import os
-BASE_DIR = os.path.dirname(__file__)
-
-
-DEBUG = True
-TEMPLATE_DEBUG = DEBUG
-
-ADMINS = (
- # ('Your Name', 'your_email@example.com'),
-)
-
-MANAGERS = ADMINS
-
-DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': os.path.join(BASE_DIR,'test_db'), # 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
-
-# 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/'
-
-# URL prefix for admin static files -- CSS, JavaScript and images.
-# Make sure to use a trailing slash.
-# Examples: "http://foo.com/static/admin/", "/static/admin/".
-ADMIN_MEDIA_PREFIX = '/static/admin/'
-
-# Additional locations of static files
-STATICFILES_DIRS = (
- # Put strings here, like "/home/html/static" or "C:/www/django/static".
- # Always use forward slashes, even on Windows.
- # Don't forget to use absolute paths, not relative paths.
-)
-
-# List of finder classes that know how to find static files in
-# various locations.
-STATICFILES_FINDERS = (
- 'django.contrib.staticfiles.finders.FileSystemFinder',
- 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
-# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
-)
-
-# Make this unique, and don't share it with anybody.
-SECRET_KEY = '7w&644i+-5djdf$z0u5nfutimep*gu%vdb$c!(qb9)(vbidzmh'
-
-# 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',
-)
-
-MIDDLEWARE_CLASSES = (
- 'django.middleware.common.CommonMiddleware',
- 'django.contrib.sessions.middleware.SessionMiddleware',
- 'django.middleware.csrf.CsrfViewMiddleware',
- 'django.contrib.auth.middleware.AuthenticationMiddleware',
- 'django.contrib.messages.middleware.MessageMiddleware',
-)
-
-ROOT_URLCONF = 'adaptor.urls'
-
-#TEMPLATE_DIRS = ('C:/Users/trez/PycharmProjects/csv_importer/templates',)
-
-INSTALLED_APPS = (
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.sites',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- # Uncomment the next line to enable the admin:
- # 'django.contrib.admin',
- # Uncomment the next line to enable admin documentation:
- # 'django.contrib.admindocs',
- 'adaptor',
- 'myTestModel',
- 'django_nose',
-)
-
-# A sample logging configuration. The only tangible logging
-# performed by this configuration is to send an email to
-# the site admins on every HTTP 500 error.
-# See http://docs.djangoproject.com/en/dev/topics/logging for
-# more details on how to customize your logging configuration.
-LOGGING = {
- 'version': 1,
- 'disable_existing_loggers': False,
- 'handlers': {
- 'mail_admins': {
- 'level': 'ERROR',
- 'class': 'django.utils.log.AdminEmailHandler'
- }
- },
- 'loggers': {
- 'django.request': {
- 'handlers': ['mail_admins'],
- 'level': 'ERROR',
- 'propagate': True,
- },
- }
-}
-
-TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
0  myTestModel/__init__.py → tests/__init__.py
View
File renamed without changes
0  test/csv1.csv → tests/fixtures/csv1.csv
View
File renamed without changes
0  test/csv2.csv → tests/fixtures/csv2.csv
View
File renamed without changes
0  test/csv3.csv → tests/fixtures/csv3.csv
View
File renamed without changes
0  test/csv4-error.csv → tests/fixtures/csv4-error.csv
View
File renamed without changes
15 adaptor/tests.py → tests/main_tests.py
View
@@ -1,10 +1,10 @@
from datetime import datetime
from django.test import TestCase
-from fields import *
-from model import CsvModel, CsvDbModel, ImproperlyConfigured,\
+from adaptor.fields import *
+from adaptor.model import CsvModel, CsvDbModel, ImproperlyConfigured,\
CsvException, CsvDataException, TabularLayout, SkipRow,\
GroupedCsvModel, XMLModel,CsvFieldDataException
-from myTestModel.models import *
+from tests.test_app.models import *
class TestCsvModel(CsvModel):
@@ -138,7 +138,7 @@ def test_default_value(self):
test = TestCsvModel.import_data(data=TestCsvModel.test_data_missing)
def test_real_file(self):
- file = open("test/csv1.csv")
+ file = open("tests/fixtures/csv1.csv")
test = TestCsvModel.import_from_file(file)
line1 = test[0]
self.assertEquals(line1.nom, 'Roger')
@@ -146,7 +146,7 @@ def test_real_file(self):
self.assertEquals(line1.taille, 1.8)
def test_db_model(self):
- test = TestCsvDBModel.import_from_filename("test/csv2.csv")
+ test = TestCsvDBModel.import_from_filename("tests/fixtures/csv2.csv")
self.assertEquals(MyModel.objects.all().count(), 2)
@@ -177,7 +177,7 @@ class Meta:
dbModel = MyModel
- test = TestCsvDBUnmatchingModel.import_from_filename("test/csv1.csv")
+ test = TestCsvDBUnmatchingModel.import_from_filename("tests/fixtures/csv1.csv")
self.assertEquals(MyModel.objects.all().count(), 1)
obj = test[0].get_object()
@@ -257,7 +257,7 @@ class TestCsvWithHeader(TestCsvModel):
class Meta:
dbModel = MyModel
- test = TestCsvWithHeader.import_from_filename("test/csv3.csv")
+ test = TestCsvWithHeader.import_from_filename("tests/fixtures/csv3.csv")
self.assertEquals(MyModel.objects.all().count(), 23)
def test_error_message_foreign(self):
@@ -524,6 +524,7 @@ class Meta:
MyModel.objects.create(nom="name",age=12, taille=1.2)
self.assertRaises(CsvFieldDataException, TestMatchCsv.import_data, ["name"])
+
class TestGroupCsv(TestCase):
def test_simple_group(self):
class TestCsv1(CsvModel):
0  __init__.py → tests/test_app/__init__.py
View
File renamed without changes
0  myTestModel/models.py → tests/test_app/models.py
View
File renamed without changes
17 urls.py
View
@@ -1,17 +0,0 @@
-from django.conf.urls.defaults import patterns, include, url
-
-# Uncomment the next two lines to enable the admin:
-# from django.contrib import admin
-# admin.autodiscover()
-
-urlpatterns = patterns('',
- # Examples:
- # url(r'^$', 'csv_importer.views.home', name='home'),
- # url(r'^csv_importer/', include('csv_importer.foo.urls')),
-
- # Uncomment the admin/doc line below to enable admin documentation:
- # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
-
- # Uncomment the next line to enable the admin:
- # url(r'^admin/', include(admin.site.urls)),
-)
Please sign in to comment.
Something went wrong with that request. Please try again.