Exemple #1
0
    def test_no_static_url(self, monkeypatch):
        settings = Mock(name='settings')
        settings.STATIC_URL = None
        monkeypatch.setattr(resource, 'settings', settings)

        storage = Mock(spec=Storage, name='storage')
        storage.path.return_value = '/tmp/file1'
        finder = Mock(name='finder')
        finder.list.return_value = (('img/1.jpg', storage), )

        sr = resource.StaticResource([finder], None)
Exemple #2
0
    def test_default(self, monkeypatch):
        settings = Mock(name='settings')
        settings.STATIC_URL = '/static/'
        monkeypatch.setattr(resource, 'settings', settings)

        request = Mock(name='request')
        request.prepath = ['admin']
        request.postpath = ['magic']

        sr = resource.StaticResource([], sentinel.default)
        r = sr.getChildWithDefault('admin', request) 

        assert r == sentinel.default
        assert request.prepath == []
        assert request.postpath == ['admin', 'magic']
Exemple #3
0
    def test_no_prefix(self, monkeypatch):
        settings = Mock(name='settings')
        settings.STATIC_URL = '/static/'
        monkeypatch.setattr(resource, 'settings', settings)
        File = Mock(name='file', return_value=sentinel.file)
        monkeypatch.setattr(resource.static, 'File', File)

        storage = Mock(spec=Storage, name='storage')
        storage.path.return_value = '/tmp/file1'
        finder = Mock(name='finder')
        finder.list.return_value = (('img/1.jpg', storage), )

        sr = resource.StaticResource([finder], None)

        r = sr.getChildWithDefault('static', None)
        r = r.getChildWithDefault('img', None)
        r = r.getChildWithDefault('1.jpg', None)

        assert r == sentinel.file
        File.assert_called_with('/tmp/file1')