Created
March 19, 2012 20:40
-
-
Save nwjsmith/2126960 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
import urlparse | |
import os.path | |
opts = { 'cachedir': '/var/cache/salt' } | |
env = 'base' | |
def destdir(url_data): | |
dest = os.path.normpath( | |
os.sep.join([ | |
opts['cachedir'], | |
'extrn_files', | |
env, | |
url_data.netloc, | |
url_data.path])) | |
return os.path.dirname(dest) | |
class TestCacheDestination(unittest.TestCase): | |
def test_dest_from_top_level_path(self): | |
url_data = urlparse.urlparse('http://example.com/foo.bar') | |
self.assertEqual('/var/cache/salt/extrn_files/base/example.com', destdir(url_data)) | |
def test_dest_from_subpath(self): | |
url_data = urlparse.urlparse('http://example.com/debs/foo.bar') | |
self.assertEqual('/var/cache/salt/extrn_files/base/example.com/debs', destdir(url_data)) | |
def test_dest_from_nested_subpath(self): | |
url_data = urlparse.urlparse('http://example.com/top/debs/foo.bar') | |
self.assertEqual('/var/cache/salt/extrn_files/base/example.com/top/debs', destdir(url_data)) | |
unittest.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@master:~$ python --version | |
Python 2.6.5 | |
vagrant@master:~$ wget https://raw.github.com/gist/2126960/9babcd4b49b8ae4841b92a5b5124eb6fc84027d7/destdir.py | |
--2012-03-20 06:18:51-- https://raw.github.com/gist/2126960/9babcd4b49b8ae4841b92a5b5124eb6fc84027d7/destdir.py | |
Resolving raw.github.com... 207.97.227.243 | |
Connecting to raw.github.com|207.97.227.243|:443... connected. | |
HTTP request sent, awaiting response... 200 OK | |
Length: 996 [text/plain] | |
Saving to: `destdir.py' | |
100%[============================================================================>] 996 --.-K/s in 0s | |
2012-03-20 06:18:51 (283 MB/s) - `destdir.py' saved [996/996] | |
vagrant@master:~$ python destdir.py | |
... | |
---------------------------------------------------------------------- | |
Ran 3 tests in 0.000s | |
OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ λ python --version | |
Python 2.7.2 | |
~ λ wget https://raw.github.com/gist/2126960/9babcd4b49b8ae4841b92a5b5124eb6fc84027d7/destdir.py | |
--2012-03-20 09:20:33-- https://raw.github.com/gist/2126960/9babcd4b49b8ae4841b92a5b5124eb6fc84027d7/destdir.py | |
Resolving raw.github.com... 207.97.227.243 | |
Connecting to raw.github.com|207.97.227.243|:443... connected. | |
HTTP request sent, awaiting response... 200 OK | |
Length: 996 [text/plain] | |
Saving to: `destdir.py' | |
100%[============================================================================>] 996 --.-K/s in 0s | |
2012-03-20 09:20:33 (950 MB/s) - `destdir.py' saved [996/996] | |
~ λ python destdir.py | |
... | |
---------------------------------------------------------------------- | |
Ran 3 tests in 0.001s | |
OK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment