def test_build_short_url(self): with h.push_config(config, **{ 'short_url.url_pattern': '{base_url}:{nbhd}:{project}:{mount_point}:{short_name}', 'base_url': 'b', }): nbhd = mock.Mock(url_prefix='/n/') project = mock.Mock(shortname='p', neighborhood=nbhd) app = mock.Mock(project=project) app.config.options.mount_point = 'm' url = ShortUrl.build_short_url(app, 's') assert_equal(url, 'b:n:p:m:s')
def command(self): self._setup() self._load_objects() if self.options.clean: ShortUrl.query.remove({'app_config_id': c.app.config._id}) for row in self.urls.select().execute(): url = ShortUrl.upsert(h.really_unicode(row['short_id'])) url.full_url = h.really_unicode(row['url']) url.description = h.really_unicode(row['description']) url.private = row['private'] == 'Y' url.created = datetime.utcfromtimestamp(row['create_time']) url.last_updated = datetime.utcfromtimestamp(row['edit_time']) user = M.User.query.find({'tool_data.sfx.userid': row['create_user']}).first() url.create_user = user._id if user else M.User.anonymous()._id session(ShortUrl).flush()