def test_index_route(self): with Mock() as full_path_redirect: from tvseries import full_path_redirect full_path_redirect({}, "/series") >> "/series" with Mock() as Redirect: from pyroutes.http.response import Redirect Redirect("/series") tvseries.routes.index(Request({})) Redirect.validate() full_path_redirect.validate()
def delete_episode(req, serie, episode): if serie and episode: s = Serie.get_by(name=serie) e = Episode.get_by(serie=s, name=episode) s.episodes.remove(e) session.commit() return Redirect(full_path_redirect(req.ENV, "/series/edit/%s" % serie))
def new_serie(req): if req.POST: serie = req.POST.get('serie', None) if serie: s = Serie(name=serie) session.commit() return Redirect(full_path_redirect(req.ENV, "/series")) return render_to_response('serie_new.html')
def edit_serie(req, serie): if req.POST: episode = req.POST.get('episode', None) if episode and serie: s = Serie.get_by(name=serie) e = Episode(name=episode) s.episodes.append(e) session.commit() return Redirect(full_path_redirect(req.ENV, "/series/edit/%s" % serie)) s = Serie.get_by(name=serie) return render_to_response('episode_new.html', {'serie': s})
def next_episode(req, serie): if serie and req.POST: s = Serie.get_by(name=serie) last_ep = s.last_episode() if last_ep: next = last_ep.next() if next: s.episodes.append(next) session.commit() return render_to_response('episode_new.html', {'serie': s}) return Redirect(full_path_redirect(req.ENV, '/'))
def test_script_name_empty(self): self.ENV['SCRIPT_NAME'] = '' self.assertEquals("https://www.somehost.com.br/path", full_path_redirect(self.ENV, "/path"))
def test_script_name_without_trailing_slash(self): self.ENV['SCRIPT_NAME'] = '/cgi-bin/app.py' self.assertEquals("https://www.somehost.com.br/cgi-bin/app.py/path", full_path_redirect(self.ENV, "/path"))
def test_https_not_port_443(self): self.ENV['SERVER_PORT'] = '8002' self.assertEquals("https://www.somehost.com.br:8002/cgi-bin/app.py/path", full_path_redirect(self.ENV, "/path"))
def test_http_not_port_80(self): self.ENV['SERVER_PORT'] = '8001' del self.ENV['HTTPS'] self.assertEquals("http://www.somehost.com.br:8001/cgi-bin/app.py/path", full_path_redirect(self.ENV, "/path"))
def test_basic_path(self): self.assertEquals("https://www.somehost.com.br/cgi-bin/app.py/path/to/go", full_path_redirect(self.ENV, "/path/to/go"))
def delete_serie(req, serie): s = Serie.get_by(name=serie) if s: s.delete() session.commit() return Redirect(full_path_redirect(req.ENV, "/series"))
def index(req): return Redirect(full_path_redirect(req.ENV, "/series"))