~bertrand-rousseau/gtg/new-task-list-layout

« back to all changes in this revision

Viewing changes to GTG/tests/test_syncengine.py

  • Committer: Bertrand Rousseau
  • Date: 2012-07-13 17:24:28 UTC
  • mfrom: (1178.1.28 trunk)
  • mto: (1178.1.30 trunk)
  • mto: This revision was merged to the branch mainline in revision 1183.
  • Revision ID: bertrand.rousseau@gmail.com-20120713172428-ou3ic646fccov41d
Merge with trunk. Fixes conflict with CHANGELOG.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# this program.  If not, see <http://www.gnu.org/licenses/>.
18
18
# -----------------------------------------------------------------------------
19
19
 
20
 
'''
21
 
Tests for the SyncEngine class
22
 
'''
 
20
""" Tests for the SyncEngine class """
23
21
 
24
22
import unittest
25
23
import uuid
27
25
from GTG.backends.syncengine import SyncEngine
28
26
 
29
27
 
30
 
 
31
28
class TestSyncEngine(unittest.TestCase):
32
 
    '''
33
 
    Tests for the SyncEngine object.
34
 
    '''
35
 
    
 
29
    """ Tests for the SyncEngine object. """
 
30
 
36
31
    def setUp(self):
37
32
        self.ftp_local = FakeTaskProvider()
38
33
        self.ftp_remote = FakeTaskProvider()
39
34
        self.sync_engine = SyncEngine()
40
 
    
 
35
 
41
36
    def test_analyze_element_and_record_and_break_relationship(self):
42
 
        '''
43
 
        Test for the _analyze_element, analyze_remote_id, analyze_local_id,
44
 
        record_relationship, break_relationship
45
 
        '''
 
37
        """ Test for the _analyze_element, analyze_remote_id, analyze_local_id,
 
38
        record_relationship, break_relationship """
46
39
        #adding a new local task
47
40
        local_id = uuid.uuid4()
48
41
        self.ftp_local.fake_add_task(local_id)
80
73
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id, \
81
74
                       self.ftp_local.has_task, self.ftp_remote.has_task), \
82
75
                         (SyncEngine.ADD, None))
83
 
        #we add them back and remove giving the remote id as key to find what to
84
 
        #delete
 
76
        # we add them back and remove giving the remote id as key to find
 
77
        # what to delete
85
78
        self.ftp_local.fake_add_task(local_id)
86
79
        self.ftp_remote.fake_add_task(remote_id)
87
80
        self.ftp_remote.fake_remove_task(remote_id)
95
88
                         (SyncEngine.ADD, None))
96
89
 
97
90
    def test_syncability(self):
98
 
        '''
99
 
        Test for the _analyze_element, analyze_remote_id, analyze_local_id.
100
 
        Checks that the is_syncable parameter is used correctly
101
 
        '''
 
91
        """ Test for the _analyze_element, analyze_remote_id, analyze_local_id.
 
92
        Checks that the is_syncable parameter is used correctly """
102
93
        #adding a new local task unsyncable
103
94
        local_id = uuid.uuid4()
104
95
        self.ftp_local.fake_add_task(local_id)
137
128
        #now we remove the remote task
138
129
        self.ftp_remote.fake_remove_task(remote_id)
139
130
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
140
 
                       self.ftp_local.has_task, self.ftp_remote.has_task, 
 
131
                       self.ftp_local.has_task, self.ftp_remote.has_task,
141
132
                                                          True), \
142
133
                         (SyncEngine.REMOVE, None))
143
134
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
144
 
                       self.ftp_local.has_task, self.ftp_remote.has_task, 
 
135
                       self.ftp_local.has_task, self.ftp_remote.has_task,
145
136
                                                          False), \
146
137
                         (SyncEngine.REMOVE, None))
147
138
        self.sync_engine.break_relationship(local_id = local_id)
162
153
                                                           False), \
163
154
                         (None, None))
164
155
 
 
156
 
165
157
def test_suite():
166
158
    return unittest.TestLoader().loadTestsFromTestCase(TestSyncEngine)
167
159
 
172
164
        self.dic = {}
173
165
 
174
166
    def has_task(self, tid):
175
 
        return self.dic.has_key(tid)
 
167
        return tid in self.dic
176
168
 
177
169
###############################################################################
178
170
### Function with the fake_ prefix are here to assist in testing, they do not
179
171
### need to be present in the real class
180
172
###############################################################################
181
 
 
182
173
    def fake_add_task(self, tid):
183
174
        self.dic[tid] = "something"
184
175