~ubuntu-branches/debian/sid/waagent/sid

« back to all changes in this revision

Viewing changes to tests/test_file_util.py

  • Committer: Package Import Robot
  • Author(s): Bastian Blank
  • Date: 2015-07-30 13:27:01 UTC
  • mfrom: (1.2.1) (3.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20150730132701-dvdym85n5twpucfk
Tags: 2.1.0-1
* New upstream version.
* Hijack package.
* Not longer try to install systemd stuff by package setup.
* Use own systemd service, use dh-systemd.
* Use own init script.
* Remove unused python3 support.
* Remove old postinst, postrm script.
* Remove upstart support, "It's dead, Jim".
* Make package arch-all.
* Disable environment monitor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2014 Microsoft Corporation
 
2
#
 
3
# Licensed under the Apache License, Version 2.0 (the "License");
 
4
# you may not use this file except in compliance with the License.
 
5
# You may obtain a copy of the License at
 
6
#
 
7
#     http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
# Unless required by applicable law or agreed to in writing, software
 
10
# distributed under the License is distributed on an "AS IS" BASIS,
 
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
12
# See the License for the specific language governing permissions and
 
13
# limitations under the License.
 
14
#
 
15
# Requires Python 2.4+ and Openssl 1.0+
 
16
#
 
17
# Implements parts of RFC 2131, 1541, 1497 and
 
18
# http://msdn.microsoft.com/en-us/library/cc227282%28PROT.10%29.aspx
 
19
# http://msdn.microsoft.com/en-us/library/cc227259%28PROT.13%29.aspx
 
20
 
 
21
import env
 
22
import tests.tools as tools
 
23
import uuid
 
24
import unittest
 
25
import os
 
26
import azurelinuxagent.utils.fileutil as fileutil
 
27
import test
 
28
 
 
29
class TestFileOperations(unittest.TestCase):
 
30
    def test_get_set_file_contents(self):
 
31
        test_file='/tmp/test_file'
 
32
        content = str(uuid.uuid4())
 
33
        fileutil.SetFileContents(test_file, content)
 
34
        self.assertTrue(tools.simple_file_grep(test_file, content))
 
35
        self.assertEquals(content, fileutil.GetFileContents('/tmp/test_file'))
 
36
        os.remove(test_file)
 
37
 
 
38
    def test_append_file(self):
 
39
        test_file='/tmp/test_file2'
 
40
        content = str(uuid.uuid4())
 
41
        fileutil.AppendFileContents(test_file, content)
 
42
        self.assertTrue(tools.simple_file_grep(test_file, content))
 
43
        os.remove(test_file)
 
44
 
 
45
    def test_replace_file(self):
 
46
        test_file='/tmp/test_file3'
 
47
        contentOld = str(uuid.uuid4())
 
48
        content = str(uuid.uuid4())
 
49
        with open(test_file, "a+") as F:
 
50
            F.write(contentOld)
 
51
        fileutil.ReplaceFileContentsAtomic(test_file, content)
 
52
        self.assertFalse(tools.simple_file_grep(test_file, contentOld))
 
53
        self.assertTrue(tools.simple_file_grep(test_file, content))
 
54
        os.remove(test_file)
 
55
 
 
56
    def test_get_last_path_element(self):
 
57
        filepath = '/tmp/abc.def'
 
58
        filename = fileutil.GetLastPathElement(filepath)
 
59
        self.assertEquals('abc.def', filename)
 
60
 
 
61
        filepath = '/tmp/abc'
 
62
        filename = fileutil.GetLastPathElement(filepath)
 
63
        self.assertEquals('abc', filename)
 
64
 
 
65
if __name__ == '__main__':
 
66
    unittest.main()