Browse Source

drop example model, add alembic tracimv1 history and use same database scheme as tracimv1

Guénaël Muller 7 years ago
parent
commit
f3b6140c78
27 changed files with 1073 additions and 106 deletions
  1. 74 0
      alembic.ini
  2. 1 0
      setup.py
  3. 78 0
      tracim/migration/env.py
  4. 22 0
      tracim/migration/script.py.mako
  5. 77 0
      tracim/migration/versions/15305f71bfda_fill_content_file_extension_column.py
  6. 26 0
      tracim/migration/versions/2b4043fa2502_remove_webdav_right_digest_response_.py
  7. 26 0
      tracim/migration/versions/2cd20ff3d23a_user_timezone.py
  8. 28 0
      tracim/migration/versions/43a323cc661_add_read_not_read_content_status.py
  9. 26 0
      tracim/migration/versions/534c4594ed29_add_calendar_enabled_column_to_workspace.py
  10. 31 0
      tracim/migration/versions/59fc98c3c965_delete_content_file_name_column.py
  11. 38 0
      tracim/migration/versions/69fb10c3d6f0_files_on_disk.py
  12. 99 0
      tracim/migration/versions/913efdf409e5_all_files_also_on_disk.py
  13. 26 0
      tracim/migration/versions/ad79f58ec2bf_tracim_v2.py
  14. 28 0
      tracim/migration/versions/b4b8d57b54e5_add_hash_column_for_digest_.py
  15. 22 0
      tracim/migration/versions/b73e57760b36_add_user_field_for_imported_profiles.py
  16. 28 0
      tracim/migration/versions/bdb195ed95bb_user_auth_token_columns.py
  17. 78 0
      tracim/migration/versions/c1cea4bbae16_file_extentions_value_for_pages_and_.py
  18. 187 0
      tracim/migration/versions/da12239d9da0_delete_content_view.py
  19. 33 0
      tracim/migration/versions/e31ddc009b37_add_content_file_extension_column.py
  20. 66 0
      tracim/migration/versions/f3852e1349c4_all_files_only_on_disk.py
  21. 0 1
      tracim/models/__init__.py
  22. 1 1
      tracim/models/meta.py
  23. 0 21
      tracim/models/mymodel.py
  24. 0 1
      tracim/routes.py
  25. 4 6
      tracim/scripts/initializedb.py
  26. 65 65
      tracim/tests/views/test_example.py
  27. 9 11
      tracim/views/default.py

+ 74 - 0
alembic.ini View File

@@ -0,0 +1,74 @@
1
+# A generic, single database configuration.
2
+
3
+[alembic]
4
+# path to migration scripts
5
+script_location = tracim/migration
6
+
7
+# template used to generate migration files
8
+# file_template = %%(rev)s_%%(slug)s
9
+
10
+# timezone to use when rendering the date
11
+# within the migration file as well as the filename.
12
+# string value is passed to dateutil.tz.gettz()
13
+# leave blank for localtime
14
+# timezone =
15
+
16
+# max length of characters to apply to the
17
+# "slug" field
18
+#truncate_slug_length = 40
19
+
20
+# set to 'true' to run the environment during
21
+# the 'revision' command, regardless of autogenerate
22
+# revision_environment = false
23
+
24
+# set to 'true' to allow .pyc and .pyo files without
25
+# a source .py file to be detected as revisions in the
26
+# versions/ directory
27
+# sourceless = false
28
+
29
+# version location specification; this defaults
30
+# to migrate/versions.  When using multiple version
31
+# directories, initial revisions must be specified with --version-path
32
+# version_locations = %(here)s/bar %(here)s/bat migrate/versions
33
+
34
+# the output encoding used when revision files
35
+# are written from script.py.mako
36
+# output_encoding = utf-8
37
+
38
+sqlalchemy.url = sqlite:///%(here)s/tracim.sqlite
39
+
40
+
41
+# Logging configuration
42
+[loggers]
43
+keys = root,sqlalchemy,alembic
44
+
45
+[handlers]
46
+keys = console
47
+
48
+[formatters]
49
+keys = generic
50
+
51
+[logger_root]
52
+level = WARN
53
+handlers = console
54
+qualname =
55
+
56
+[logger_sqlalchemy]
57
+level = WARN
58
+handlers =
59
+qualname = sqlalchemy.engine
60
+
61
+[logger_alembic]
62
+level = INFO
63
+handlers =
64
+qualname = alembic
65
+
66
+[handler_console]
67
+class = StreamHandler
68
+args = (sys.stderr,)
69
+level = NOTSET
70
+formatter = generic
71
+
72
+[formatter_generic]
73
+format = %(levelname)-5.5s [%(name)s] %(message)s
74
+datefmt = %H:%M:%S

+ 1 - 0
setup.py View File

@@ -21,6 +21,7 @@ requires = [
21 21
     'waitress',
22 22
     'filedepot',
23 23
     'babel',
24
+    'alembic',
24 25
 ]
25 26
 
