/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_push.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-12-18 10:09:49 UTC
  • mfrom: (4871.5.4 admin-guide-submit)
  • Revision ID: pqm@pqm.ubuntu.com-20091218100949-2c1ityvnbqjtdf3g
(nmb) Add backup section to admin-guide

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2007, 2008 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
31
31
    workingtree
32
32
    )
33
33
from bzrlib.repofmt import knitrepo
34
 
from bzrlib.tests import (
35
 
    blackbox,
36
 
    http_server,
37
 
    test_foreign,
38
 
    test_server,
39
 
    )
 
34
from bzrlib.tests import http_server
40
35
from bzrlib.transport import memory
41
36
 
42
37
 
585
580
 
586
581
class RedirectingMemoryServer(memory.MemoryServer):
587
582
 
588
 
    def start_server(self):
 
583
    def setUp(self):
589
584
        self._dirs = {'/': None}
590
585
        self._files = {}
591
586
        self._locks = {}
599
594
        result._locks = self._locks
600
595
        return result
601
596
 
602
 
    def stop_server(self):
 
597
    def tearDown(self):
603
598
        transport.unregister_transport(self._scheme, self._memory_factory)
604
599
 
605
600
 
661
656
    _default_wd = 'local'
662
657
    _default_errors = ['Working tree ".*/local/" has uncommitted '
663
658
                       'changes \(See bzr status\)\.',]
664
 
    _default_additional_error = 'Use --no-strict to force the push.\n'
665
 
    _default_additional_warning = 'Uncommitted changes will not be pushed.'
666
 
 
 
659
    _default_pushed_revid = 'modified'
667
660
 
668
661
    def assertPushFails(self, args):
669
 
        out, err = self.run_bzr_error(self._default_errors,
670
 
                                      self._default_command + args,
671
 
                                      working_dir=self._default_wd, retcode=3)
672
 
        self.assertContainsRe(err, self._default_additional_error)
 
662
        self.run_bzr_error(self._default_errors, self._default_command + args,
 
663
                           working_dir=self._default_wd, retcode=3)
673
664
 
674
 
    def assertPushSucceeds(self, args, with_warning=False, revid_to_push=None):
675
 
        if with_warning:
676
 
            error_regexes = self._default_errors
677
 
        else:
678
 
            error_regexes = []
679
 
        out, err = self.run_bzr(self._default_command + args,
680
 
                                working_dir=self._default_wd,
681
 
                                error_regexes=error_regexes)
682
 
        if with_warning:
683
 
            self.assertContainsRe(err, self._default_additional_warning)
684
 
        else:
685
 
            self.assertNotContainsRe(err, self._default_additional_warning)
686
 
        branch_from = branch.Branch.open(self._default_wd)
687
 
        if revid_to_push is None:
688
 
            revid_to_push = branch_from.last_revision()
689
 
        branch_to = branch.Branch.open('to')
690
 
        repo_to = branch_to.repository
691
 
        self.assertTrue(repo_to.has_revision(revid_to_push))
692
 
        self.assertEqual(revid_to_push, branch_to.last_revision())
 
665
    def assertPushSucceeds(self, args, pushed_revid=None):
 
666
        self.run_bzr(self._default_command + args,
 
667
                     working_dir=self._default_wd)
 
668
        if pushed_revid is None:
 
669
            pushed_revid = self._default_pushed_revid
 
670
        tree_to = workingtree.WorkingTree.open('to')
 
671
        repo_to = tree_to.branch.repository
 
672
        self.assertTrue(repo_to.has_revision(pushed_revid))
 
673
        self.assertEqual(tree_to.branch.last_revision_info()[1], pushed_revid)
693
674
 
694
675
 
695
676
 
756
737
        self._default_wd = 'checkout'
757
738
        self._default_errors = ["Working tree is out of date, please run"
758
739
                                " 'bzr update'\.",]
 
740
        self._default_pushed_revid = 'modified-in-local'
759
741
 
760
742
    def test_push_default(self):
761
 
        self.assertPushSucceeds([], with_warning=True)
 
743
        self.assertPushFails([])
762
744
 
763
745
    def test_push_with_revision(self):
764
 
        self.assertPushSucceeds(['-r', 'revid:added'], revid_to_push='added')
 
746
        self.assertPushSucceeds(['-r', 'revid:added'], pushed_revid='added')
765
747
 
766
748
    def test_push_no_strict(self):
767
749
        self.assertPushSucceeds(['--no-strict'])
775
757
 
776
758
    def test_push_bogus_config_var_ignored(self):
777
759
        self.set_config_push_strict("I don't want you to be strict")
778
 
        self.assertPushSucceeds([], with_warning=True)
 
760
        self.assertPushFails([])
779
761
 
780
762
    def test_push_no_strict_command_line_override_config(self):
781
763
        self.set_config_push_strict('yES')
786
768
        self.set_config_push_strict('oFF')
787
769
        self.assertPushFails(['--strict'])
788
770
        self.assertPushSucceeds([])
789
 
 
790
 
 
791
 
class TestPushForeign(blackbox.ExternalBase):
792
 
 
793
 
    def setUp(self):
794
 
        super(TestPushForeign, self).setUp()
795
 
        test_foreign.register_dummy_foreign_for_test(self)
796
 
 
797
 
    def make_dummy_builder(self, relpath):
798
 
        builder = self.make_branch_builder(
799
 
            relpath, format=test_foreign.DummyForeignVcsDirFormat())
800
 
        builder.build_snapshot('revid', None,
801
 
            [('add', ('', 'TREE_ROOT', 'directory', None)),
802
 
             ('add', ('foo', 'fooid', 'file', 'bar'))])
803
 
        return builder
804
 
 
805
 
    def test_no_roundtripping(self):
806
 
        target_branch = self.make_dummy_builder('dp').get_branch()
807
 
        source_tree = self.make_branch_and_tree("dc")
808
 
        output, error = self.run_bzr("push -d dc dp", retcode=3)
809
 
        self.assertEquals("", output)
810
 
        self.assertEquals(error, "bzr: ERROR: It is not possible to losslessly"
811
 
            " push to dummy. You may want to use dpush instead.\n")