def test_opens_file_on_read(self):
     mock_s3()
     (flexmock(MockKey)
         .should_receive('open')
         .once())
     file_ = S3BotoStorageFile(self.storage, prefix='pics/')
     file_.read()
    def setup_method(self, method):
        TestCase.setup_method(self, method)
        flexmock(S3BotoStorage) \
            .should_receive('_get_or_create_bucket') \
            .with_args('some_bucket') \
            .and_return(MockBucket())

        self.storage = S3BotoStorage('some_bucket')
        self.file = S3BotoStorageFile(self.storage, 'some_file')
    def test_supports_reading(self):
        mock_s3()
        file_ = S3BotoStorageFile(self.storage, prefix='pics/')
        file_.name = 'some_key'

        (flexmock(MockKey)
            .should_receive('read')
            .once()
            .with_args(341)
            .and_return('test data!'))

        assert file_.read(341) == 'test data!'
 def test_does_not_open_file_on_creation(self):
     mock_s3()
     (flexmock(MockKey)
         .should_receive('open')
         .never())
     S3BotoStorageFile(self.storage, prefix='pics/')
 def test_supports_last_modified(self):
     mock_s3()
     file_ = S3BotoStorageFile(self.storage, prefix='pics/')
     file_.name = 'some_key'
     file_.last_modified
 def test_supports_prefixes(self):
     mock_s3()
     file_ = S3BotoStorageFile(self.storage, prefix='pics/')
     file_.name = 'some_key'
     assert file_.name == u'pics/some_key'
 def test_supports_file_objects_without_name(self):
     file_ = S3BotoStorageFile(self.storage)
     assert bool(file_) is False