~jaypipes/+junk/creiht-paste-deploy

« back to all changes in this revision

Viewing changes to tests/stubs.py

  • Committer: Tarmac
  • Author(s): jaypipes at gmail
  • Date: 2010-12-11 20:17:00 UTC
  • mfrom: (19.2.5 teller-api)
  • Revision ID: tarmac-20101211201700-z16ecaqcvwl0ndcn
Adds DELETE call to Teller API

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
def stub_out_filesystem_backend(stubs):
84
84
    """
85
85
    Stubs out the Filesystem Teller service to return fake
86
 
    data from files.
 
86
    gzipped image data from files.
87
87
 
88
88
    We establish a few fake images in a directory under /tmp/glance-tests
89
89
    and ensure that this directory contains the following files:
104
104
        @classmethod
105
105
        def get(cls, parsed_uri, expected_size, opener=None):
106
106
            filepath = os.path.join('/',
107
 
                                    parsed_uri.netloc,
108
 
                                    parsed_uri.path.strip(os.path.sep))
109
 
            f = gzip.open(filepath, 'rb')
110
 
            data = f.read()
111
 
            f.close()
112
 
            return data
 
107
                                    parsed_uri.netloc.lstrip('/'),
 
108
                                    parsed_uri.path.strip(os.path.sep))
 
109
            if os.path.exists(filepath):
 
110
                f = gzip.open(filepath, 'rb')
 
111
                data = f.read()
 
112
                f.close()
 
113
                return data
 
114
            else:
 
115
                raise exception.NotFound("File %s does not exist" % filepath) 
 
116
 
 
117
        @classmethod
 
118
        def delete(self, parsed_uri):
 
119
            filepath = os.path.join('/',
 
120
                                    parsed_uri.netloc.lstrip('/'),
 
121
                                    parsed_uri.path.strip(os.path.sep))
 
122
            if os.path.exists(filepath):
 
123
                try:
 
124
                    os.unlink(filepath)
 
125
                except OSError:
 
126
                    raise exception.NotAuthorized("You cannot delete file %s" %
 
127
                                                  filepath)
 
128
            else:
 
129
                raise exception.NotFound("File %s does not exist" % filepath) 
113
130
 
114
131
    # Establish a clean faked filesystem with dummy images
115
132
    if os.path.exists(FAKE_FILESYSTEM_ROOTDIR):
130
147
    fake_filesystem_backend = FakeFilesystemBackend()
131
148
    stubs.Set(glance.teller.backends.FilesystemBackend, 'get',
132
149
              fake_filesystem_backend.get)
 
150
    stubs.Set(glance.teller.backends.FilesystemBackend, 'delete',
 
151
              fake_filesystem_backend.delete)
133
152
 
134
153
 
135
154
def stub_out_swift_backend(stubs):