~vila/brz-byov/trunk

« back to all changes in this revision

Viewing changes to tests/test_commands.py

  • Committer: Vincent Ladeuil
  • Date: 2016-07-21 11:00:44 UTC
  • mfrom: (6.1.10 push-pull-tree)
  • Revision ID: v.ladeuil+lp@free.fr-20160721110044-nh5zwgf7p7udrjdo
Merge the push-tree command implementation and tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2016 Canonical Ltd
 
2
#
 
3
# This software is licensed under the GNU General Public License version 3 (see
 
4
# the file LICENSE).
 
5
"""Tests for the olsvms plugin commands."""
 
6
import os
 
7
 
 
8
from bzrlib import (
 
9
    bzrdir,
 
10
    tests,
 
11
)
 
12
 
 
13
from bzrlib.plugins.olsvms import (
 
14
    ols_vms,
 
15
)
 
16
from bzrlib.plugins.olsvms.tests import (
 
17
    features,
 
18
    fixtures,
 
19
)
 
20
 
 
21
 
 
22
class TestPushTree(tests.TestCaseWithTransport):
 
23
 
 
24
    def setUp(self):
 
25
        vm = features.VmFeature()
 
26
        self.requireFeature(vm)
 
27
        outter_home = os.environ['HOME']
 
28
        super(TestPushTree, self).setUp()
 
29
        fixtures.import_vm(self, outter_home)
 
30
        self.vm_name = vm.vm_name
 
31
        self.permit_url('olsvms://{}/'.format(self.vm_name))
 
32
        # Use a unique name for the remote dir to isolate tests from each other
 
33
        # and allow them to run concurrently.
 
34
        self.remote_dir = '~/test-{}'.format(os.getpid())
 
35
 
 
36
    def create_basis_tree(self):
 
37
        tree = self.make_branch_and_tree('.')
 
38
        self.build_tree(['file'])
 
39
        tree.add('file')
 
40
        tree.commit('commit 1')
 
41
        return tree
 
42
 
 
43
    def cleanup_remote(self, path):
 
44
        ols_vms.run(['shell', self.vm_name, 'rm', '-fr', path])
 
45
 
 
46
    def get_remote_branch(self, location):
 
47
        octob = bzrdir.BzrDir.open_containing_tree_or_branch
 
48
        return octob(location)[1]
 
49
 
 
50
    def test_push_no_changes(self):
 
51
        # Use an absolute path
 
52
        self.remote_dir = '/home/ubuntu/test-{}'.format(os.getpid())
 
53
        tree = self.create_basis_tree()
 
54
        self.addCleanup(self.cleanup_remote, self.remote_dir)
 
55
        location = 'olsvms://{}/{}'.format(self.vm_name, self.remote_dir)
 
56
        out, err = self.run_bzr(['push-tree', location])
 
57
        self.assertEqual(1, tree.branch.revno())
 
58
        remote_branch = self.get_remote_branch(location)
 
59
        self.assertEqual(1, remote_branch.revno())
 
60
 
 
61
    def test_push_simple_branch_with_change(self):
 
62
        tree = self.create_basis_tree()
 
63
        self.build_tree(['file2'])
 
64
        tree.add('file2')
 
65
        self.addCleanup(self.cleanup_remote, self.remote_dir)
 
66
        location = 'olsvms://{}/{}'.format(self.vm_name, self.remote_dir)
 
67
        out, err = self.run_bzr(['push-tree', location])
 
68
        self.assertEqual(1, tree.branch.revno())
 
69
        remote_branch = self.get_remote_branch(location)
 
70
        # The remote branch keeps the commit
 
71
        self.assertEqual(2, remote_branch.revno())
 
72
        self.assertTrue(remote_branch.user_transport.has('file2'))
 
73
        self.assertEqual('contents of file2\n',
 
74
                         remote_branch.user_transport.get('file2').read())
 
75
 
 
76
    def test_push_twice_with_different_changes(self):
 
77
        tree = self.create_basis_tree()
 
78
        self.build_tree(['file2'])
 
79
        tree.add('file2')
 
80
        self.addCleanup(self.cleanup_remote, self.remote_dir)
 
81
        location = 'olsvms://{}/{}'.format(self.vm_name, self.remote_dir)
 
82
        out, err = self.run_bzr(['push-tree', location])
 
83
        self.assertEqual(1, tree.branch.revno())
 
84
        with open('file2', 'w') as f:
 
85
            f.write('different content for file2\n')
 
86
        location = 'olsvms://{}/{}'.format(self.vm_name, self.remote_dir)
 
87
        out, err = self.run_bzr(['push-tree', location])
 
88
        self.assertEqual(1, tree.branch.revno())
 
89
 
 
90
    def test_push_without_parent_dir(self):
 
91
        # Cleanup the whole dir
 
92
        self.addCleanup(self.cleanup_remote, self.remote_dir)
 
93
        subdir = '~/test-{}/there'.format(os.getpid())
 
94
        tree = self.create_basis_tree()
 
95
        location = 'olsvms://{}/{}'.format(self.vm_name, subdir)
 
96
        out, err = self.run_bzr(['push-tree', location])
 
97
        self.assertEqual(1, tree.branch.revno())
 
98
        remote_branch = self.get_remote_branch(location)
 
99
        self.assertEqual(1, remote_branch.revno())