Exemplo n.º 1
0
    def _make_repository(self, jpgs=['test.jpg', 'test2.jpg', 'test3.jpg'],
                         date=(2007,2,15), visibility='new'):
        import datetime
        import os
        import shutil
        import sys
        import tempfile
        from edwin.models.album import Album
        from edwin.models.photo import Photo
        self.root_path = tempfile.mkdtemp('_test', 'edwin_')
        here = os.path.dirname(sys.modules[__name__].__file__)
        test_jpgs = [os.path.join(here, jpg) for jpg in jpgs]
        n = len(test_jpgs)

        from happy.acl import Allow
        from happy.acl import Everyone
        Album(self.root_path)._acl = [
            (Allow, Everyone, 'view')
        ]

        if date is not None:
            year, month, day = 2007, 2, 15
        for album_name in ['one', 'two']:
            if date is not None:
                day += 1
            path = os.path.join(self.root_path, album_name)
            os.mkdir(path)
            album = Album(path)
            album.title = album_name.title()
            album.desc = 'Test %s' % album.title
            if date is not None:
                album.date_range = (
                    datetime.date(year, month, day),
                    datetime.date(year, month, day),
                    )
            for i in xrange(5):
                fpath = os.path.join(album.fspath, 'test%02d.jpg' % i)
                shutil.copy(test_jpgs[i%n], fpath)
                photo = Photo(fpath)
                photo.title = 'Test %02d' % i
                photo.visibility = visibility
Exemplo n.º 2
0
    def setUp(self):
        # Create test fixtures
        import os
        import shutil
        import sys
        import tempfile
        tmpdir = tempfile.mkdtemp('edwin_', '_twill_test_fixture')
        here = os.path.dirname(sys.modules[__name__].__file__)
        test_jpg = os.path.join(here, 'test.jpg')
        photos_dir = os.path.join(tmpdir, 'var', 'photos')

        import datetime
        from edwin.models.album import Album
        from edwin.models.photo import Photo
        date = datetime.date(*self.start_date)

        from happy.acl import ALL_PERMISSIONS
        from happy.acl import Allow
        from happy.acl import Everyone
        os.makedirs(photos_dir)
        Album(photos_dir)._acl = [
            (Allow, Everyone, ['view']),
            (Allow, 'group.Administrators', ALL_PERMISSIONS),
        ]

        for i in xrange(self.n_albums):
            parts = map(str, (date.year, date.month, date.day))
            album_dir = os.path.join(photos_dir, *parts)
            os.makedirs(album_dir)
            album = Album(album_dir)
            album.title = str(date)

            for j in xrange(self.n_photos):
                photo_file = os.path.join(album_dir, 'photo_%02d.jpg' % j)
                os.symlink(test_jpg, photo_file)
                photo = Photo(photo_file)
                photo.title = 'Test %d' % j
                photo.visibility = self.initial_visibility

            album.update_acl()
            date += datetime.timedelta(days=self.delta_days)

        etc = os.path.join(tmpdir, 'etc')
        os.mkdir(etc)
        for fname in ('test.ini', 'htpasswd', 'principals'):
            src = os.path.join(here, fname)
            dst = os.path.join(etc, fname)
            os.symlink(src, dst)

        ini_file = os.path.join(etc, 'test.ini')
        from edwin.config import ApplicationContext
        app_context = ApplicationContext(ini_file)
        app_context.catalog.scan()

        # Twill is unable to parse the standard login form.  I don't know why.
        # I don't want to f**k with it any more.  Substitute this very easy
        # to parse one.
        def login_template(**kw):
            return u"""
                <html>
                  <head>
                    <title>WTF?</title>
                  </head>
                  <body>
                    <form method="POST" name="login">
                      <input type="hidden" name="redirect_to"
                             value="%(redirect_to)s">
                      <input name="login" value="%(login)s">
                      <input name="password" type="password">
                      <input type="submit" value="log in">
                      %(status_msg)s
                    </form>
                  </body>
                </html>
            """ % kw

        # Init wsgi app
        from edwin.application import make_app
        app = make_app(ini_file, login_template=login_template)
        def get_app():
            return app

        # Register wsgi intercept and visit homepage to start off
        import twill
        twill.add_wsgi_intercept('localhost', 8080, get_app)
        twill.commands.go('http://localhost:8080/')
        twill.commands.code(200)

        self.tmpdir = tmpdir