#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Tests for google.appengine.tools.devappserver2.static_files_handler."""


import errno
import os.path
import unittest

import google
import mox

from google.appengine.api import appinfo
from google.appengine.tools.devappserver2 import errors
from google.appengine.tools.devappserver2 import static_files_handler
from google.appengine.tools.devappserver2 import wsgi_test_utils


class TestStaticContentHandlerHandlePath(wsgi_test_utils.WSGITestCase):
  """Tests for static_files_handler.StaticContentHandler._handle_path."""

  def setUp(self):
    self.mox = mox.Mox()
    self.mox.StubOutWithMock(os.path, 'getmtime')
    self.mox.StubOutWithMock(static_files_handler.StaticContentHandler,
                             '_read_file')

  def tearDown(self):
    static_files_handler.StaticContentHandler._filename_to_mtime_and_etag = {}
    self.mox.UnsetStubs()

  def test_load_file(self):
    url_map = appinfo.URLMap(url='/',
                             static_files='index.html')

    h = static_files_handler.StaticContentHandler(
        root_path=None,
        url_map=url_map,
        url_pattern='/$')

    os.path.getmtime('/home/appdir/index.html').AndReturn(12345.6)
    static_files_handler.StaticContentHandler._read_file(