From e7153965f09adae3ed0d70617848f7153e470286 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 1 Mar 2014 12:59:07 +0200 Subject: [PATCH] Move secrets out to test_pylast.yaml and provide an example. --- .gitignore | 1 + requirements.txt | 1 + test_pylast.py | 21 +++++++++++++++++---- test_pylast_example.yaml | 4 ++++ 4 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 requirements.txt mode change 100644 => 100755 test_pylast.py create mode 100644 test_pylast_example.yaml diff --git a/.gitignore b/.gitignore index 76f2a46..a66d7f0 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,4 @@ coverage.xml # Sphinx documentation docs/_build/ +test_pylast.yaml diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c3726e8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pyyaml diff --git a/test_pylast.py b/test_pylast.py old mode 100644 new mode 100755 index fb30c7c..2e64893 --- a/test_pylast.py +++ b/test_pylast.py @@ -5,20 +5,33 @@ Integration (not unit) tests for pylast.py import datetime import time import unittest +import yaml # pip install pyyaml import pylast +def load_secrets(): + with open("test_pylast.yaml", "r") as f: # see test_pylast_example.yaml + doc = yaml.load(f) + print doc + print doc["username"] + return doc + class TestSequenceFunctions(unittest.TestCase): + secrets = None + def unix_timestamp(self): return int(time.mktime(datetime.datetime.now().timetuple())) def setUp(self): - self.username = "TODO" - password_hash = "TODO" + if self.__class__.secrets is None: + self.__class__.secrets = load_secrets() - API_KEY = "TODO" - API_SECRET = "TODO" + self.username = self.__class__.secrets["username"] + password_hash = self.__class__.secrets["password_hash"] + + API_KEY = self.__class__.secrets["api_key"] + API_SECRET = self.__class__.secrets["api_secret"] self.network = pylast.LastFMNetwork(api_key = API_KEY, api_secret = API_SECRET, username = self.username, password_hash = password_hash) diff --git a/test_pylast_example.yaml b/test_pylast_example.yaml new file mode 100644 index 0000000..a8fa045 --- /dev/null +++ b/test_pylast_example.yaml @@ -0,0 +1,4 @@ +username: TODO_ENTER_YOURS_HERE +password_hash: TODO_ENTER_YOURS_HERE +api_key: TODO_ENTER_YOURS_HERE +api_secret: TODO_ENTER_YOURS_HERE