~ubuntu-branches/ubuntu/precise/landscape-client/precise

« back to all changes in this revision

Viewing changes to landscape/lib/tests/test_fs.py

  • Committer: Package Import Robot
  • Author(s): Andreas Hasenack
  • Date: 2012-03-19 09:33:34 UTC
  • mto: This revision was merged to the branch mainline in revision 41.
  • Revision ID: package-import@ubuntu.com-20120319093334-oxjttz163vvfgq8s
Tags: upstream-12.04
ImportĀ upstreamĀ versionĀ 12.04

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
 
1
3
from landscape.tests.helpers import LandscapeTest
2
4
 
3
 
from landscape.lib.fs import read_file, touch_file
 
5
from landscape.lib.fs import append_file, read_file, touch_file
4
6
 
5
7
 
6
8
class ReadFileTest(LandscapeTest):
59
61
        touch_file(path)
60
62
        touch_file(path)
61
63
        self.assertFileContent(path, "")
 
64
 
 
65
 
 
66
class AppendFileTest(LandscapeTest):
 
67
 
 
68
    def test_append_existing_file(self):
 
69
        """
 
70
        The L{append_file} function appends contents to an existing file.
 
71
        """
 
72
        existing_file = self.makeFile("foo bar")
 
73
        append_file(existing_file, " baz")
 
74
        self.assertFileContent(existing_file, "foo bar baz")
 
75
 
 
76
    def test_append_no_file(self):
 
77
        """
 
78
        The L{append_file} function creates a new file if one doesn't
 
79
        exist already.
 
80
        """
 
81
        new_file = os.path.join(self.makeDir(), "new_file")
 
82
        append_file(new_file, "contents")
 
83
        self.assertFileContent(new_file, "contents")