Skip to content

Commit

Permalink
Merge pull request #37 from yunstanford/fix-request-cache
Browse files Browse the repository at this point in the history
Fix request cache
  • Loading branch information
toumorokoshi committed Aug 25, 2017
2 parents c01d129 + 687423b commit 3996093
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
26 changes: 26 additions & 0 deletions tests/test_get_remote_script_full.py
@@ -1,6 +1,7 @@
import httpretty
from uranium import get_remote_script
from uranium.build import Build
import pytest

SCRIPT_URL = "http://www.myinternalwebsite.com/uranium_base.py"

Expand Down Expand Up @@ -29,3 +30,28 @@ def test_get_remote_script_with_cache(tmpdir):
httpretty.disable()
httpretty.reset()
get_remote_script(SCRIPT_URL, cache_dir=tmpdir.strpath)


def test_build_include_cache(tmpdir):
httpretty.enable()
httpretty.register_uri(httpretty.GET, SCRIPT_URL,
body=REMOTE_SCRIPT)
build = Build(tmpdir.strpath)
build.URANIUM_CACHE_DIR = tmpdir.strpath
build.include(SCRIPT_URL, cache=True)
httpretty.disable()
httpretty.reset()
build.include(SCRIPT_URL, cache=True)


def test_build_include_without_cache(tmpdir):
httpretty.enable()
httpretty.register_uri(httpretty.GET, SCRIPT_URL,
body=REMOTE_SCRIPT)
build = Build(tmpdir.strpath)
build.URANIUM_CACHE_DIR = tmpdir.strpath
build.include(SCRIPT_URL, cache=False)
httpretty.disable()
httpretty.reset()
with pytest.raises(Exception):
build.include(SCRIPT_URL, cache=True)
4 changes: 2 additions & 2 deletions uranium/build.py
Expand Up @@ -44,7 +44,7 @@ class Build(object):
URANIUM_CACHE_DIR = ".uranium"
HISTORY_NAME = "history.json"

def __init__(self, root, config=None, with_sandbox=True):
def __init__(self, root, config=None, with_sandbox=True, cache_requests=True):
self._config = config or Config()
self._root = root
self._executables = Executables(root)
Expand All @@ -54,7 +54,7 @@ def __init__(self, root, config=None, with_sandbox=True):
self._tasks = Tasks()
self._envvars = EnvironmentVariables()
self._options = None
self._cache_requests = False
self._cache_requests = cache_requests
self._history = History(
os.path.join(self._root, self.URANIUM_CACHE_DIR, self.HISTORY_NAME)
)
Expand Down

0 comments on commit 3996093

Please sign in to comment.