import django.template
import django.template.loader
import pretend


def test_compile_filter(monkeypatch):

    compile_static = pretend.call_recorder(lambda source_path: "compiled")
    monkeypatch.setattr("static_precompiler.utils.compile_static", compile_static)
    template = django.template.loader.get_template_from_string("""{% load compile_static %}{{ "source"|compile }}""")
    assert template.render(django.template.Context({})) == "compiled"

    monkeypatch.setattr("static_precompiler.settings.PREPEND_STATIC_URL", True)
    assert template.render(django.template.Context({})) == "/static/compiled"

    assert compile_static.calls == [pretend.call("source"), pretend.call("source")]


def test_inlinecompile_tag(monkeypatch):
    compiler = pretend.stub(compile_source=pretend.call_recorder(lambda *args: "compiled"))
    get_compiler_by_name = pretend.call_recorder(lambda *args: compiler)

    monkeypatch.setattr("static_precompiler.utils.get_compiler_by_name", get_compiler_by_name)

    template = django.template.loader.get_template_from_string(
        "{% load compile_static %}{% inlinecompile compiler='sass' %}source{% endinlinecompile %}"
    )
    assert template.render(django.template.Context({})) == "compiled"

    assert get_compiler_by_name.calls == [pretend.call("sass")]
    assert compiler.compile_source.calls == [pretend.call("source")]

import django.template
import pretend


def test_compile_filter(monkeypatch):

    compile_static = pretend.call_recorder(lambda source_path: "compiled")
    monkeypatch.setattr("static_precompiler.utils.compile_static", compile_static)
    template = django.template.Template("""{% load compile_static %}{{ "source"|compile }}""")
    assert template.render(django.template.Context({})) == "compiled"

    monkeypatch.setattr("static_precompiler.settings.PREPEND_STATIC_URL", True)
    assert template.render(django.template.Context({})) == "/static/compiled"

    assert compile_static.calls == [pretend.call("source"), pretend.call("source")]


def test_inlinecompile_tag(monkeypatch):
    compiler = pretend.stub(compile_source=pretend.call_recorder(lambda *args: "compiled"))
    get_compiler_by_name = pretend.call_recorder(lambda *args: compiler)

    monkeypatch.setattr("static_precompiler.utils.get_compiler_by_name", get_compiler_by_name)

    template = django.template.Template(
        "{% load compile_static %}{% inlinecompile compiler='sass' %}source{% endinlinecompile %}"
    )
    assert template.render(django.template.Context({})) == "compiled"

    assert get_compiler_by_name.calls == [pretend.call("sass")]
    assert compiler.compile_source.calls == [pretend.call("source")]

Fix tests for Django 1.8
Fix tests for Django 1.8

  import django.template
- import django.template.loader
  import pretend
  
  
  def test_compile_filter(monkeypatch):
  
      compile_static = pretend.call_recorder(lambda source_path: "compiled")
      monkeypatch.setattr("static_precompiler.utils.compile_static", compile_static)
-     template = django.template.loader.get_template_from_string("""{% load compile_static %}{{ "source"|compile }}""")
+     template = django.template.Template("""{% load compile_static %}{{ "source"|compile }}""")
      assert template.render(django.template.Context({})) == "compiled"
  
      monkeypatch.setattr("static_precompiler.settings.PREPEND_STATIC_URL", True)
      assert template.render(django.template.Context({})) == "/static/compiled"
  
      assert compile_static.calls == [pretend.call("source"), pretend.call("source")]
  
  
  def test_inlinecompile_tag(monkeypatch):
      compiler = pretend.stub(compile_source=pretend.call_recorder(lambda *args: "compiled"))
      get_compiler_by_name = pretend.call_recorder(lambda *args: compiler)
  
      monkeypatch.setattr("static_precompiler.utils.get_compiler_by_name", get_compiler_by_name)
  
-     template = django.template.loader.get_template_from_string(
+     template = django.template.Template(
          "{% load compile_static %}{% inlinecompile compiler='sass' %}source{% endinlinecompile %}"
      )
      assert template.render(django.template.Context({})) == "compiled"
  
      assert get_compiler_by_name.calls == [pretend.call("sass")]
      assert compiler.compile_source.calls == [pretend.call("source")]
  
Fix tests for Django 1.8
## Code Before:
import django.template
import django.template.loader
import pretend


def test_compile_filter(monkeypatch):

    compile_static = pretend.call_recorder(lambda source_path: "compiled")
    monkeypatch.setattr("static_precompiler.utils.compile_static", compile_static)
    template = django.template.loader.get_template_from_string("""{% load compile_static %}{{ "source"|compile }}""")
    assert template.render(django.template.Context({})) == "compiled"

    monkeypatch.setattr("static_precompiler.settings.PREPEND_STATIC_URL", True)
    assert template.render(django.template.Context({})) == "/static/compiled"

    assert compile_static.calls == [pretend.call("source"), pretend.call("source")]


def test_inlinecompile_tag(monkeypatch):
    compiler = pretend.stub(compile_source=pretend.call_recorder(lambda *args: "compiled"))
    get_compiler_by_name = pretend.call_recorder(lambda *args: compiler)

    monkeypatch.setattr("static_precompiler.utils.get_compiler_by_name", get_compiler_by_name)

    template = django.template.loader.get_template_from_string(
        "{% load compile_static %}{% inlinecompile compiler='sass' %}source{% endinlinecompile %}"
    )
    assert template.render(django.template.Context({})) == "compiled"

    assert get_compiler_by_name.calls == [pretend.call("sass")]
    assert compiler.compile_source.calls == [pretend.call("source")]

## Instruction:
Fix tests for Django 1.8
## Code After:
import django.template
import pretend


def test_compile_filter(monkeypatch):

    compile_static = pretend.call_recorder(lambda source_path: "compiled")
    monkeypatch.setattr("static_precompiler.utils.compile_static", compile_static)
    template = django.template.Template("""{% load compile_static %}{{ "source"|compile }}""")
    assert template.render(django.template.Context({})) == "compiled"

    monkeypatch.setattr("static_precompiler.settings.PREPEND_STATIC_URL", True)
    assert template.render(django.template.Context({})) == "/static/compiled"

    assert compile_static.calls == [pretend.call("source"), pretend.call("source")]


def test_inlinecompile_tag(monkeypatch):
    compiler = pretend.stub(compile_source=pretend.call_recorder(lambda *args: "compiled"))
    get_compiler_by_name = pretend.call_recorder(lambda *args: compiler)

    monkeypatch.setattr("static_precompiler.utils.get_compiler_by_name", get_compiler_by_name)

    template = django.template.Template(
        "{% load compile_static %}{% inlinecompile compiler='sass' %}source{% endinlinecompile %}"
    )
    assert template.render(django.template.Context({})) == "compiled"

    assert get_compiler_by_name.calls == [pretend.call("sass")]
    assert compiler.compile_source.calls == [pretend.call("source")]
