~gtg-user/gtg/pep8

« back to all changes in this revision

Viewing changes to GTG/tests/test_syncengine.py

  • Committer: nimit.svnit at gmail
  • Date: 2013-01-27 07:28:10 UTC
  • Revision ID: nimit.svnit@gmail.com-20130127072810-0o6reyi6xd9mjmsn
PEP8ification of the codebase

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    def test_analyze_element_and_record_and_break_relationship(self):
37
37
        """ Test for the _analyze_element, analyze_remote_id, analyze_local_id,
38
38
        record_relationship, break_relationship """
39
 
        #adding a new local task
 
39
        # adding a new local task
 
40
        has_local_task = self.ftp_local.has_task
 
41
        has_remote_task = self.ftp_remote.has_task
40
42
        local_id = uuid.uuid4()
41
43
        self.ftp_local.fake_add_task(local_id)
42
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
43
 
                       self.ftp_local.has_task, self.ftp_remote.has_task), \
 
44
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
45
                                                           has_local_task,
 
46
                                                           has_remote_task),
44
47
                         (SyncEngine.ADD, None))
45
 
        #creating the related remote task
 
48
        # creating the related remote task
46
49
        remote_id = uuid.uuid4()
47
50
        self.ftp_remote.fake_add_task(remote_id)
48
 
        #informing the sync_engine about that
 
51
        # informing the sync_engine about that
49
52
        self.sync_engine.record_relationship(local_id, remote_id, object())
50
 
        #verifying that it understood that
51
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
52
 
                       self.ftp_local.has_task, self.ftp_remote.has_task), \
 
53
        # verifying that it understood that
 
54
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
55
                                                           has_local_task,
 
56
                                                           has_remote_task),
53
57
                         (SyncEngine.UPDATE, remote_id))
54
 
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id, \
55
 
                       self.ftp_local.has_task, self.ftp_remote.has_task), \
 
58
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
 
59
                                                            has_local_task,
 
60
                                                            has_remote_task),
56
61
                         (SyncEngine.UPDATE, local_id))
57
 
        #and not the reverse
58
 
        self.assertEqual(self.sync_engine.analyze_remote_id(local_id, \
59
 
                       self.ftp_local.has_task, self.ftp_remote.has_task), \
60
 
                         (SyncEngine.ADD, None))
61
 
        self.assertEqual(self.sync_engine.analyze_local_id(remote_id, \
62
 
                       self.ftp_local.has_task, self.ftp_remote.has_task), \
63
 
                         (SyncEngine.ADD, None))
64
 
        #now we remove the remote task
 
62
        # and not the reverse
 
63
        self.assertEqual(self.sync_engine.analyze_remote_id(local_id,
 
64
                                                            has_local_task,
 
65
                                                            has_remote_task),
 
66
                         (SyncEngine.ADD, None))
 
67
        self.assertEqual(self.sync_engine.analyze_local_id(remote_id,
 
68
                                                           has_local_task,
 
69
                                                           has_remote_task),
 
70
                         (SyncEngine.ADD, None))
 
71
        # now we remove the remote task
65
72
        self.ftp_remote.fake_remove_task(remote_id)
66
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
67
 
                       self.ftp_local.has_task, self.ftp_remote.has_task), \
 
73
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
74
                                                           has_local_task,
 
75
                                                           has_remote_task),
68
76
                         (SyncEngine.REMOVE, None))
69
 
        self.sync_engine.break_relationship(local_id = local_id)
70
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
71
 
                       self.ftp_local.has_task, self.ftp_remote.has_task), \
 
77
        self.sync_engine.break_relationship(local_id=local_id)
 
78
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
79
                                                           has_local_task,
 
80
                                                           has_remote_task),
72
81
                         (SyncEngine.ADD, None))
73
 
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id, \
74
 
                       self.ftp_local.has_task, self.ftp_remote.has_task), \
 
82
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
 
83
                                                            has_local_task,
 
84
                                                            has_remote_task),
75
85
                         (SyncEngine.ADD, None))
76
86
        # we add them back and remove giving the remote id as key to find
77
87
        # what to delete
79
89
        self.ftp_remote.fake_add_task(remote_id)
80
90
        self.ftp_remote.fake_remove_task(remote_id)
81
91
        self.sync_engine.record_relationship(local_id, remote_id, object)
82
 
        self.sync_engine.break_relationship(remote_id = remote_id)
83
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
84
 
                       self.ftp_local.has_task, self.ftp_remote.has_task), \
 
92
        self.sync_engine.break_relationship(remote_id=remote_id)
 
93
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
94
                                                           has_local_task,
 
95
                                                           has_remote_task),
85
96
                         (SyncEngine.ADD, None))
86
 
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id, \
87
 
                       self.ftp_local.has_task, self.ftp_remote.has_task), \
 
97
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
 
98
                                                            has_local_task,
 
99
                                                            has_remote_task),
88
100
                         (SyncEngine.ADD, None))
89
101
 
90
102
    def test_syncability(self):
91
103
        """ Test for the _analyze_element, analyze_remote_id, analyze_local_id.
92
104
        Checks that the is_syncable parameter is used correctly """
93
 
        #adding a new local task unsyncable
 
105
        # adding a new local task unsyncable
 
106
        has_local_task = self.ftp_local.has_task
 
107
        has_remote_task = self.ftp_remote.has_task
