85 self.assertEqual(str(cm.exception), |
85 self.assertEqual(str(cm.exception), |
86 'This callback is only available for BytesFileSystemStorage ' |
86 'This callback is only available for BytesFileSystemStorage ' |
87 'managed attribute. Is FSPATH() argument BFSS managed?') |
87 'managed attribute. Is FSPATH() argument BFSS managed?') |
88 |
88 |
89 def test_bfss_storage(self): |
89 def test_bfss_storage(self): |
90 with self.admin_access.repo_cnx() as cnx: |
90 with self.admin_access.web_request() as req: |
91 f1 = self.create_file(cnx) |
91 cnx = req.cnx |
|
92 f1 = self.create_file(req) |
92 filepaths = glob(osp.join(self.tempdir, '%s_data_*' % f1.eid)) |
93 filepaths = glob(osp.join(self.tempdir, '%s_data_*' % f1.eid)) |
93 self.assertEqual(len(filepaths), 1, filepaths) |
94 self.assertEqual(len(filepaths), 1, filepaths) |
94 expected_filepath = filepaths[0] |
95 expected_filepath = filepaths[0] |
95 # file should be read only |
96 # file should be read only |
96 self.assertFalse(os.access(expected_filepath, os.W_OK)) |
97 self.assertFalse(os.access(expected_filepath, os.W_OK)) |
97 self.assertEqual(file(expected_filepath).read(), 'the-data') |
98 self.assertEqual(open(expected_filepath).read(), 'the-data') |
98 cnx.rollback() |
99 cnx.rollback() |
99 self.assertFalse(osp.isfile(expected_filepath)) |
100 self.assertFalse(osp.isfile(expected_filepath)) |
100 filepaths = glob(osp.join(self.tempdir, '%s_data_*' % f1.eid)) |
101 filepaths = glob(osp.join(self.tempdir, '%s_data_*' % f1.eid)) |
101 self.assertEqual(len(filepaths), 0, filepaths) |
102 self.assertEqual(len(filepaths), 0, filepaths) |
102 f1 = self.create_file(cnx) |
103 f1 = self.create_file(req) |
103 cnx.commit() |
104 cnx.commit() |
104 filepaths = glob(osp.join(self.tempdir, '%s_data_*' % f1.eid)) |
105 filepaths = glob(osp.join(self.tempdir, '%s_data_*' % f1.eid)) |
105 self.assertEqual(len(filepaths), 1, filepaths) |
106 self.assertEqual(len(filepaths), 1, filepaths) |
106 expected_filepath = filepaths[0] |
107 expected_filepath = filepaths[0] |
107 self.assertEqual(file(expected_filepath).read(), 'the-data') |
108 self.assertEqual(open(expected_filepath).read(), 'the-data') |
|
109 |
|
110 # add f1 back to the entity cache with req as _cw |
|
111 f1 = req.entity_from_eid(f1.eid) |
108 f1.cw_set(data=Binary('the new data')) |
112 f1.cw_set(data=Binary('the new data')) |
109 cnx.rollback() |
113 cnx.rollback() |
110 self.assertEqual(file(expected_filepath).read(), 'the-data') |
114 self.assertEqual(open(expected_filepath).read(), 'the-data') |
111 f1.cw_delete() |
115 f1.cw_delete() |
112 self.assertTrue(osp.isfile(expected_filepath)) |
116 self.assertTrue(osp.isfile(expected_filepath)) |
113 cnx.rollback() |
117 cnx.rollback() |
114 self.assertTrue(osp.isfile(expected_filepath)) |
118 self.assertTrue(osp.isfile(expected_filepath)) |
115 f1.cw_delete() |
119 f1.cw_delete() |