Re: [Arches] Unit tests in custom Arches app

2018-11-19 Thread Alexei Peters
Vincent,
I've never tried this before, but I'm sure you can get it to work with a
little fiddling.
The test module is completely separate from the pip installed arches code.
ROOT_DIR should point to your app root directory.
TEST_DIR should point to your test directory.
Hope that's helpful.
-Alexei

Director of Web Development - Farallon Geographics, Inc. - 971.227.3173


On Sat, Nov 17, 2018 at 7:16 AM Vincent Meijer 
wrote:

> I was wondering what the recommended method is for adding unit tests to my
> own Arches app.
>
> The unit test section in Arches core looks like an isolated python module
> and I can't seem to import e.g. the test_settings.py file from my own app.
> Also, when I try copying that settings file to my own app and then try to
> run my own unit tests with it (from manage.py in my own app), the process
> still looks for database init (sql) files in core Arches folders.
>
> And if I should copy/paste test_settings.py into my own app, what should I
> set settings like ROOT_DIR and TEST_ROOT to?
>
> My current settings:
> ROOT_DIR =
> os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe(
> ROOT_DIR = os.path.normpath(os.path.join(ROOT_DIR, '..' ,'..', 'arches',
> 'arches'))
> TEST_ROOT = os.path.normpath(os.path.join(ROOT_DIR, '..', 'tests'))
>
>
> But now I'm getting this stack:
> Destroying old test database for alias 'default'...
> Traceback (most recent call last):
>   File "manage.py", line 35, in 
> execute_from_command_line(sys.argv)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/__init__.py"
> , line 364, in execute_from_command_line
> utility.execute()
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/__init__.py"
> , line 356, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/commands/test.py"
> , line 29, in run_from_argv
> super(Command, self).run_from_argv(argv)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/base.py"
> , line 283, in run_from_argv
> self.execute(*args, **cmd_options)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/base.py"
> , line 330, in execute
> output = self.handle(*args, **options)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/commands/test.py"
> , line 62, in handle
> failures = test_runner.run_tests(test_labels)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/test/runner.py",
> line 601, in run_tests
> old_config = self.setup_databases()
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/test/runner.py",
> line 546, in setup_databases
> self.parallel, **kwargs
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/test/utils.py",
> line 187, in setup_databases
> serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE',
> True),
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/db/backends/base/creation.py"
> , line 69, in create_test_db
> run_syncdb=True,
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/__init__.py"
> , line 131, in call_command
> return command.execute(*args, **defaults)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/base.py"
> , line 330, in execute
> output = self.handle(*args, **options)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py"
> , line 204, in handle
> fake_initial=fake_initial,
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/db/migrations/executor.py"
> , line 115, in migrate
> state = self._migrate_all_forwards(state, plan, full_plan, fake=fake,
> fake_initial=fake_initial)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/db/migrations/executor.py"
> , line 145, in _migrate_all_forwards
> state = self.apply_migration(state, migration, fake=fake, fake_initial
> =fake_initial)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/db/migrations/executor.py"
> , line 244, in apply_migration
> state = migration.apply(state, schema_editor)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/db/migrations/migration.py"
> , line 129, in apply
> operation.database_forwards(self.app_label, schema_editor, old_state,
> project_state)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/db/migrations/operations/special.py"
> , line 193, in database_forwards
> self.code(from_state.apps, schema_editor)
>   File "/web_root/arches/arches/app/models/migrations/0001_initial.py",
> line 55, in make_permissions
> create_permissions(model_app, verbosity=0)
>   File
> "/web_root/ENV/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py"
> , line 63, in create_permissions
> 

[Arches] Unit tests in custom Arches app

2018-11-17 Thread Vincent Meijer
I was wondering what the recommended method is for adding unit tests to my 
own Arches app.

The unit test section in Arches core looks like an isolated python module 
and I can't seem to import e.g. the test_settings.py file from my own app.
Also, when I try copying that settings file to my own app and then try to 
run my own unit tests with it (from manage.py in my own app), the process 
still looks for database init (sql) files in core Arches folders.

And if I should copy/paste test_settings.py into my own app, what should I 
set settings like ROOT_DIR and TEST_ROOT to?

My current settings:
ROOT_DIR = 
os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe(
ROOT_DIR = os.path.normpath(os.path.join(ROOT_DIR, '..' ,'..', 'arches', 
'arches'))
TEST_ROOT = os.path.normpath(os.path.join(ROOT_DIR, '..', 'tests'))


But now I'm getting this stack:
Destroying old test database for alias 'default'...
Traceback (most recent call last):
  File "manage.py", line 35, in 
execute_from_command_line(sys.argv)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/__init__.py"
, line 364, in execute_from_command_line
utility.execute()
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/__init__.py"
, line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/commands/test.py"
, line 29, in run_from_argv
super(Command, self).run_from_argv(argv)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/base.py"
, line 283, in run_from_argv
self.execute(*args, **cmd_options)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/base.py"
, line 330, in execute
output = self.handle(*args, **options)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/commands/test.py"
, line 62, in handle
failures = test_runner.run_tests(test_labels)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/test/runner.py", 
line 601, in run_tests
old_config = self.setup_databases()
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/test/runner.py", 
line 546, in setup_databases
self.parallel, **kwargs
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/test/utils.py", 
line 187, in setup_databases
serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True
),
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/db/backends/base/creation.py"
, line 69, in create_test_db
run_syncdb=True,
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/__init__.py"
, line 131, in call_command
return command.execute(*args, **defaults)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/base.py"
, line 330, in execute
output = self.handle(*args, **options)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py"
, line 204, in handle
fake_initial=fake_initial,
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/db/migrations/executor.py"
, line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, 
fake_initial=fake_initial)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/db/migrations/executor.py"
, line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=
fake_initial)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/db/migrations/executor.py"
, line 244, in apply_migration
state = migration.apply(state, schema_editor)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/db/migrations/migration.py"
, line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, 
project_state)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/db/migrations/operations/special.py"
, line 193, in database_forwards
self.code(from_state.apps, schema_editor)
  File "/web_root/arches/arches/app/models/migrations/0001_initial.py", 
line 55, in make_permissions
create_permissions(model_app, verbosity=0)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/contrib/auth/management/__init__.py"
, line 63, in create_permissions
ctype = ContentType.objects.db_manager(using).get_for_model(klass)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/contrib/contenttypes/models.py"
, line 60, in get_for_model
model=opts.model_name,
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/db/models/manager.py"
, line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
  File 
"/web_root/ENV/local/lib/python2.7/site-packages/django/db/models/query.py", 
line 466, in get_or_create
return self._create_object_from_params(lookup, params)
  File