26 27
 tests_require = [

+ 78 - 0
tracim/migration/env.py View File

@@ -0,0 +1,78 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+from __future__ import with_statement
4
+from alembic import context
5
+from sqlalchemy import engine_from_config, pool
6
+from tracim import models
7
+# from logging.config import fileConfig
8
+
9
+# this is the Alembic Config object, which provides
10
+# access to the values within the .ini file in use.
11
+config = context.config
12
+# Interpret the config file for Python logging.
13
+# This line sets up loggers basically.
14
+# fileConfig(config.config_file_name)
15
+
16
+# add your model's MetaData object here
17
+# for 'autogenerate' support
18
+# from myapp import mymodel
19
+# target_metadata = mymodel.Base.metadata
20
+
21
+target_metadata = models.meta.metadata
22
+
23
+# other values from the config, defined by the needs of env.py,
24
+# can be acquired:
25
+# my_important_option = config.get_main_option("my_important_option")
26
+# ... etc.
27
+
28
+
29
+def run_migrations_offline():
30
+    """Run migrations in 'offline' mode.
31
+
32
+    This configures the context with just a URL
33
+    and not an Engine, though an Engine is acceptable
34
+    here as well.  By skipping the Engine creation
35
+    we don't even need a DBAPI to be available.
36
+
37
+    Calls to context.execute() here emit the given string to the
38
+    script output.
39
+
40
+    """
41
+    url = config.get_main_option("sqlalchemy.url")
42
+    context.configure(url=url, version_table='migrate_version')
43
+
44
+    with context.begin_transaction():
45
+        context.run_migrations()
46
+
47
+
48
+def run_migrations_online():
49
+    """Run migrations in 'online' mode.
50
+
51
+    In this scenario we need to create an Engine
52
+    and associate a connection with the context.
53
+
54
+    """
55
+    engine = engine_from_config(
56
+                config.get_section(config.config_ini_section),
57
+                prefix='sqlalchemy.',
58
+                poolclass=pool.NullPool)
59
+
60
+    connection = engine.connect()
61
+    context.configure(
62
+                connection=connection,
63
+                target_metadata=target_metadata,
64
+                version_table='migrate_version'
65
+                )
66
+
67
+    try:
68
+        with context.begin_transaction():
69
+            context.run_migrations()
70
+    finally:
71
+        connection.close()
72
+        engine.dispose()
73
+
74
+
75
+if context.is_offline_mode():
76
+    run_migrations_offline()
77
+else:
78
+    run_migrations_online()

+ 22 - 0
tracim/migration/script.py.mako View File

@@ -0,0 +1,22 @@
1
+"""${message}
2
+
3
+Revision ID: ${up_revision}
4
+Revises: ${down_revision}
5
+Create Date: ${create_date}
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = ${repr(up_revision)}
11
+down_revision = ${repr(down_revision)}
12
+
13
+from alembic import op
14
+import sqlalchemy as sa
15
+${imports if imports else ""}
16
+
17
+def upgrade():
18
+    ${upgrades if upgrades else "pass"}
19
+
20
+
21
+def downgrade():
22
+    ${downgrades if downgrades else "pass"}

+ 77 - 0
tracim/migration/versions/15305f71bfda_fill_content_file_extension_column.py View File

@@ -0,0 +1,77 @@
1
+"""fill content file_extension column
2
+
3
+Revision ID: 15305f71bfda
4
+Revises: e31ddc009b37
5
+Create Date: 2016-11-25 10:50:01.874820
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+import os
11
+
12
+revision = '15305f71bfda'
13
+down_revision = 'e31ddc009b37'
14
+
15
+from alembic import op
16
+import sqlalchemy as sa
17
+
18
+
19
+content_revision_helper = sa.Table(
20
+    'content_revisions',
21
+    sa.MetaData(),
22
+    sa.Column('revision_id', sa.Integer, primary_key=True),
23
+    sa.Column('content_id', sa.ForeignKey(u'content.id'), nullable=False),
24
+    sa.Column('owner_id', sa.ForeignKey(u'users.user_id'), index=True),
25
+    sa.Column('label', sa.String(1024), nullable=False),
26
+    sa.Column('description', sa.Text, nullable=False),
27
+    sa.Column('file_name', sa.String(255), nullable=False),
28
+    sa.Column('file_extension', sa.String(255), nullable=False),
29
+    sa.Column('file_mimetype', sa.String(255), nullable=False),
30
+    sa.Column('file_content', sa.LargeBinary),
31
+    sa.Column('properties', sa.Text, nullable=False),
32
+    sa.Column('type', sa.String(32), nullable=False),
33
+    sa.Column('status', sa.String(32), nullable=False),
34
+    sa.Column('created', sa.DateTime, nullable=False),
35
+    sa.Column('updated', sa.DateTime, nullable=False),
36
+    sa.Column('is_deleted', sa.Boolean, nullable=False),
37
+    sa.Column('is_archived', sa.Boolean, nullable=False),
38
+    sa.Column('is_temporary', sa.Boolean, nullable=False),
39
+    sa.Column('revision_type', sa.String(32), nullable=False),
40
+    sa.Column('workspace_id', sa.ForeignKey(u'workspaces.workspace_id')),
41
+    sa.Column('parent_id', sa.ForeignKey(u'content.id'), index=True),
42
+)
43
+
44
+
45
+def upgrade():
46
+    connection = op.get_bind()
47
+
48
+    for content_revision in connection.execute(
49
+            content_revision_helper.select()
50
+    ):
51
+        # On work with FILE
52
+        if content_revision.type == 'file':
53
+            file_name, file_extension = \
54
+                os.path.splitext(content_revision.file_name)
55
+
56
+            # Don't touch label if already set
57
+            if content_revision.label:
58
+                new_label = content_revision.label
59
+            # Label will be file name without extension
60
+            else:
61
+                new_label = file_name
62
+
63
+            # Update record
64
+            connection.execute(
65
+                content_revision_helper.update()
66
+                .where(
67
+                    content_revision_helper.c.revision_id ==
68
+                    content_revision.revision_id
69
+                ).values(
70
+                    label=new_label,
71
+                    file_extension=file_extension,
72
+                )
73
+            )
74
+
75
+
76
+def downgrade():
77
+    pass

+ 26 - 0
tracim/migration/versions/2b4043fa2502_remove_webdav_right_digest_response_.py View File

@@ -0,0 +1,26 @@
1
+"""remove webdav_right_digest_response_hash from database
2
+
3
+Revision ID: 2b4043fa2502
4
+Revises: f3852e1349c4
5
+Create Date: 2018-03-13 14:41:38.590375
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = '2b4043fa2502'
11
+down_revision = 'f3852e1349c4'
12
+
13
+from alembic import op
14
+from sqlalchemy import Column, Unicode
15
+
16
+
17
+def upgrade():
18
+    with op.batch_alter_table('users') as batch_op:
19
+        batch_op.drop_column('webdav_left_digest_response_hash')
20
+
21
+
22
+def downgrade():
23
+    with op.batch_alter_table('users') as batch_op:
24
+        batch_op.add_column(
25
+            Column('webdav_left_digest_response_hash', Unicode(128))
26
+        )

+ 26 - 0
tracim/migration/versions/2cd20ff3d23a_user_timezone.py View File

@@ -0,0 +1,26 @@
1
+"""user_timezone
2
+
3
+Revision ID: 2cd20ff3d23a
4
+Revises: b4b8d57b54e5
5
+Create Date: 2016-11-08 11:32:00.903232
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = '2cd20ff3d23a'
11
+down_revision = 'b4b8d57b54e5'
12
+
13
+from alembic import op
14
+import sqlalchemy as sa
15
+
16
+
17
+def upgrade():
18
+    ### commands auto generated by Alembic - please adjust! ###
19
+    op.add_column('users', sa.Column('timezone', sa.Unicode(length=255), server_default='', nullable=False))
20
+    ### end Alembic commands ###
21
+
22
+
23
+def downgrade():
24
+    ### commands auto generated by Alembic - please adjust! ###
25
+    op.drop_column('users', 'timezone')
26
+    ### end Alembic commands ###

+ 28 - 0
tracim/migration/versions/43a323cc661_add_read_not_read_content_status.py View File

@@ -0,0 +1,28 @@
1
+"""add read/not read content status
2
+
3
+Revision ID: 43a323cc661
4
+Revises: None
5
+Create Date: 2015-08-26 11:23:03.466554
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = '43a323cc661'
11
+down_revision = None
12
+
13
+from alembic import op
14
+import sqlalchemy as sa
15
+
16
+
17
+def upgrade():
18
+    op.create_table(
19
+        'revision_read_status',
20
+        sa.Column('revision_id', sa.Integer, sa.ForeignKey('content_revisions.revision_id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True),
21
+        sa.Column('user_id', sa.Integer, sa.ForeignKey('users.user_id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True),
22
+        sa.Column('view_datetime', sa.DateTime, server_default=sa.func.now(), unique=False, nullable=False)
23
+    )
24
+
25
+
26
+def downgrade():
27
+    op.drop_table('revision_read_status')
28
+

+ 26 - 0
tracim/migration/versions/534c4594ed29_add_calendar_enabled_column_to_workspace.py View File

@@ -0,0 +1,26 @@
1
+"""Add calendar_enabled column to Workspace
2
+
3
+Revision ID: 534c4594ed29
4
+Revises: da12239d9da0
5
+Create Date: 2016-05-31 13:02:28.301984
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = '534c4594ed29'
11
+down_revision = 'da12239d9da0'
12
+
13
+from alembic import op
14
+import sqlalchemy as sa
15
+
16
+
17
+def upgrade():
18
+    ### commands auto generated by Alembic - please adjust! ###
19
+    op.add_column('workspaces', sa.Column('calendar_enabled', sa.Boolean(), nullable=False, server_default='0'))
20
+    ### end Alembic commands ###
21
+
22
+
23
+def downgrade():
24
+    ### commands auto generated by Alembic - please adjust! ###
25
+    op.drop_column('workspaces', 'calendar_enabled')
26
+    ### end Alembic commands ###

+ 31 - 0
tracim/migration/versions/59fc98c3c965_delete_content_file_name_column.py View File

@@ -0,0 +1,31 @@
1
+"""delete content file name column
2
+
3
+Revision ID: 59fc98c3c965
4
+Revises: 15305f71bfda
5
+Create Date: 2016-11-25 14:55:22.176175
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = '59fc98c3c965'
11
+down_revision = '15305f71bfda'
12
+
13
+from alembic import op
14
+import sqlalchemy as sa
15
+
16
+
17
+def upgrade():
18
+    op.drop_column('content_revisions', 'file_name')
19
+
20
+
21
+def downgrade():
22
+    op.add_column(
23
+        'content_revisions',
24
+        sa.Column(
25
+            'file_name',
26
+            sa.VARCHAR(length=255),
27
+            server_default=sa.text("''::character varying"),
28
+            autoincrement=False,
29
+            nullable=False
30
+        ),
31
+    )

+ 38 - 0
tracim/migration/versions/69fb10c3d6f0_files_on_disk.py View File

@@ -0,0 +1,38 @@
1
+"""files on disk.
2
+
3
+Revision ID: 69fb10c3d6f0
4
+Revises: c1cea4bbae16
5
+Create Date: 2017-06-07 17:25:47.306472
6
+
7
+"""
8
+
9
+from alembic import op
10
+from depot.fields.sqlalchemy import UploadedFileField
11
+import sqlalchemy as sa
12
+
13
+# revision identifiers, used by Alembic.
14
+revision = '69fb10c3d6f0'
15
+down_revision = 'c1cea4bbae16'
16
+
17
+
18
+# INFO - A.P - 2017-07-20 - alembic batch migrations
19
+# http://alembic.zzzcomputing.com/en/latest/batch.html
20
+# This migration uses alembic batch mode, a workaround allowing to enforce
21
+# ALTER statement with SQLite while maintaining the traditional behavior of
22
+# the commented lines on other RDBMS.
23
+
24
+
25
+def upgrade():
26
+    """Adds the depot file in revision."""
27
+    # op.add_column('content_revisions',
28
+    #               sa.Column('depot_file',
29
+    #                         UploadedFileField))
30
+    with op.batch_alter_table('content_revisions') as batch_op:
31
+        batch_op.add_column(sa.Column('depot_file', UploadedFileField))
32
+
33
+
34
+def downgrade():
35
+    """Drops the depot file in revision."""
36
+    # op.drop_column('content_revisions', 'depot_file')
37
+    with op.batch_alter_table('content_revisions') as batch_op:
38
+        batch_op.drop_column('depot_file')

+ 99 - 0
tracim/migration/versions/913efdf409e5_all_files_also_on_disk.py View File

@@ -0,0 +1,99 @@
1
+"""all files also on disk.
2
+
3
+Revision ID: 913efdf409e5
4
+Revises: 69fb10c3d6f0
5
+Create Date: 2017-07-12 15:44:20.568447
6
+
7
+"""
8
+
9
+import shutil
10
+
11
+from alembic import context
12
+from alembic import op
13
+from depot.fields.sqlalchemy import UploadedFileField
14
+from depot.fields.upload import UploadedFile
15
+from depot.io.utils import FileIntent
16
+from depot.manager import DepotManager
17
+import sqlalchemy as sa
18
+from sqlalchemy.sql.expression import func
19
+
20
+# revision identifiers, used by Alembic.
21
+revision = '913efdf409e5'
22
+down_revision = '69fb10c3d6f0'
23
+
24
+
25
+revision_helper = sa.Table(
26
+    'content_revisions',
27
+    sa.MetaData(),
28
+    sa.Column('revision_id', sa.Integer, primary_key=True),
29
+    sa.Column('label', sa.String(1024), nullable=False),
30
+    sa.Column('file_extension', sa.String(255), nullable=False),
31
+    sa.Column('file_mimetype', sa.String(255), nullable=False),
32
+    sa.Column('file_content', sa.LargeBinary),
33
+    sa.Column('depot_file', UploadedFileField, nullable=True),
34
+    sa.Column('type', sa.String(32), nullable=False),
35
+)
36
+
37
+
38
+def configure_depot():
39
+    """Configure Depot."""
40
+    depot_storage_name = context.config.get_main_option('depot_storage_name')
41
+    depot_storage_path = context.config.get_main_option('depot_storage_dir')
42
+    depot_storage_settings = {'depot.storage_path': depot_storage_path}
43
+    DepotManager.configure(
44
+        depot_storage_name,
45
+        depot_storage_settings,
46
+    )
47
+
48
+
49
+def delete_files_on_disk(connection: sa.engine.Connection):
50
+    """Deletes files from disk and their references in database."""
51
+    delete_query = revision_helper.update() \
52
+        .where(revision_helper.c.type == 'file') \
53
+        .where(revision_helper.c.depot_file.isnot(None)) \
54
+        .values(depot_file=None)
55
+    connection.execute(delete_query)
56
+    depot_storage_path = context.config.get_main_option('depot_storage_dir')
57
+    shutil.rmtree(depot_storage_path, ignore_errors=True)
58
+
59
+
60
+def upgrade():
61
+    """
62
+    Sets all depot files for file typed revisions.
63
+
64
+    Until now, files are both in database and, for the newly created
65
+    ones, on disk. In order to simplify the migration, this procedure
66
+    will:
67
+    - delete the few files on disk,
68
+    - create all files on disk from database.
69
+    """
70
+    # Creates files depot used in this migration
71
+    configure_depot()
72
+    connection = op.get_bind()
73
+    delete_files_on_disk(connection=connection)
74
+    select_query = revision_helper.select() \
75
+        .where(revision_helper.c.type == 'file') \
76
+        .where(revision_helper.c.depot_file.is_(None)) \
77
+        .where(func.length(revision_helper.c.file_content) > 0)
78
+    files = connection.execute(select_query).fetchall()
79
+    for file in files:
80
+        file_filename = '{0}{1}'.format(
81
+            file.label,
82
+            file.file_extension,
83
+        )
84
+        depot_file_intent = FileIntent(
85
+            file.file_content,
86
+            file_filename,
87
+            file.file_mimetype,
88
+        )
89
+        depot_file_field = UploadedFile(depot_file_intent, 'tracim')
90
+        update_query = revision_helper.update() \
91
+            .where(revision_helper.c.revision_id == file.revision_id) \
92
+            .values(depot_file=depot_file_field)
93
+        connection.execute(update_query)
94
+
95
+
96
+def downgrade():
97
+    """Resets depot file for file typed revisions."""
98
+    connection = op.get_bind()
99
+    delete_files_on_disk(connection=connection)

+ 26 - 0
tracim/migration/versions/ad79f58ec2bf_tracim_v2.py View File

@@ -0,0 +1,26 @@
1
+"""Tracim V2
2
+
3
+Revision ID: ad79f58ec2bf
4
+Revises: 2b4043fa2502
5
+Create Date: 2018-03-29 17:05:41.735260
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = 'ad79f58ec2bf'
11
+down_revision = '2b4043fa2502'
12
+
13
+from alembic import op
14
+import sqlalchemy as sa
15
+
16
+
17
+def upgrade():
18
+    # ### commands auto generated by Alembic - please adjust! ###
19
+    pass
20
+    # ### end Alembic commands ###
21
+
22
+
23
+def downgrade():
24
+    # ### commands auto generated by Alembic - please adjust! ###
25
+    pass
26
+    # ### end Alembic commands ###

+ 28 - 0
tracim/migration/versions/b4b8d57b54e5_add_hash_column_for_digest_.py View File

@@ -0,0 +1,28 @@
1
+"""add hash column for digest authentication
2
+
3
+Revision ID: b4b8d57b54e5
4
+Revises: 534c4594ed29
5
+Create Date: 2016-08-11 10:27:28.951506
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = 'b4b8d57b54e5'
11
+down_revision = 'bdb195ed95bb'
12
+
13
+from alembic import op
14
+from sqlalchemy import Column, Unicode, Boolean
15
+
16
+
17
+def upgrade():
18
+    op.add_column('users', Column('webdav_left_digest_response_hash', Unicode(128)))
19
+    op.add_column('content_revisions', Column('is_temporary', Boolean(), unique=False, nullable=True))
20
+    op.execute('''
21
+        UPDATE content_revisions
22
+        SET is_temporary = FALSE
23
+        ''')
24
+    op.alter_column('content_revisions', 'is_temporary', nullable=False)
25
+
26
+def downgrade():
27
+    op.drop_column('users', 'webdav_left_digest_response_hash')
28
+    op.drop_column('content_revisions', 'is_temporary')

+ 22 - 0
tracim/migration/versions/b73e57760b36_add_user_field_for_imported_profiles.py View File

@@ -0,0 +1,22 @@
1
+"""Add User field for imported profiles
2
+
3
+Revision ID: b73e57760b36
4
+Revises: 43a323cc661
5
+Create Date: 2016-02-09 11:00:22.694054
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = 'b73e57760b36'
11
+down_revision = '43a323cc661'
12
+
13
+import sqlalchemy as sa
14
+from alembic import op
15
+
16
+
17
+def upgrade():
18
+    op.add_column('users', sa.Column('imported_from', sa.Unicode(length=32), nullable=True))
19
+
20
+
21
+def downgrade():
22
+    op.drop_column('users', 'imported_from')

+ 28 - 0
tracim/migration/versions/bdb195ed95bb_user_auth_token_columns.py View File

@@ -0,0 +1,28 @@
1
+"""User auth token columns
2
+
3
+Revision ID: bdb195ed95bb
4
+Revises: 534c4594ed29
5
+Create Date: 2016-07-28 15:38:18.889151
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = 'bdb195ed95bb'
11
+down_revision = '534c4594ed29'
12
+
13
+from alembic import op
14
+import sqlalchemy as sa
15
+
16
+
17
+def upgrade():
18
+    ### commands auto generated by Alembic - please adjust! ###
19
+    op.add_column('users', sa.Column('auth_token', sa.Unicode(length=255), nullable=True))
20
+    op.add_column('users', sa.Column('auth_token_created', sa.DateTime(), nullable=True))
21
+    ### end Alembic commands ###
22
+
23
+
24
+def downgrade():
25
+    ### commands auto generated by Alembic - please adjust! ###
26
+    op.drop_column('users', 'auth_token_created')
27
+    op.drop_column('users', 'auth_token')
28
+    ### end Alembic commands ###

+ 78 - 0
tracim/migration/versions/c1cea4bbae16_file_extentions_value_for_pages_and_.py View File

@@ -0,0 +1,78 @@
1
+"""file_extentions value for Pages and Threads
2
+
3
+Revision ID: c1cea4bbae16
4
+Revises: 59fc98c3c965
5
+Create Date: 2016-11-30 10:41:51.893531
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+
11
+revision = 'c1cea4bbae16'
12
+down_revision = '59fc98c3c965'
13
+
14
+from alembic import op
15
+import sqlalchemy as sa
16
+
17
+content_revision_helper = sa.Table(
18
+    'content_revisions',
19
+    sa.MetaData(),
20
+    sa.Column('revision_id', sa.Integer, primary_key=True),
21
+    sa.Column('content_id', sa.ForeignKey(u'content.id'), nullable=False),
22
+    sa.Column('owner_id', sa.ForeignKey(u'users.user_id'), index=True),
23
+    sa.Column('label', sa.String(1024), nullable=False),
24
+    sa.Column('description', sa.Text, nullable=False),
25
+    sa.Column('file_extension', sa.String(255), nullable=False),
26
+    sa.Column('file_mimetype', sa.String(255), nullable=False),
27
+    sa.Column('file_content', sa.LargeBinary),
28
+    sa.Column('properties', sa.Text, nullable=False),
29
+    sa.Column('type', sa.String(32), nullable=False),
30
+    sa.Column('status', sa.String(32), nullable=False),
31
+    sa.Column('created', sa.DateTime, nullable=False),
32
+    sa.Column('updated', sa.DateTime, nullable=False),
33
+    sa.Column('is_deleted', sa.Boolean, nullable=False),
34
+    sa.Column('is_archived', sa.Boolean, nullable=False),
35
+    sa.Column('is_temporary', sa.Boolean, nullable=False),
36
+    sa.Column('revision_type', sa.String(32), nullable=False),
37
+    sa.Column('workspace_id', sa.ForeignKey(u'workspaces.workspace_id')),
38
+    sa.Column('parent_id', sa.ForeignKey(u'content.id'), index=True),
39
+)
40
+
41
+
42
+def upgrade():
43
+    connection = op.get_bind()
44
+
45
+    for content_revision in connection.execute(
46
+            content_revision_helper.select()
47
+    ):
48
+        if content_revision.type in ('page', 'thread'):
49
+            # Update record
50
+            connection.execute(
51
+                content_revision_helper.update()
52
+                    .where(
53
+                        content_revision_helper.c.revision_id ==
54
+                        content_revision.revision_id
55
+                    ).values(
56
+                        file_extension='.html',
57
+                    )
58
+                )
59
+
60
+
61
+def downgrade():
62
+    connection = op.get_bind()
63
+
64
+    for content_revision in connection.execute(
65
+            content_revision_helper.select()
66
+    ):
67
+        # On work with FILE
68
+        if content_revision.type in ('page', 'thread'):
69
+            # Update record
70
+            connection.execute(
71
+                content_revision_helper.update()
72
+                    .where(
73
+                        content_revision_helper.c.revision_id ==
74
+                        content_revision.revision_id
75
+                    ).values(
76
+                        file_extension='',
77
+                    )
78
+                )

+ 187 - 0
tracim/migration/versions/da12239d9da0_delete_content_view.py View File

@@ -0,0 +1,187 @@
1
+"""delete_content_view
2
+
3
+Revision ID: da12239d9da0
4
+Revises: b73e57760b36
5
+Create Date: 2016-03-04 15:59:05.828757
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = 'da12239d9da0'
11
+down_revision = 'b73e57760b36'
12
+
13
+import sqlalchemy as sa
14
+from alembic import op
15
+from sqlalchemy.dialects import postgresql
16
+
17
+
18
+def set_field_where_null(field_name, value="''"):
19
+    op.execute("UPDATE content_revisions SET %s = %s WHERE %s IS NULL" % (field_name, value, field_name))
20
+
21
+
22
+def set_field_to_null_where_empty_string(field_name):
23
+    op.execute("UPDATE content_revisions SET %s = NULL WHERE %s = ''" % (field_name, field_name))
24
+
25
+fields_names_to_empty_string = ('file_mimetype', 'file_name', 'label', 'properties',
26
+                                'revision_type', 'status', 'description', 'label')
27
+
28
+
29
+def upgrade():
30
+    ### commands auto generated by Alembic - please adjust! ###
31
+
32
+    # Drop triggers
33
+    op.execute("DROP TRIGGER trg__contents__on_insert__set_created ON content_revisions")
34
+    op.execute("DROP TRIGGER trg__contents__on_update__set_updated ON content_revisions")
35
+    op.execute("DROP TRIGGER trg__contents__on_update On contents")
36
+    op.execute("DROP TRIGGER trg__workspaces__on_insert__set_created ON workspaces")
37
+    op.execute("DROP TRIGGER trg__workspaces__on_update__set_updated ON workspaces")
38
+    op.execute("DROP VIEW contents")
39
+
40
+    # Set empty string on future non null fields
41
+    for field_name in fields_names_to_empty_string:
42
+        set_field_where_null(field_name)
43
+
44
+    op.create_table('content',
45
+                    sa.Column('id', sa.Integer(), nullable=False),
46
+                    sa.PrimaryKeyConstraint('id', name=op.f('pk__content'))
47
+                    )
48
+
49
+    # Create contents and reinit auto increment
50
+    op.execute("INSERT INTO content (id) SELECT DISTINCT(content_id) FROM content_revisions;")
51
+    op.execute("select setval('content_id_seq', (select max(id)+1 from content), false)")
52
+
53
+    op.alter_column('content_revisions', 'created',
54
+                    existing_type=postgresql.TIMESTAMP(),
55
+                    nullable=False,
56
+                    server_default=sa.func.now())
57
+    op.alter_column('content_revisions', 'file_mimetype',
58
+                    existing_type=sa.VARCHAR(length=255),
59
+                    nullable=False,
60
+                    server_default='')
61
+    op.alter_column('content_revisions', 'file_name',
62
+                    existing_type=sa.VARCHAR(length=255),
63
+                    nullable=False,
64
+                    server_default='')
65
+    op.alter_column('content_revisions', 'label',
66
+                    existing_type=sa.VARCHAR(length=1024),
67
+                    nullable=False,
68
+                    server_default='')
69
+    op.alter_column('content_revisions', 'properties',
70
+                    existing_type=sa.TEXT(),
71
+                    nullable=False,
72
+                    server_default='')
73
+    op.alter_column('content_revisions', 'revision_type',
74
+                    existing_type=sa.VARCHAR(length=32),
75
+                    nullable=False,
76
+                    server_default='')
77
+    op.alter_column('content_revisions', 'status',
78
+                    existing_type=sa.VARCHAR(length=32),
79
+                    nullable=False,
80
+                    existing_server_default=sa.text("'new'::character varying"),
81
+                    server_default='')
82
+    op.alter_column('content_revisions', 'updated',
83
+                    existing_type=postgresql.TIMESTAMP(),
84
+                    nullable=False,
85
+                    server_default=sa.func.now())
86
+    op.create_foreign_key(op.f('fk__content_revisions__content_id__content'), 'content_revisions', 'content',
87
+                          ['content_id'], ['id'])
88
+    op.create_foreign_key(op.f('fk__content_revisions__workspace_id__workspaces'), 'content_revisions', 'workspaces',
89
+                          ['workspace_id'], ['workspace_id'])
90
+    op.create_foreign_key(op.f('fk__content_revisions__parent_id__content'), 'content_revisions', 'content',
91
+                          ['parent_id'], ['id'])
92
+    op.alter_column('user_workspace', 'role',
93
+                    existing_type=sa.INTEGER(),
94
+                    nullable=False)
95
+    op.drop_constraint('fk__user_workspace__user_id', 'user_workspace', type_='foreignkey')
96
+    op.drop_constraint('fk__user_workspace__workspace_id', 'user_workspace', type_='foreignkey')
97
+    op.create_foreign_key(op.f('fk__user_workspace__user_id__users'), 'user_workspace', 'users', ['user_id'],
98
+                          ['user_id'])
99
+    op.create_foreign_key(op.f('fk__user_workspace__workspace_id__workspaces'), 'user_workspace', 'workspaces',
100
+                          ['workspace_id'], ['workspace_id'])
101
+    op.alter_column('workspaces', 'created',
102
+                    existing_type=postgresql.TIMESTAMP(),
103
+                    nullable=False,
104
+                    server_default=sa.func.now())
105
+    op.alter_column('workspaces', 'description',
106
+                    existing_type=sa.TEXT(),
107
+                    nullable=False,
108
+                    server_default='')
109
+    op.alter_column('workspaces', 'label',
110
+                    existing_type=sa.VARCHAR(length=1024),
111
+                    nullable=False,
112
+                    server_default='')
113
+    op.alter_column('workspaces', 'updated',
114
+                    existing_type=postgresql.TIMESTAMP(),
115
+                    nullable=False,
116
+                    server_default=sa.func.now())
117
+    ### end Alembic commands ###
118
+
119
+
120
+def downgrade():
121
+    ### commands auto generated by Alembic - please adjust! ###
122
+    op.alter_column('workspaces', 'updated',
123
+                    existing_type=postgresql.TIMESTAMP(),
124
+                    nullable=True)
125
+    op.alter_column('workspaces', 'label',
126
+                    existing_type=sa.VARCHAR(length=1024),
127
+                    nullable=True)
128
+    op.alter_column('workspaces', 'description',
129
+                    existing_type=sa.TEXT(),
130
+                    nullable=True)
131
+    op.alter_column('workspaces', 'created',
132
+                    existing_type=postgresql.TIMESTAMP(),
133
+                    nullable=True)
134
+    op.drop_constraint(op.f('fk__user_workspace__workspace_id__workspaces'), 'user_workspace', type_='foreignkey')
135
+    op.drop_constraint(op.f('fk__user_workspace__user_id__users'), 'user_workspace', type_='foreignkey')
136
+    op.create_foreign_key('fk__user_workspace__workspace_id', 'user_workspace', 'workspaces', ['workspace_id'],
137
+                          ['workspace_id'], onupdate='CASCADE', ondelete='CASCADE')
138
+    op.create_foreign_key('fk__user_workspace__user_id', 'user_workspace', 'users', ['user_id'], ['user_id'],
139
+                          onupdate='CASCADE', ondelete='CASCADE')
140
+    op.alter_column('user_workspace', 'role',
141
+                    existing_type=sa.INTEGER(),
142
+                    nullable=True)
143
+    op.drop_constraint(op.f('fk__content_revisions__parent_id__content'), 'content_revisions', type_='foreignkey')
144
+    op.drop_constraint(op.f('fk__content_revisions__workspace_id__workspaces'), 'content_revisions', type_='foreignkey')
145
+    op.drop_constraint(op.f('fk__content_revisions__content_id__content'), 'content_revisions', type_='foreignkey')
146
+    op.alter_column('content_revisions', 'updated',
147
+                    existing_type=postgresql.TIMESTAMP(),
148
+                    nullable=True)
149
+    op.alter_column('content_revisions', 'status',
150
+                    existing_type=sa.VARCHAR(length=32),
151
+                    nullable=True,
152
+                    existing_server_default=sa.text("'new'::character varying"))
153
+    op.alter_column('content_revisions', 'revision_type',
154
+                    existing_type=sa.VARCHAR(length=32),
155
+                    nullable=True)
156
+    op.alter_column('content_revisions', 'properties',
157
+                    existing_type=sa.TEXT(),
158
+                    nullable=True)
159
+    op.alter_column('content_revisions', 'label',
160
+                    existing_type=sa.VARCHAR(length=1024),
161
+                    nullable=True)
162
+    op.alter_column('content_revisions', 'file_name',
163
+                    existing_type=sa.VARCHAR(length=255),
164
+                    nullable=True)
165
+    op.alter_column('content_revisions', 'file_mimetype',
166
+                    existing_type=sa.VARCHAR(length=255),
167
+                    nullable=True)
168
+    op.alter_column('content_revisions', 'created',
169
+                    existing_type=postgresql.TIMESTAMP(),
170
+                    nullable=True)
171
+    op.drop_table('content')
172
+
173
+    for field_name in fields_names_to_empty_string:
174
+        set_field_to_null_where_empty_string(field_name)
175
+
176
+    op.execute("""
177
+CREATE VIEW contents AS
178
+    SELECT DISTINCT ON (content_revisions.content_id) content_revisions.content_id, content_revisions.parent_id, content_revisions.type, content_revisions.created, content_revisions.updated, content_revisions.label, content_revisions.description, content_revisions.status, content_revisions.file_name, content_revisions.file_content, content_revisions.file_mimetype, content_revisions.owner_id, content_revisions.workspace_id, content_revisions.is_deleted, content_revisions.is_archived, content_revisions.properties, content_revisions.revision_type FROM content_revisions ORDER BY content_revisions.content_id, content_revisions.updated DESC, content_revisions.created DESC;
179
+
180
+
181
+CREATE TRIGGER trg__contents__on_insert__set_created BEFORE INSERT ON content_revisions FOR EACH ROW EXECUTE PROCEDURE set_created();
182
+CREATE TRIGGER trg__contents__on_update__set_updated BEFORE UPDATE ON content_revisions FOR EACH ROW EXECUTE PROCEDURE set_updated();
183
+CREATE TRIGGER trg__contents__on_update INSTEAD OF UPDATE ON contents FOR EACH ROW EXECUTE PROCEDURE update_node();
184
+CREATE TRIGGER trg__workspaces__on_insert__set_created BEFORE INSERT ON workspaces FOR EACH ROW EXECUTE PROCEDURE set_created();
185
+CREATE TRIGGER trg__workspaces__on_update__set_updated BEFORE UPDATE ON workspaces FOR EACH ROW EXECUTE PROCEDURE set_updated();
186
+""")
187
+    ### end Alembic commands ###

+ 33 - 0
tracim/migration/versions/e31ddc009b37_add_content_file_extension_column.py View File

@@ -0,0 +1,33 @@
1
+"""add_content_file_extension_column
2
+
3
+Revision ID: e31ddc009b37
4
+Revises: 2cd20ff3d23a
5
+Create Date: 2016-11-25 10:43:23.700867
6
+
7
+"""
8
+
9
+# revision identifiers, used by Alembic.
10
+revision = 'e31ddc009b37'
11
+down_revision = '2cd20ff3d23a'
12
+
13
+from alembic import op
14
+import sqlalchemy as sa
15
+
16
+
17
+def upgrade():
18
+    op.add_column(
19
+        'content_revisions',
20
+        sa.Column(
21
+            'file_extension',
22
+            sa.Unicode(length=255),
23
+            server_default='',
24
+            nullable=False,
25
+        )
26
+    )
27
+
28
+
29
+def downgrade():
30
+    op.drop_column(
31
+        'content_revisions',
32
+        'file_extension',
33
+    )

+ 66 - 0
tracim/migration/versions/f3852e1349c4_all_files_only_on_disk.py View File

@@ -0,0 +1,66 @@
1
+"""all files only on disk.
2
+
3
+Revision ID: f3852e1349c4
4
+Revises: 913efdf409e5
5
+Create Date: 2017-07-24 17:15:54.278141
6
+
7
+"""
8
+
9
+from alembic import context
10
+from alembic import op
11
+
12
+from depot.fields.sqlalchemy import UploadedFileField
13
+from depot.manager import DepotManager
14
+
15
+import sqlalchemy as sa
16
+
17
+# revision identifiers, used by Alembic.
18
+revision = 'f3852e1349c4'
19
+down_revision = '913efdf409e5'
20
+
21
+
22
+def configure_depot():
23
+    """Configure Depot."""
24
+    depot_storage_name = context.config.get_main_option('depot_storage_name')
25
+    depot_storage_path = context.config.get_main_option('depot_storage_dir')
26
+    depot_storage_settings = {'depot.storage_path': depot_storage_path}
27
+    DepotManager.configure(
28
+        depot_storage_name,
29
+        depot_storage_settings,
30
+    )
31
+
32
+
33
+revision_helper = sa.Table(
34
+    'content_revisions',
35
+    sa.MetaData(),
36
+    sa.Column('revision_id', sa.Integer, primary_key=True),
37
+    sa.Column('file_content', sa.LargeBinary),
38
+    sa.Column('depot_file', UploadedFileField, nullable=True),
39
+    sa.Column('type', sa.String(32), nullable=False),
40
+)
41
+
42
+
43
+def upgrade():
44
+    """Drop the file content from revision."""
45
+    with op.batch_alter_table('content_revisions') as batch_op:
46
+        batch_op.drop_column('file_content')
47
+
48
+
49
+def downgrade():
50
+    """Add the file content in revision."""
51
+    with op.batch_alter_table('content_revisions') as batch_op:
52
+        batch_op.add_column(sa.Column('file_content', sa.LargeBinary))
53
+
54
+    configure_depot()
55
+    depot = DepotManager.get()
56
+    connection = op.get_bind()
57
+    select_query = revision_helper.select() \
58
+        .where(revision_helper.c.type == 'file') \
59
+        .where(revision_helper.c.depot_file.isnot(None))
60
+    files = connection.execute(select_query).fetchall()
61
+    for file in files:
62
+        depot_file_content = depot.get(file.depot_file).read()
63
+        update_query = revision_helper.update() \
64
+            .where(revision_helper.c.revision_id == file.revision_id) \
65
+            .values(file_content=depot_file_content)
66
+        connection.execute(update_query)

+ 0 - 1
tracim/models/__init__.py View File

@@ -8,7 +8,6 @@ from .meta import DeclarativeBase
8 8
 from .revision_protection import prevent_content_revision_delete
9 9
 # import or define all models here to ensure they are attached to the
10 10
 # Base.metadata prior to any initialization routines
11
-from tracim.models.mymodel import MyModel  # flake8: noqa
12 11
 from tracim.models.auth import User, Group, Permission
13 12
 from tracim.models.data import Content, ContentRevisionRO
14 13
 

+ 1 - 1
tracim/models/meta.py View File

@@ -7,7 +7,7 @@ from sqlalchemy.schema import MetaData
7 7
 # difficult. See: http://alembic.zzzcomputing.com/en/latest/naming.html
8 8
 NAMING_CONVENTION = {
9 9
     "ix": "ix_%(column_0_label)s",
10
-    "uq": "uq_%(table_name)s_%(column_0_name)s",
10
+    "uq": "uq__%(table_name)s__%(column_0_name)s",  # Unique constrains
11 11
     # TODO - G.M - 28-03-2018 - [Database] Convert database to allow naming convention
12 12
     # for ck contraint.
13 13
     # "ck": "ck_%(table_name)s_%(constraint_name)s",

+ 0 - 21
tracim/models/mymodel.py View File

@@ -1,21 +0,0 @@
1
-# -*- coding: utf-8 -*-
2
-from sqlalchemy import (
3
-    Column,
4
-    Index,
5
-    Integer,
6
-    Text,
7
-)
8
-
9
-from .meta import DeclarativeBase
10
-
11
-# TODO - G.M - 28-03-2018 - [Cleanup] Remove this example Model
12
-
13
-
14
-class MyModel(DeclarativeBase):
15
-    __tablename__ = 'models'
16
-    id = Column(Integer, primary_key=True)
17
-    name = Column(Text)
18
-    value = Column(Integer)
19
-
20
-
21
-Index('my_index', MyModel.name, unique=True, mysql_length=255)

+ 0 - 1
tracim/routes.py View File

@@ -2,4 +2,3 @@
2 2
 def includeme(config):
3 3
     config.add_static_view('static', 'static', cache_max_age=3600)
4 4
     config.add_route('home', '/')
5
-    config.add_route('test_config', '/test_config')

+ 4 - 6
tracim/scripts/initializedb.py View File

@@ -16,7 +16,6 @@ from ..models import (
16 16
     get_session_factory,
17 17
     get_tm_session,
18 18
     )
19
-from ..models import MyModel
20 19
 
21 20
 
22 21
 def usage(argv):
@@ -40,9 +39,8 @@ def main(argv=sys.argv):
40 39
     session_factory = get_session_factory(engine)
41 40
     # TODO - G.M - 28-03-2018 - [Cleanup] Remove code related to example
42 41
     with transaction.manager:
43
-        dbsession = get_tm_session(session_factory, transaction.manager)
44
-
45
-        model = MyModel(name='one', value=1)
46
-        dbsession.add(model)
47
-
42
+        pass
43
+        # dbsession = get_tm_session(session_factory, transaction.manager)
44
+        # model = MyModel(name='one', value=1)
45
+        # dbsession.add(model)
48 46
         # Add global manager data, just for test

+ 65 - 65
tracim/tests/views/test_example.py View File

@@ -1,67 +1,67 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 # TODO - G.M - [Cleanup] Drop this file
3
-import unittest
4
-import transaction
5
-
6
-from pyramid import testing
7
-
8
-
9
-def dummy_request(dbsession):
10
-    return testing.DummyRequest(dbsession=dbsession)
11
-
12
-
13
-class BaseTest(unittest.TestCase):
14
-    def setUp(self):
15
-        self.config = testing.setUp(settings={
16
-            'sqlalchemy.url': 'sqlite:///:memory:'
17
-        })
18
-        self.config.include('tracim.models')
19
-        settings = self.config.get_settings()
20
-
21
-        from tracim.models import (
22
-            get_engine,
23
-            get_session_factory,
24
-            get_tm_session,
25
-            )
26
-
27
-        self.engine = get_engine(settings)
28
-        session_factory = get_session_factory(self.engine)
29
-
30
-        self.session = get_tm_session(session_factory, transaction.manager)
31
-
32
-    def init_database(self):
33
-        from tracim.models.meta import DeclarativeBase
34
-        DeclarativeBase.metadata.create_all(self.engine)
35
-
36
-    def tearDown(self):
37
-        from tracim.models.meta import DeclarativeBase
38
-
39
-        testing.tearDown()
40
-        transaction.abort()
41
-        DeclarativeBase.metadata.drop_all(self.engine)
42
-
43
-
44
-class TestMyViewSuccessCondition(BaseTest):
45
-
46
-    def setUp(self):
47
-        super(TestMyViewSuccessCondition, self).setUp()
48
-        self.init_database()
49
-
50
-        from tracim.models import MyModel
51
-
52
-        model = MyModel(name='one', value=55)
53
-        self.session.add(model)
54
-
55
-    def test_passing_view(self):
56
-        from tracim.views.default import my_view
57
-        info = my_view(dummy_request(self.session))
58
-        self.assertEqual(info['one'].name, 'one')
59
-        self.assertEqual(info['project'], 'tracim')
60
-
61
-
62
-class TestMyViewFailureCondition(BaseTest):
63
-
64
-    def test_failing_view(self):
65
-        from tracim.views.default import my_view
66
-        info = my_view(dummy_request(self.session))
67
-        self.assertEqual(info.status_int, 500)
3
+# import unittest
4
+# import transaction
5
+#
6
+# from pyramid import testing
7
+#
8
+#
9
+# def dummy_request(dbsession):
10
+#     return testing.DummyRequest(dbsession=dbsession)
11
+#
12
+#
13
+# class BaseTest(unittest.TestCase):
14
+#     def setUp(self):
15
+#         self.config = testing.setUp(settings={
16
+#             'sqlalchemy.url': 'sqlite:///:memory:'
17
+#         })
18
+#         self.config.include('tracim.models')
19
+#         settings = self.config.get_settings()
20
+#
21
+#         from tracim.models import (
22
+#             get_engine,
23
+#             get_session_factory,
24
+#             get_tm_session,
25
+#             )
26
+#
27
+#         self.engine = get_engine(settings)
28
+#         session_factory = get_session_factory(self.engine)
29
+#
30
+#         self.session = get_tm_session(session_factory, transaction.manager)
31
+#
32
+#     def init_database(self):
33
+#         from tracim.models.meta import DeclarativeBase
34
+#         DeclarativeBase.metadata.create_all(self.engine)
35
+#
36
+#     def tearDown(self):
37
+#         from tracim.models.meta import DeclarativeBase
38
+#
39
+#         testing.tearDown()
40
+#         transaction.abort()
41
+#         DeclarativeBase.metadata.drop_all(self.engine)
42
+#
43
+#
44
+# class TestMyViewSuccessCondition(BaseTest):
45
+#
46
+#     def setUp(self):
47
+#         super(TestMyViewSuccessCondition, self).setUp()
48
+#         self.init_database()
49
+#
50
+#         from tracim.models import MyModel
51
+#
52
+#         model = MyModel(name='one', value=55)
53
+#         self.session.add(model)
54
+#
55
+#     def test_passing_view(self):
56
+#         from tracim.views.default import my_view
57
+#         info = my_view(dummy_request(self.session))
58
+#         self.assertEqual(info['one'].name, 'one')
59
+#         self.assertEqual(info['project'], 'tracim')
60
+#
61
+#
62
+# class TestMyViewFailureCondition(BaseTest):
63
+#
64
+#     def test_failing_view(self):
65
+#         from tracim.views.default import my_view
66
+#         info = my_view(dummy_request(self.session))
67
+#         self.assertEqual(info.status_int, 500)

+ 9 - 11
tracim/views/default.py View File

@@ -4,12 +4,10 @@ from pyramid.response import Response
4 4
 from pyramid.view import view_config
5 5
 
6 6
 from sqlalchemy.exc import DBAPIError
7
-
8
-from ..models import MyModel
9 7
 from ..models import Content
10 8
 
11 9
 
12
-@view_config(route_name='test_config', renderer='../templates/mytemplate.jinja2')
10
+@view_config(route_name='home', renderer='../templates/mytemplate.jinja2')
13 11
 def test_config(request):
14 12
     try:
15 13
         project = request.config().WEBSITE_TITLE
@@ -17,14 +15,14 @@ def test_config(request):
17 15
         return Response(e, content_type='text/plain', status=500)
18 16
     return {'project': project}
19 17
 
20
-@view_config(route_name='home', renderer='../templates/mytemplate.jinja2')
21
-def my_view(request):
22
-    try:
23
-        query = request.dbsession.query(MyModel)
24
-        one = query.filter(MyModel.name == 'one').first()
25
-    except DBAPIError:
26
-        return Response(db_err_msg, content_type='text/plain', status=500)
27
-    return {'one': one, 'project': 'tracim'}
18
+# @view_config(route_name='home', renderer='../templates/mytemplate.jinja2')
19
+# def my_view(request):
20
+#     try:
21
+#         query = request.dbsession.query(MyModel)
22
+#         one = query.filter(MyModel.name == 'one').first()
23
+#     except DBAPIError:
24
+#         return Response(db_err_msg, content_type='text/plain', status=500)
25
+#    return {'one': one, 'project': 'tracim'}
28 26
 
29 27
 
30 28
 db_err_msg = """\