lundi 27 avril 2015

ValidationError when running unittest

I am trying to start testing on a django app. The app is working fine but I want to set up testing before I do some refactoring. Now I just tried to do a simple dummy test:

import unittest

class TestBasic(unittest.TestCase):
    "Basic tests"

def test_basic(self):
    a = 1
    self.assertEqual(1, a)

def test_basic_2(self):
    a = 1
    assert a == 1

And I get this error that does not seem to have anything to do with the test itself:

Traceback (most recent call last):
  File "Y:\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
385, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\commands\test.py",
line 50, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 288,
 in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\commands\test.py",
line 71, in execute
    super(Command, self).execute(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 338,
 in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\test.py",
line 88, in handle
    failures = test_runner.run_tests(test_labels)
  File "C:\Python27\lib\site-packages\django\test\runner.py", line 147, in run_t
ests
    old_config = self.setup_databases()
  File "C:\Python27\lib\site-packages\django\test\runner.py", line 109, in setup
_databases
    return setup_databases(self.verbosity, self.interactive, **kwargs)
  File "C:\Python27\lib\site-packages\django\test\runner.py", line 299, in setup
_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File "C:\Python27\lib\site-packages\django\db\backends\creation.py", line 377,
 in create_test_db
    test_flush=True,
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line
115, in call_command
    return klass.execute(*args, **defaults)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 338,
 in execute
    output = self.handle(*args, **options)
  File "C:\Python27\lib\site-packages\django\core\management\commands\migrate.py
", line 161, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 68
, in migrate
    self.apply_migration(migration, fake=fake)
  File "C:\Python27\lib\site-packages\django\db\migrations\executor.py", line 10
2, in apply_migration
    migration.apply(project_state, schema_editor)
  File "C:\Python27\lib\site-packages\django\db\migrations\migration.py", line 1
08, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, ne
w_state)
  File "C:\Python27\lib\site-packages\django\db\migrations\operations\models.py"
, line 36, in database_forwards
    schema_editor.create_model(model)
  File "C:\Python27\lib\site-packages\django\db\backends\schema.py", line 212, i
n create_model
    definition, extra_params = self.column_sql(model, field)
  File "C:\Python27\lib\site-packages\django\db\backends\schema.py", line 124, i
n column_sql
    default_value = self.effective_default(field)
  File "C:\Python27\lib\site-packages\django\db\backends\schema.py", line 187, i
n effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line
 627, in get_db_prep_save
    prepared=False)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line
 1176, in get_db_prep_value
    value = self.get_prep_value(value)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line
 1171, in get_prep_value
    return self.to_python(value)
  File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line
 1141, in to_python
    params={'value': value},
django.core.exceptions.ValidationError: [u"'' value has an invalid date format.
It must be in YYYY-MM-DD format."]

Seems to be an error when creating the test database. How can this throw a validation error? How can I resolve this?

Aucun commentaire:

Enregistrer un commentaire