Example #1
0
 def test_content_fails(self):
     bundle = MagicMock()
     bundle.bundle_dir = "/tmp/bw_file_test"
     bundle.bundle_data_dir = "/d/dir"
     f = files.File(bundle, "foo", { 'content_type': 'mako', 'source': "fail" })
     with self.assertRaises(CompileException):
         f.test()
Example #2
0
 def test_missing_template(self):
     bundle = MagicMock()
     bundle.bundle_dir = "/bogus"
     bundle.bundle_data_dir = "/notthere"
     f = files.File(bundle, "foo", { 'source': "bogus" })
     with self.assertRaises(BundleError):
         f.test()
Example #3
0
 def test_create(self):
     if system() == "Darwin":
         return
     handle, target_file = mkstemp()
     remove(target_file)
     bundle = MagicMock()
     bundle.bundle_dir = mkdtemp()
     bundle.bundle_data_dir = mkdtemp()
     bundle.node = Node('localhost')
     Repository().add_node(bundle.node)
     item = files.File(
         bundle,
         target_file,
         {
             'content_type': 'mako',
             'owner': getuser(),
             'source': 'my_template',
         },
     )
     mkdir(item.item_dir)
     with open(join(item.item_dir, "my_template"), 'w') as f:
         f.write("Hi from ${node.name}!")
     item.apply(interactive=False)
     with open(target_file) as f:
         content = f.read()
     try:
         self.assertEqual(content, "Hi from localhost!")
     finally:
         remove(target_file)
Example #4
0
 def test_binary(self, hash_local_file):
     bundle = MagicMock()
     bundle.bundle_dir = "/b/dir"
     bundle.bundle_data_dir = "/d/dir"
     f = files.File(
         bundle,
         "/foo",
         {'content_type': 'binary', 'source': 'foobar'},
     )
     self.assertEqual(f.content_hash, "47")
     hash_local_file.assert_called_once_with("/b/dir/files/foobar")
Example #5
0
 def test_regular(self):
     node = MagicMock()
     bundle = MagicMock()
     bundle.bundle_dir = "/b/dir"
     bundle.bundle_data_dir = "/d/dir"
     bundle.node = node
     f = files.File(
         bundle,
         "/foo",
         {'content': "47", 'content_type': 'mako'},
     )
     f._fix_content(MagicMock())
     node.upload.assert_called_once()
Example #6
0
 def test_binary(self):
     node = MagicMock()
     bundle = MagicMock()
     bundle.bundle_dir = "/b/dir"
     bundle.bundle_data_dir = "/d/dir"
     bundle.node = node
     f = files.File(
         bundle,
         "/foo",
         {'content_type': 'binary', 'source': 'foobar'},
     )
     f._fix_content(MagicMock())
     node.upload.assert_called_once_with(
         "/b/dir/files/foobar",
         "/foo",
         owner="",
         group="",
         mode=None,
     )
Example #7
0
 def test_content_ok(self):
     bundle = MagicMock()
     bundle.bundle_dir = "/tmp/bw_file_test"
     bundle.bundle_data_dir = "/d/dir"
     f = files.File(bundle, "foo", { 'content_type': 'mako', 'source': "success" })
     f.test()