94
108
        local_id = uuid.uuid4()
95
109
        self.ftp_local.fake_add_task(local_id)
96
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
97
 
                       self.ftp_local.has_task, self.ftp_remote.has_task,
98
 
                                                           False), \
 
110
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
111
                                                           has_local_task,
 
112
                                                           has_remote_task,
 
113
                                                           False),
99
114
                         (None, None))
100
 
        #adding a new local task, syncable
 
115
        # adding a new local task, syncable
101
116
        local_id = uuid.uuid4()
102
117
        self.ftp_local.fake_add_task(local_id)
103
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
104
 
                       self.ftp_local.has_task, self.ftp_remote.has_task), \
 
118
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
119
                                                           has_local_task,
 
120
                                                           has_remote_task),
105
121
                         (SyncEngine.ADD, None))
106
 
        #creating the related remote task
 
122
        # creating the related remote task
107
123
        remote_id = uuid.uuid4()
108
124
        self.ftp_remote.fake_add_task(remote_id)
109
 
        #informing the sync_engine about that
 
125
        # informing the sync_engine about that
110
126
        self.sync_engine.record_relationship(local_id, remote_id, object())
111
 
        #checking that it behaves correctly with established relationships
112
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
113
 
                       self.ftp_local.has_task, self.ftp_remote.has_task,
114
 
                                                          True), \
 
127
        # checking that it behaves correctly with established relationships
 
128
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
129
                                                           has_local_task,
 
130
                                                           has_remote_task,
 
131
                                                           True),
115
132
                         (SyncEngine.UPDATE, remote_id))
116
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
117
 
                       self.ftp_local.has_task, self.ftp_remote.has_task,
118
 
                                                          False), \
 
133
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
134
                                                           has_local_task,
 
135
                                                           has_remote_task,
 
136
                                                           False),
119
137
                         (SyncEngine.LOST_SYNCABILITY, remote_id))
120
 
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id, \
121
 
                       self.ftp_local.has_task, self.ftp_remote.has_task,
122
 
                                                           True), \
 
138
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
 
139
                                                            has_local_task,
 
140
                                                            has_remote_task,
 
141
                                                            True),
123
142
                         (SyncEngine.UPDATE, local_id))
124
 
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id, \
125
 
                       self.ftp_local.has_task, self.ftp_remote.has_task,
126
 
                                                           False), \
 
143
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
 
144
                                                            has_local_task,
 
145
                                                            has_remote_task,
 
146
                                                            False),
127
147
                         (SyncEngine.LOST_SYNCABILITY, local_id))
128
 
        #now we remove the remote task
 
148
        # now we remove the remote task
129
149
        self.ftp_remote.fake_remove_task(remote_id)
130
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
131
 
                       self.ftp_local.has_task, self.ftp_remote.has_task,
132
 
                                                          True), \
133
 
                         (SyncEngine.REMOVE, None))
134
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
135
 
                       self.ftp_local.has_task, self.ftp_remote.has_task,
136
 
                                                          False), \
137
 
                         (SyncEngine.REMOVE, None))
138
 
        self.sync_engine.break_relationship(local_id = local_id)
139
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
140
 
                       self.ftp_local.has_task, self.ftp_remote.has_task,
141
 
                                                          True), \
 
150
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
151
                                                           has_local_task,
 
152
                                                           has_remote_task,
 
153
                                                           True),
 
154
                         (SyncEngine.REMOVE, None))
 
155
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
156
                                                           has_local_task,
 
157
                                                           has_remote_task,
 
158
                                                           False),
 
159
                         (SyncEngine.REMOVE, None))
 
160
        self.sync_engine.break_relationship(local_id=local_id)
 
161
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
162
                                                           has_local_task,
 
163
                                                           has_remote_task,
 
164
                                                           True),
142
165
                         (SyncEngine.ADD, None))
143
 
        self.assertEqual(self.sync_engine.analyze_local_id(local_id, \
144
 
                       self.ftp_local.has_task, self.ftp_remote.has_task,
145
 
                                                          False), \
 
166
        self.assertEqual(self.sync_engine.analyze_local_id(local_id,
 
167
                                                           has_local_task,
 
168
                                                           has_remote_task,
 
169
                                                           False),
146
170
                         (None, None))
147
 
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id, \
148
 
                       self.ftp_local.has_task, self.ftp_remote.has_task,
149
 
                                                           True), \
 
171
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
 
172
                                                            has_local_task,
 
173
                                                            has_remote_task,
 
174
                                                            True),
150
175
                         (SyncEngine.ADD, None))
151
 
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id, \
152
 
                       self.ftp_local.has_task, self.ftp_remote.has_task,
153
 
                                                           False), \
 
176
        self.assertEqual(self.sync_engine.analyze_remote_id(remote_id,
 
177
                                                            has_local_task,
 
178
                                                            has_remote_task,
 
179
                                                            False),
154
180
                         (None, None))
155
181
 
156
182
 
166
192
    def has_task(self, tid):
167
193
        return tid in self.dic
168
194
 
169
 
###############################################################################
 
195
##############################################################################
170
196
### Function with the fake_ prefix are here to assist in testing, they do not
171
197
### need to be present in the real class
172
 
###############################################################################
 
198
##############################################################################
173
199
    def fake_add_task(self, tid):
174
200
        self.dic[tid] = "something"
175
201