0001-formdef-don-t-try-preserving-intenral_identifier-in-.patch
tests/test_formdef.py | ||
---|---|---|
126 | 126 |
assert FormDef.get(formdef.id).url_name == 'foo' |
127 | 127 |
assert FormDef.get(formdef.id).internal_identifier == 'bar' |
128 | 128 | |
129 |
# makes sure the internal_name doesn't change if there are submitted forms |
|
130 |
formdef.data_class()().store() |
|
131 |
formdef.name = 'baz' |
|
132 |
formdef.store() |
|
133 |
assert FormDef.get(formdef.id).name == 'baz' |
|
134 |
assert FormDef.get(formdef.id).internal_identifier == 'bar' # didn't change |
|
129 |
if not pub.is_using_postgresql(): |
|
130 |
# makes sure the internal_name doesn't change if there are submitted forms |
|
131 |
formdef.data_class()().store() |
|
132 |
formdef.name = 'baz' |
|
133 |
formdef.store() |
|
134 |
assert FormDef.get(formdef.id).name == 'baz' |
|
135 |
assert FormDef.get(formdef.id).internal_identifier == 'bar' # didn't change |
|
135 | 136 | |
136 | 137 | |
137 | 138 |
def test_substitution_variables(pub): |
tests/test_sql.py | ||
---|---|---|
1 | 1 |
import datetime |
2 |
import io |
|
2 | 3 |
import random |
3 | 4 |
import string |
4 | 5 |
import time |
6 |
import zipfile |
|
5 | 7 | |
6 | 8 |
import psycopg2 |
7 | 9 |
import pytest |
... | ... | |
2075 | 2077 |
assert len(sql_queries) == 2 |
2076 | 2078 |
assert 'SELECT' in sql_queries[0] |
2077 | 2079 |
assert 'UPDATE' in sql_queries[1] |
2080 | ||
2081 | ||
2082 |
def test_sql_import_zip_create_tables(): |
|
2083 |
pub = create_temporary_pub(sql_mode=True) |
|
2084 | ||
2085 |
c = io.BytesIO() |
|
2086 |
with zipfile.ZipFile(c, 'w') as z: |
|
2087 |
z.writestr( |
|
2088 |
'formdefs_xml/123', |
|
2089 |
'''<?xml version="1.0"?> |
|
2090 |
<formdef id="123"> |
|
2091 |
<name>crash</name> |
|
2092 |
<url_name>crash</url_name> |
|
2093 |
<internal_identifier>different-identifier</internal_identifier> |
|
2094 |
<max_field_id>1</max_field_id> |
|
2095 |
<fields> |
|
2096 |
</fields> |
|
2097 |
</formdef> |
|
2098 |
''', |
|
2099 |
) |
|
2100 |
c.seek(0) |
|
2101 | ||
2102 |
pub.import_zip(c) |
|
2103 | ||
2104 |
formdef = FormDef.get(123) |
|
2105 | ||
2106 |
conn, cur = sql.get_connection_and_cursor() |
|
2107 |
assert table_exists(cur, formdef.table_name) |
|
2108 |
conn.commit() |
|
2109 |
cur.close() |
wcs/formdef.py | ||
---|---|---|
93 | 93 |
description = None |
94 | 94 |
keywords = None |
95 | 95 |
url_name = None |
96 |
internal_identifier = None # mostly for pickle
|
|
96 |
internal_identifier = None # used to have a stable pickle object class name
|
|
97 | 97 |
table_name = None # for SQL only |
98 | 98 |
fields = None |
99 | 99 |
category_id = None |
... | ... | |
402 | 402 |
new_internal_identifier = self.get_new_internal_identifier() |
403 | 403 |
if not self.internal_identifier: |
404 | 404 |
self.internal_identifier = new_internal_identifier |
405 |
object_only = kwargs.pop('object_only', False) |
|
406 | 405 |
if new_internal_identifier != self.internal_identifier: |
407 | 406 |
# title changed, internal identifier will be changed only if |
408 | 407 |
# the formdef is currently being imported (self.id is None) |
409 |
# or if there are not yet any submitted forms |
|
410 |
if self.id is None or self.data_class().count() == 0: |
|
408 |
# or if there are not yet any submitted forms (or if site |
|
409 |
# is using the SQL storage as internal identifier is not used |
|
410 |
# in that mode. |
|
411 |
if self.id is None or get_publisher().is_using_postgresql() or self.data_class().count() == 0: |
|
411 | 412 |
self.internal_identifier = new_internal_identifier |
413 |
object_only = kwargs.pop('object_only', False) |
|
412 | 414 |
StorableObject.store(self, *args, **kwargs) |
413 | 415 |
if object_only: |
414 | 416 |
return |
415 |
- |