def test_get_filename_from_path_when_path_ends_with_slash():
    mox = Mox()
    http_request, model_base, manager, model, queryset = get_mocks(mox)
    settings = CustomSettings(WEB_ROOT="test_web_root")
    
    fs_mock = mox.CreateMockAnything()
    fs_mock.join("test_web_root", "foo/bar/index.html").AndReturn("test_web_root/foo/bar/index.html")
    fs_mock.dirname("test_web_root/foo/bar/index.html").AndReturn("test_web_root/foo/bar")
    
    path_mock = '/foo/bar/'

    mox.ReplayAll()
    
    instance = StaticGenerator(http_request=http_request,
                               model_base=model_base,
                               manager=manager,
                               model=model,
                               queryset=queryset,
                               settings=settings,
                               fs=fs_mock)

    result = instance.get_filename_from_path(path_mock)
    
    assert result ==  ('test_web_root/foo/bar/index.html', 'test_web_root/foo/bar')
    mox.VerifyAll()
Esempio n. 2
0
def test_get_filename_from_path_when_path_ends_with_slash():
    mox = Mox()
    http_request, model_base, manager, model, queryset = get_mocks(mox)
    settings = CustomSettings(WEB_ROOT="test_web_root")
    
    fs_mock = mox.CreateMockAnything()
    fs_mock.join("test_web_root", "foo/bar/index.html").AndReturn("test_web_root/foo/bar/index.html")
    fs_mock.dirname("test_web_root/foo/bar/index.html").AndReturn("test_web_root/foo/bar")
    
    path_mock = '/foo/bar/'

    mox.ReplayAll()
    
    instance = StaticGenerator(http_request=http_request,
                               model_base=model_base,
                               manager=manager,
                               model=model,
                               queryset=queryset,
                               settings=settings,
                               fs=fs_mock)

    result = instance.get_filename_from_path(path_mock)
    
    assert result ==  ('test_web_root/foo/bar/index.html', 'test_web_root/foo/bar')
    mox.VerifyAll()
    def test_get_lang_aware_filename_from_path_when_path_ends_with_slash(self):
        for lang in ('uk', 'ru'):
            # activate first non-default language
            if lang != settings.LANGUAGE_CODE:
                activate('ru')

        instance = StaticGenerator()

        result = instance.get_filename_from_path('/foo/bar/', '')

        self.assertEqual('test_web_root/foo/bar/{}.index.html%3F'.format(lang),
                         result)
    def test_get_filename_from_path_when_path_ends_with_slash(self):
        instance = StaticGenerator()

        result = instance.get_filename_from_path('/foo/bar/', '')

        self.assertEqual('test_web_root/foo/bar/index.html%3F', result)
    def test_get_filename_from_path(self):
        instance = StaticGenerator()

        result = instance.get_filename_from_path('/foo/bar', '')

        self.assertEqual('test_web_root/foo/bar', result)
    def test_get_filename_from_path_when_path_ends_with_slash(self):
        instance = StaticGenerator()

        result = instance.get_filename_from_path('/foo/bar/', '')

        self.assertEqual('test_web_root/foo/bar/index.html%3F', result)
    def test_get_filename_from_path(self):
        instance = StaticGenerator()

        result = instance.get_filename_from_path('/foo/bar', '')

        self.assertEqual('test_web_root/foo/bar', result)