~ubuntu-branches/ubuntu/karmic/landscape-client/karmic-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2010-04-21 12:31:28 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100421123128-qwde8pqe5zi6so05
Tags: 1.5.0.1-0ubuntu0.9.10.0
* New upstream version
  - Fix smart-update failing its very first run (LP: #562496)
  - Depend on pythonX.Y-dbus and pythonX.Y-pycurl (LP: #563063)
  - Make only one request at a time to retrieve EC2 instances (LP: #567515)

* New upstream version (LP: #557244)
  - Fix package-changer running before smart-update has completed (LP: #542215)
  - Report the version of Eucalyptus used to generate topology data (LP: #554007)
  - Enable the Eucalyptus plugin by default, if supported (LP: #546531)
  - Use a whitelist of allowed filesystem types to instead of a blacklist (LP: #351927)
  - Report the update-manager logs to the server (LP: #503384)
  - Turn off Curl's DNS caching for requests. (LP: #522668)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from landscape.tests.helpers import LandscapeTest
 
2
 
 
3
from landscape.lib.fs import read_file, touch_file
 
4
 
 
5
 
 
6
class ReadFileTest(LandscapeTest):
 
7
 
 
8
    def test_read_file(self):
 
9
        """
 
10
        With no options L{read_file} reads the whole file passed as argument.
 
11
        """
 
12
        path = self.makeFile("foo")
 
13
        self.assertEquals(read_file(path), "foo")
 
14
 
 
15
    def test_read_file_with_limit(self):
 
16
        """
 
17
        With a positive limit L{read_file} reads only the bytes after the
 
18
        given limit.
 
19
        """
 
20
        path = self.makeFile("foo bar")
 
21
        self.assertEquals(read_file(path, limit=3), " bar")
 
22
 
 
23
    def test_read_file_with_negative_limit(self):
 
24
        """
 
25
        With a negative limit L{read_file} reads only the tail of the file.
 
26
        """
 
27
        path = self.makeFile("foo bar from end")
 
28
        self.assertEquals(read_file(path, limit=-3), "end")
 
29
 
 
30
    def test_read_file_with_limit_bigger_than_file(self):
 
31
        """
 
32
        If the limit is bigger than the file L{read_file} reads the entire
 
33
        file.
 
34
        """
 
35
        path = self.makeFile("foo bar from end")
 
36
        self.assertEquals(read_file(path, limit=100), "foo bar from end")
 
37
        self.assertEquals(read_file(path, limit=-100), "foo bar from end")
 
38
 
 
39
 
 
40
class TouchFileTest(LandscapeTest):
 
41
 
 
42
    def test_touch_file(self):
 
43
        """
 
44
        The L{touch_file} function touches a file, setting its last
 
45
        modification time.
 
46
        """
 
47
        path = self.makeFile()
 
48
        uname_mock = self.mocker.replace("os.utime")
 
49
        self.expect(uname_mock(path, None))
 
50
        self.mocker.replay()
 
51
        touch_file(path)
 
52
        self.assertFileContent(path, "")
 
53
 
 
54
    def test_touch_file_multiple_times(self):
 
55
        """
 
56
        The L{touch_file} function can be called multiple times.
 
57
        """
 
58
        path = self.makeFile()
 
59
        touch_file(path)
 
60
        touch_file(path)
 
61
        self.assertFileContent(path, "")