old_contents: # -*- coding: utf-8 -*-
  """Test that the package exists and has specified metadata."""
  
  from malt import Malt
  import pytest
  
  
  @pytest.fixture
  def app():
      app = Malt()
  
      @app.get('/')
      def root(request):
          return Response('Hello World!\n')
  
      return app
  
  
  def test_base_routing():
      app = Malt()
  
      @app.get('/')
      def root(request):
          return Response('Hello World!\n')
  
      @app.post('/')
      def post_home(request):
          return Response()
  
      assert app.router.path_map == {'/': {'GET': root, 'POST': post_home}}
  
  
  def test_duplicate_route(app):
  
      def view(request):
          return Response('')
  
      with pytest.raises(Exception) as exc_info:
          app.get('/')(view)
      assert 'Duplicate route: GET /' in str(exc_info)
  
      decorator = app.post('/')
      decorator(view)
      with pytest.raises(Exception) as exc_info:
          decorator(view)
      assert 'Duplicate route: POST /' in str(exc_info)
  
  
  def test_url_for(app):
  
      @app.get('/hello')
      def hello(request):
          return Response('Hi there\n')
  
      def unregistered(request):
          return Response('')
  
      assert app.url_for(hello) == '/hello'
      assert app.url_for(hello, msg='a = b') == '/hello?msg=a+%3D+b'
  
      with pytest.raises(Exception) as exc_info:
          app.url_for(unregistered)
      assert 'is not registered to a url' in str(exc_info)
  
new_contents: # -*- coding: utf-8 -*-
  """Test that the package exists and has specified metadata."""
  
  from malt.routing import Router
  import pytest
  
  
  def test_get_and_post():
      router = Router()
  
      def get_root():
          pass
  
      def post_root():
          pass
  
      def get_home():
          pass
  
      router.add_rule('GET', '/', get_root)
      router.add_rule('POST', '/', post_root)
      router.add_rule('GET', '/home', get_home)
      router.add_rule('GET', '/homie', get_home)
  
      assert router.path_map == {
          '/': {
              'GET': get_root,
              'POST': post_root,
          },
          '/home': {
              'GET': get_home,
          },
          '/homie': {
              'GET': get_home,
          }
      }
  
      assert router.view_map == {
          get_root: ('GET', '/'),
          post_root: ('POST', '/'),
          get_home: ('GET', '/home'),
      }
  
      assert router.get_view('GET', '/') == get_root
      assert router.get_view('POST', '/') == post_root
      assert router.get_view('GET', '/home') == get_home
      assert router.get_view('GET', '/homie') == get_home
  
      assert router.path_for(get_root) == '/'
      assert router.path_for(post_root) == '/'
      assert router.path_for(get_home) == '/home'
  
  
  def test_duplicate_route():
      router = Router()
  
      def get_root():
          pass
  
      def get_root_again():
          pass
  
      router.add_rule('GET', '/', get_root)
  
      for view in (get_root, get_root_again):
          with pytest.raises(Exception) as exc_info:
              router.add_rule('GET', '/', view)
          assert 'Duplicate route: GET /' in str(exc_info)
  
  
  def test_bad_rules():
      router = Router()
  
      def get_root():
          pass
  
      router.add_rule('GET', '/', get_root)
  
      assert router.get_view('GET', '/') == get_root
  
      for method in ('GET', 'POST', 'PUT', 'DELETE', 'fake method'):
          with pytest.raises(LookupError) as exc_info:
              router.get_view(method, '/something')
          assert str(exc_info.value) == 'No such path'
  
      for method in ('POST', 'PUT', 'DELETE', 'fake method'):
          with pytest.raises(LookupError) as exc_info:
              router.get_view(method, '/')
          assert str(exc_info.value) == 'No such method'
  
  
  def test_missing_view():
      router = Router()
  
      def get_root():
          pass
  
      def unregistered():
          pass
  
      router.add_rule('GET', '/', get_root)
  
      assert router.path_for(get_root) == '/'
  
      with pytest.raises(KeyError):
          router.path_for(unregistered)
  
subject: Rewrite routing tests