~ubuntu-branches/ubuntu/precise/desktopcouch/precise

« back to all changes in this revision

Viewing changes to desktopcouch/pair/tests/test_ubuntuone_pairing.py

  • Committer: Bazaar Package Importer
  • Author(s): Ken VanDine
  • Date: 2010-04-19 12:52:22 UTC
  • mfrom: (12.1.9 lucid)
  • Revision ID: james.westby@ubuntu.com-20100419125222-zsh9lrm15h84951j
* debian/patches/lp_522538.patch
  - Handle reconnects if the server isn't running (LP: #522538)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2010 Canonical Ltd.
2
 
#
3
 
# This file is part of desktopcouch.
4
 
#
5
 
# desktopcouch is free software: you can redistribute it and/or modify
6
 
# it under the terms of the GNU Lesser General Public License version 3
7
 
# as published by the Free Software Foundation.
8
 
#
9
 
# desktopcouch is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU Lesser General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU Lesser General Public License
15
 
# along with desktopcouch.  If not, see <http://www.gnu.org/licenses/>.
16
 
#
17
 
# Authors: Manuel de la pena <manuel.delapena@canonical.com>
18
 
import testtools
19
 
from mocker import Mocker
20
 
 
21
 
import desktopcouch.tests as test_environment
22
 
from desktopcouch.pair.couchdb_pairing.ubuntuone_pairing import (
23
 
    pair_with_ubuntuone, U1_PAIR_RECORD, MAP_JS)
24
 
 
25
 
class TestUbuntonePairing(testtools.TestCase):
26
 
 
27
 
    def setUp(self):
28
 
        """setup each test"""
29
 
        super(TestUbuntonePairing, self).setUp()
30
 
        # set a number of mocks that are used in all tests
31
 
        self.mocker = Mocker()
32
 
        self.couchdb = self.mocker.mock()
33
 
        self.put_static_paired_service = self.mocker.replace(
34
 
            'desktopcouch.pair.couchdb_pairing.couchdb_io.' + 
35
 
            'put_static_paired_service')
36
 
        
37
 
    def test_pair_with_ubuntuone_no_view(self):
38
 
        """Tests that when the view is not present it is indeed created."""
39
 
        self.couchdb.view_exists(U1_PAIR_RECORD, U1_PAIR_RECORD)
40
 
        self.mocker.result(False)
41
 
        # we are interested in the fact that the view is created
42
 
        self.couchdb.add_view(U1_PAIR_RECORD, MAP_JS, None, U1_PAIR_RECORD)
43
 
        # added to esure that the method carries on normally
44
 
        self.couchdb.execute_view(U1_PAIR_RECORD, U1_PAIR_RECORD)
45
 
        self.mocker.result([])
46
 
        self.put_static_paired_service(None, "ubuntuone")
47
 
        self.mocker.replay()
48
 
        pair_with_ubuntuone(self.couchdb)
49
 
        self.mocker.verify()
50
 
        
51
 
 
52
 
    def test_pair_with_ubuntuone_no_record(self):
53
 
        """Ensure pairing is not done when there are no records ."""
54
 
        # execute the steps when no records are returned by the view
55
 
        self.couchdb.view_exists(U1_PAIR_RECORD, U1_PAIR_RECORD)
56
 
        self.mocker.result(True)
57
 
        self.couchdb.execute_view(U1_PAIR_RECORD, U1_PAIR_RECORD)
58
 
        self.mocker.result([])
59
 
        self.put_static_paired_service(None, "ubuntuone")
60
 
        self.mocker.replay()
61
 
        pair_with_ubuntuone(self.couchdb)
62
 
        self.mocker.verify()
63
 
 
64
 
    def test_pair_with_ubuntuone_user_deleted_record(self):
65
 
        """Ensure pairing is not done when the user explicitly removed it."""
66
 
        # create a mock object that will be the result from the view
67
 
        row = self.mocker.mock()
68
 
        # execute the steps to show that the user deleted the record
69
 
        self.couchdb.view_exists(U1_PAIR_RECORD, U1_PAIR_RECORD)
70
 
        self.mocker.result(True)
71
 
        self.couchdb.execute_view(U1_PAIR_RECORD, U1_PAIR_RECORD)
72
 
        self.mocker.result([row])
73
 
        row.value
74
 
        self.mocker.result(1)
75
 
        self.mocker.replay()
76
 
        pair_with_ubuntuone(self.couchdb)
77
 
        self.mocker.verify()
78
 
 
79
 
    def test_pair_with_ubuntuone_record_present(self):
80
 
        """Ensure pairing is not done when the record is already present."""
81
 
        # create a mock object that will be the result from the view
82
 
        row = self.mocker.mock()
83
 
        # execute the steps to show that the user deleted the record
84
 
        self.couchdb.view_exists(U1_PAIR_RECORD, U1_PAIR_RECORD)
85
 
        self.mocker.result(True)
86
 
        self.couchdb.execute_view(U1_PAIR_RECORD, U1_PAIR_RECORD)
87
 
        self.mocker.result([row])
88
 
        row.value
89
 
        self.mocker.result(0)
90
 
        self.mocker.replay()
91
 
        pair_with_ubuntuone(self.couchdb)
92
 
        self.mocker.verify()