server/test/unittest_storage.py
changeset 5242 0063d990ac5a
parent 5196 d14bfd477c44
parent 5240 2af0427e8ead
child 5423 e15abfdcce38
equal deleted inserted replaced
5241:1460d69672bc 5242:0063d990ac5a
    53 
    53 
    54 
    54 
    55     def create_file(self, content='the-data'):
    55     def create_file(self, content='the-data'):
    56         req = self.request()
    56         req = self.request()
    57         return req.create_entity('File', data=Binary(content),
    57         return req.create_entity('File', data=Binary(content),
    58                                  data_format=u'text/plain', data_name=u'foo')
    58                                  data_format=u'text/plain', data_name=u'foo.pdf')
    59 
    59 
    60     def fspath(self, entity):
    60     def fspath(self, entity):
    61         fspath = self.execute('Any fspath(D) WHERE F eid %(f)s, F data D',
    61         fspath = self.execute('Any fspath(D) WHERE F eid %(f)s, F data D',
    62                               {'f': entity.eid})[0][0]
    62                               {'f': entity.eid})[0][0]
    63         return fspath.getvalue()
    63         return fspath.getvalue()
    64 
    64 
    65     def test_bfss_storage(self):
    65     def test_bfss_storage(self):
    66         f1 = self.create_file()
    66         f1 = self.create_file()
    67         expected_filepath = osp.join(self.tempdir, '%s_data' % f1.eid)
    67         expected_filepath = osp.join(self.tempdir, '%s_data_%s' %
       
    68                                      (f1.eid, f1.data_name))
    68         self.failUnless(osp.isfile(expected_filepath))
    69         self.failUnless(osp.isfile(expected_filepath))
    69         self.assertEquals(file(expected_filepath).read(), 'the-data')
    70         self.assertEquals(file(expected_filepath).read(), 'the-data')
    70         self.rollback()
    71         self.rollback()
    71         self.failIf(osp.isfile(expected_filepath))
    72         self.failIf(osp.isfile(expected_filepath))
    72         f1 = self.create_file()
    73         f1 = self.create_file()
    83         self.commit()
    84         self.commit()
    84         self.failIf(osp.isfile(expected_filepath))
    85         self.failIf(osp.isfile(expected_filepath))
    85 
    86 
    86     def test_bfss_sqlite_fspath(self):
    87     def test_bfss_sqlite_fspath(self):
    87         f1 = self.create_file()
    88         f1 = self.create_file()
    88         expected_filepath = osp.join(self.tempdir, '%s_data' % f1.eid)
    89         expected_filepath = osp.join(self.tempdir, '%s_data_%s' % (f1.eid, f1.data_name))
    89         self.assertEquals(self.fspath(f1), expected_filepath)
    90         self.assertEquals(self.fspath(f1), expected_filepath)
    90 
    91 
    91     def test_bfss_fs_importing_doesnt_touch_path(self):
    92     def test_bfss_fs_importing_doesnt_touch_path(self):
    92         self.session.transaction_data['fs_importing'] = True
    93         self.session.transaction_data['fs_importing'] = True
    93         filepath = osp.abspath(__file__)
    94         filepath = osp.abspath(__file__)