From 5e4b359d43f247ad1c6c0b5384c1846f0733cc68 Mon Sep 17 00:00:00 2001
From: John Chilton <jmchilton@gmail.com>
Date: Tue, 18 Feb 2014 11:14:26 -0600
Subject: [PATCH] Fix bug related to newer job metadata abstraction.

Plus outline of unit tests for JobDirectory (including test that tracked bug down).
---
 lwr/managers/base/__init__.py |  2 +-
 test/job_directory_test.py    | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)
 create mode 100644 test/job_directory_test.py

diff --git a/lwr/managers/base/__init__.py b/lwr/managers/base/__init__.py
index 4d9fd8bf..c779195d 100644
--- a/lwr/managers/base/__init__.py
+++ b/lwr/managers/base/__init__.py
@@ -269,7 +269,7 @@ class JobDirectory(RemoteJobDirectory):
             return json.loads(contents)
 
     def has_metadata(self, metadata_name):
-        self.contains_file(metadata_name)
+        return self.contains_file(metadata_name)
 
 
 def get_mapped_file(directory, remote_path, allow_nested_files=False, local_path_module=os.path, mkdir=True):
diff --git a/test/job_directory_test.py b/test/job_directory_test.py
new file mode 100644
index 00000000..496aa97c
--- /dev/null
+++ b/test/job_directory_test.py
@@ -0,0 +1,27 @@
+from .test_utils import TempDirectoryTestCase
+from lwr.managers.base import JobDirectory
+import os
+
+TEST_JOB_ID = "1234"
+
+
+class JobDirectoryTestCase(TempDirectoryTestCase):
+
+    def setUp(self):
+        super(JobDirectoryTestCase, self).setUp()
+        self.job_directory = JobDirectory(self.temp_directory, TEST_JOB_ID)
+
+    def test_setup(self):
+        expected_path = os.path.join(self.temp_directory, TEST_JOB_ID)
+        assert not os.path.exists(expected_path)
+        self.job_directory.setup()
+        assert os.path.exists(expected_path)
+
+    def test_metadata(self):
+        self.prep()
+        assert not self.job_directory.has_metadata("MooCow")
+        self.job_directory.store_metadata("MooCow", True)
+        assert self.job_directory.has_metadata("MooCow")
+
+    def prep(self):
+        self.job_directory.setup()
-- 
GitLab