96 self.failIf(osp.isfile(expected_filepath)) |
96 self.failIf(osp.isfile(expected_filepath)) |
97 |
97 |
98 def test_bfss_sqlite_fspath(self): |
98 def test_bfss_sqlite_fspath(self): |
99 f1 = self.create_file() |
99 f1 = self.create_file() |
100 expected_filepath = osp.join(self.tempdir, '%s_data_%s' % (f1.eid, f1.data_name)) |
100 expected_filepath = osp.join(self.tempdir, '%s_data_%s' % (f1.eid, f1.data_name)) |
101 self.assertEquals(self.fspath(f1), expected_filepath) |
101 self.assertEqual(self.fspath(f1), expected_filepath) |
102 |
102 |
103 def test_bfss_fs_importing_doesnt_touch_path(self): |
103 def test_bfss_fs_importing_doesnt_touch_path(self): |
104 self.session.transaction_data['fs_importing'] = True |
104 self.session.transaction_data['fs_importing'] = True |
105 filepath = osp.abspath(__file__) |
105 filepath = osp.abspath(__file__) |
106 f1 = self.session.create_entity('File', data=Binary(filepath), |
106 f1 = self.session.create_entity('File', data=Binary(filepath), |
107 data_format=u'text/plain', data_name=u'foo') |
107 data_format=u'text/plain', data_name=u'foo') |
108 self.assertEquals(self.fspath(f1), filepath) |
108 self.assertEqual(self.fspath(f1), filepath) |
109 |
109 |
110 def test_source_storage_transparency(self): |
110 def test_source_storage_transparency(self): |
111 with self.temporary_appobjects(DummyBeforeHook, DummyAfterHook): |
111 with self.temporary_appobjects(DummyBeforeHook, DummyAfterHook): |
112 self.create_file() |
112 self.create_file() |
113 |
113 |
114 def test_source_mapped_attribute_error_cases(self): |
114 def test_source_mapped_attribute_error_cases(self): |
115 ex = self.assertRaises(QueryError, self.execute, |
115 ex = self.assertRaises(QueryError, self.execute, |
116 'Any X WHERE X data ~= "hop", X is File') |
116 'Any X WHERE X data ~= "hop", X is File') |
117 self.assertEquals(str(ex), 'can\'t use File.data (X data ILIKE "hop") in restriction') |
117 self.assertEqual(str(ex), 'can\'t use File.data (X data ILIKE "hop") in restriction') |
118 ex = self.assertRaises(QueryError, self.execute, |
118 ex = self.assertRaises(QueryError, self.execute, |
119 'Any X, Y WHERE X data D, Y data D, ' |
119 'Any X, Y WHERE X data D, Y data D, ' |
120 'NOT X identity Y, X is File, Y is File') |
120 'NOT X identity Y, X is File, Y is File') |
121 self.assertEquals(str(ex), "can't use D as a restriction variable") |
121 self.assertEqual(str(ex), "can't use D as a restriction variable") |
122 # query returning mix of mapped / regular attributes (only file.data |
122 # query returning mix of mapped / regular attributes (only file.data |
123 # mapped, not image.data for instance) |
123 # mapped, not image.data for instance) |
124 ex = self.assertRaises(QueryError, self.execute, |
124 ex = self.assertRaises(QueryError, self.execute, |
125 'Any X WITH X BEING (' |
125 'Any X WITH X BEING (' |
126 ' (Any NULL)' |
126 ' (Any NULL)' |
127 ' UNION ' |
127 ' UNION ' |
128 ' (Any D WHERE X data D, X is File)' |
128 ' (Any D WHERE X data D, X is File)' |
129 ')') |
129 ')') |
130 self.assertEquals(str(ex), 'query fetch some source mapped attribute, some not') |
130 self.assertEqual(str(ex), 'query fetch some source mapped attribute, some not') |
131 ex = self.assertRaises(QueryError, self.execute, |
131 ex = self.assertRaises(QueryError, self.execute, |
132 '(Any D WHERE X data D, X is File)' |
132 '(Any D WHERE X data D, X is File)' |
133 ' UNION ' |
133 ' UNION ' |
134 '(Any D WHERE X title D, X is Bookmark)') |
134 '(Any D WHERE X title D, X is Bookmark)') |
135 self.assertEquals(str(ex), 'query fetch some source mapped attribute, some not') |
135 self.assertEqual(str(ex), 'query fetch some source mapped attribute, some not') |
136 |
136 |
137 storages.set_attribute_storage(self.repo, 'State', 'name', |
137 storages.set_attribute_storage(self.repo, 'State', 'name', |
138 storages.BytesFileSystemStorage(self.tempdir)) |
138 storages.BytesFileSystemStorage(self.tempdir)) |
139 try: |
139 try: |
140 ex = self.assertRaises(QueryError, |
140 ex = self.assertRaises(QueryError, |
141 self.execute, 'Any D WHERE X name D, X is IN (State, Transition)') |
141 self.execute, 'Any D WHERE X name D, X is IN (State, Transition)') |
142 self.assertEquals(str(ex), 'query fetch some source mapped attribute, some not') |
142 self.assertEqual(str(ex), 'query fetch some source mapped attribute, some not') |
143 finally: |
143 finally: |
144 storages.unset_attribute_storage(self.repo, 'State', 'name') |
144 storages.unset_attribute_storage(self.repo, 'State', 'name') |
145 |
145 |
146 def test_source_mapped_attribute_advanced(self): |
146 def test_source_mapped_attribute_advanced(self): |
147 f1 = self.create_file() |
147 f1 = self.create_file() |
148 rset = self.execute('Any X,D WITH D,X BEING (' |
148 rset = self.execute('Any X,D WITH D,X BEING (' |
149 ' (Any D, X WHERE X eid %(x)s, X data D)' |
149 ' (Any D, X WHERE X eid %(x)s, X data D)' |
150 ' UNION ' |
150 ' UNION ' |
151 ' (Any D, X WHERE X eid %(x)s, X data D)' |
151 ' (Any D, X WHERE X eid %(x)s, X data D)' |
152 ')', {'x': f1.eid}) |
152 ')', {'x': f1.eid}) |
153 self.assertEquals(len(rset), 2) |
153 self.assertEqual(len(rset), 2) |
154 self.assertEquals(rset[0][0], f1.eid) |
154 self.assertEqual(rset[0][0], f1.eid) |
155 self.assertEquals(rset[1][0], f1.eid) |
155 self.assertEqual(rset[1][0], f1.eid) |
156 self.assertEquals(rset[0][1].getvalue(), 'the-data') |
156 self.assertEqual(rset[0][1].getvalue(), 'the-data') |
157 self.assertEquals(rset[1][1].getvalue(), 'the-data') |
157 self.assertEqual(rset[1][1].getvalue(), 'the-data') |
158 rset = self.execute('Any X,LENGTH(D) WHERE X eid %(x)s, X data D', |
158 rset = self.execute('Any X,LENGTH(D) WHERE X eid %(x)s, X data D', |
159 {'x': f1.eid}) |
159 {'x': f1.eid}) |
160 self.assertEquals(len(rset), 1) |
160 self.assertEqual(len(rset), 1) |
161 self.assertEquals(rset[0][0], f1.eid) |
161 self.assertEqual(rset[0][0], f1.eid) |
162 self.assertEquals(rset[0][1], len('the-data')) |
162 self.assertEqual(rset[0][1], len('the-data')) |
163 rset = self.execute('Any X,LENGTH(D) WITH D,X BEING (' |
163 rset = self.execute('Any X,LENGTH(D) WITH D,X BEING (' |
164 ' (Any D, X WHERE X eid %(x)s, X data D)' |
164 ' (Any D, X WHERE X eid %(x)s, X data D)' |
165 ' UNION ' |
165 ' UNION ' |
166 ' (Any D, X WHERE X eid %(x)s, X data D)' |
166 ' (Any D, X WHERE X eid %(x)s, X data D)' |
167 ')', {'x': f1.eid}) |
167 ')', {'x': f1.eid}) |
168 self.assertEquals(len(rset), 2) |
168 self.assertEqual(len(rset), 2) |
169 self.assertEquals(rset[0][0], f1.eid) |
169 self.assertEqual(rset[0][0], f1.eid) |
170 self.assertEquals(rset[1][0], f1.eid) |
170 self.assertEqual(rset[1][0], f1.eid) |
171 self.assertEquals(rset[0][1], len('the-data')) |
171 self.assertEqual(rset[0][1], len('the-data')) |
172 self.assertEquals(rset[1][1], len('the-data')) |
172 self.assertEqual(rset[1][1], len('the-data')) |
173 ex = self.assertRaises(QueryError, self.execute, |
173 ex = self.assertRaises(QueryError, self.execute, |
174 'Any X,UPPER(D) WHERE X eid %(x)s, X data D', |
174 'Any X,UPPER(D) WHERE X eid %(x)s, X data D', |
175 {'x': f1.eid}) |
175 {'x': f1.eid}) |
176 self.assertEquals(str(ex), 'UPPER can not be called on mapped attribute') |
176 self.assertEqual(str(ex), 'UPPER can not be called on mapped attribute') |
177 |
177 |
178 |
178 |
179 def test_bfss_fs_importing_transparency(self): |
179 def test_bfss_fs_importing_transparency(self): |
180 self.session.transaction_data['fs_importing'] = True |
180 self.session.transaction_data['fs_importing'] = True |
181 filepath = osp.abspath(__file__) |
181 filepath = osp.abspath(__file__) |
182 f1 = self.session.create_entity('File', data=Binary(filepath), |
182 f1 = self.session.create_entity('File', data=Binary(filepath), |
183 data_format=u'text/plain', data_name=u'foo') |
183 data_format=u'text/plain', data_name=u'foo') |
184 self.assertEquals(f1.data.getvalue(), file(filepath).read(), |
184 self.assertEqual(f1.data.getvalue(), file(filepath).read(), |
185 'files content differ') |
185 'files content differ') |
186 |
186 |
187 @tag('Storage', 'BFSS', 'update') |
187 @tag('Storage', 'BFSS', 'update') |
188 def test_bfss_update_with_existing_data(self): |
188 def test_bfss_update_with_existing_data(self): |
189 # use self.session to use server-side cache |
189 # use self.session to use server-side cache |
206 # NOTE: do not use set_attributes() which would automatically |
206 # NOTE: do not use set_attributes() which would automatically |
207 # update f1's local dict. We want the pure rql version to work |
207 # update f1's local dict. We want the pure rql version to work |
208 self.commit() |
208 self.commit() |
209 old_path = self.fspath(f1) |
209 old_path = self.fspath(f1) |
210 self.failUnless(osp.isfile(old_path)) |
210 self.failUnless(osp.isfile(old_path)) |
211 self.assertEquals(osp.splitext(old_path)[1], '.txt') |
211 self.assertEqual(osp.splitext(old_path)[1], '.txt') |
212 self.execute('SET F data %(d)s, F data_name %(dn)s, F data_format %(df)s WHERE F eid %(f)s', |
212 self.execute('SET F data %(d)s, F data_name %(dn)s, F data_format %(df)s WHERE F eid %(f)s', |
213 {'d': Binary('some other data'), 'f': f1.eid, 'dn': u'bar.jpg', 'df': u'image/jpeg'}) |
213 {'d': Binary('some other data'), 'f': f1.eid, 'dn': u'bar.jpg', 'df': u'image/jpeg'}) |
214 self.commit() |
214 self.commit() |
215 # the new file exists with correct extension |
215 # the new file exists with correct extension |
216 # the old file is dead |
216 # the old file is dead |
217 f2 = self.execute('Any F WHERE F eid %(f)s, F is File', {'f': f1.eid}).get_entity(0, 0) |
217 f2 = self.execute('Any F WHERE F eid %(f)s, F is File', {'f': f1.eid}).get_entity(0, 0) |
218 new_path = self.fspath(f2) |
218 new_path = self.fspath(f2) |
219 self.failIf(osp.isfile(old_path)) |
219 self.failIf(osp.isfile(old_path)) |
220 self.failUnless(osp.isfile(new_path)) |
220 self.failUnless(osp.isfile(new_path)) |
221 self.assertEquals(osp.splitext(new_path)[1], '.jpg') |
221 self.assertEqual(osp.splitext(new_path)[1], '.jpg') |
222 |
222 |
223 @tag('Storage', 'BFSS', 'update', 'extension', 'rollback') |
223 @tag('Storage', 'BFSS', 'update', 'extension', 'rollback') |
224 def test_bfss_update_with_different_extension_rollbacked(self): |
224 def test_bfss_update_with_different_extension_rollbacked(self): |
225 # use self.session to use server-side cache |
225 # use self.session to use server-side cache |
226 f1 = self.session.create_entity('File', data=Binary('some data'), |
226 f1 = self.session.create_entity('File', data=Binary('some data'), |
229 # update f1's local dict. We want the pure rql version to work |
229 # update f1's local dict. We want the pure rql version to work |
230 self.commit() |
230 self.commit() |
231 old_path = self.fspath(f1) |
231 old_path = self.fspath(f1) |
232 old_data = f1.data.getvalue() |
232 old_data = f1.data.getvalue() |
233 self.failUnless(osp.isfile(old_path)) |
233 self.failUnless(osp.isfile(old_path)) |
234 self.assertEquals(osp.splitext(old_path)[1], '.txt') |
234 self.assertEqual(osp.splitext(old_path)[1], '.txt') |
235 self.execute('SET F data %(d)s, F data_name %(dn)s, F data_format %(df)s WHERE F eid %(f)s', |
235 self.execute('SET F data %(d)s, F data_name %(dn)s, F data_format %(df)s WHERE F eid %(f)s', |
236 {'d': Binary('some other data'), 'f': f1.eid, 'dn': u'bar.jpg', 'df': u'image/jpeg'}) |
236 {'d': Binary('some other data'), 'f': f1.eid, 'dn': u'bar.jpg', 'df': u'image/jpeg'}) |
237 self.rollback() |
237 self.rollback() |
238 # the new file exists with correct extension |
238 # the new file exists with correct extension |
239 # the old file is dead |
239 # the old file is dead |
240 f2 = self.execute('Any F WHERE F eid %(f)s, F is File', {'f': f1.eid}).get_entity(0, 0) |
240 f2 = self.execute('Any F WHERE F eid %(f)s, F is File', {'f': f1.eid}).get_entity(0, 0) |
241 new_path = self.fspath(f2) |
241 new_path = self.fspath(f2) |
242 new_data = f2.data.getvalue() |
242 new_data = f2.data.getvalue() |
243 self.failUnless(osp.isfile(new_path)) |
243 self.failUnless(osp.isfile(new_path)) |
244 self.assertEquals(osp.splitext(new_path)[1], '.txt') |
244 self.assertEqual(osp.splitext(new_path)[1], '.txt') |
245 self.assertEquals(old_path, new_path) |
245 self.assertEqual(old_path, new_path) |
246 self.assertEquals(old_data, new_data) |
246 self.assertEqual(old_data, new_data) |
247 |
247 |
248 def test_bfss_update_with_fs_importing(self): |
248 def test_bfss_update_with_fs_importing(self): |
249 # use self.session to use server-side cache |
249 # use self.session to use server-side cache |
250 f1 = self.session.create_entity('File', data=Binary('some data'), |
250 f1 = self.session.create_entity('File', data=Binary('some data'), |
251 data_format=u'text/plain', data_name=u'foo') |
251 data_format=u'text/plain', data_name=u'foo') |