~ralsina/ubuntu-sso-client/fix_801550

« back to all changes in this revision

Viewing changes to ubuntu_sso/utils/tests/test_txsecrets.py

  • Committer: Tarmac
  • Author(s): Rodney Dawes
  • Date: 2011-06-23 18:16:31 UTC
  • mfrom: (721.2.5 new-kr-props)
  • Revision ID: tarmac-20110623181631-uknk1hifagueua0d
Use the new property names for fdo secrets API

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
SAMPLE_CONTENT_TYPE = "text/plain; charset=utf8"
44
44
 
45
45
 
 
46
class InvalidProperty(Exception):
 
47
    """An exception for when invalid properties are passed in."""
 
48
 
 
49
 
46
50
class SampleMiscException(Exception):
47
51
    """An exception that will be turned into a DBus Exception."""
48
52
 
129
133
    unlock_prompts = False
130
134
    item_mock_class = ItemMock
131
135
 
 
136
    item_attrs_property = txsecrets.ITEM_ATTRIBUTES_PROPERTY_OLD
 
137
    item_label_property = txsecrets.ITEM_LABEL_PROPERTY_OLD
 
138
    clxn_label_property = txsecrets.CLXN_LABEL_PROPERTY_OLD
 
139
 
132
140
    def __init__(self, label, *args, **kwargs):
133
141
        """Initialize this instance."""
134
142
        super(BaseCollectionMock, self).__init__(*args, **kwargs)
145
153
            raise SampleMiscException()
146
154
        if self.locked:
147
155
            raise SampleMiscException(ERROR_CREATE_BUT_LOCKED)
148
 
        attributes = properties[txsecrets.ATTRIBUTES_PROPERTY]
149
 
        item_label = properties[txsecrets.LABEL_PROPERTY]
 
156
        attributes = properties[self.item_attrs_property]
 
157
        item_label = properties[self.item_label_property]
150
158
        value = secret[2]
151
159
        item_path = create_object_path(make_coll_path(self.label))
152
160
        item = self.dbus_publish(item_path, self.item_mock_class, self,
165
173
                         in_signature="ss", out_signature="v")
166
174
    def Get(self, interface, propname):
167
175
        """The only property implemented is Label."""
168
 
        if interface == txsecrets.COLLECTION_IFACE and propname == "Label":
 
176
        if interface == txsecrets.COLLECTION_IFACE and \
 
177
                propname == self.clxn_label_property:
169
178
            return dbus.String(self.label)
 
179
        raise InvalidProperty("Invalid property: {}".format(propname))
170
180
 
171
181
 
172
182
class CollectionMock(BaseCollectionMock):
202
212
    dismissed = False
203
213
    collection_mock_class = CollectionMock
204
214
 
 
215
    clxn_label_property = txsecrets.CLXN_LABEL_PROPERTY_OLD
 
216
    collections_property = txsecrets.COLLECTIONS_PROPERTY_OLD
 
217
 
205
218
    def __init__(self, *args, **kwargs):
206
219
        """Initialize this instance."""
207
220
        super(SecretServiceMock, self).__init__(*args, **kwargs)
226
239
        """Create a new collection with the specified properties."""
227
240
        if self.create_collection_fail:
228
241
            raise SampleMiscException()
229
 
        label = str(properties[txsecrets.LABEL_PROPERTY])
 
242
        label = str(properties[self.clxn_label_property])
230
243
        coll_path = make_coll_path(label)
231
244
        collection = self.dbus_publish(coll_path, self.collection_mock_class,
232
245
                                       label)
313
326
                         in_signature="ss", out_signature="v")
314
327
    def Get(self, interface, propname):
315
328
        """The only property implemented is Collections."""
316
 
        if interface == txsecrets.SERVICE_IFACE and propname == "Collections":
 
329
        if interface == txsecrets.SERVICE_IFACE and \
 
330
                propname == self.collections_property:
317
331
            coll_paths = [make_coll_path(l) for l in self.collections]
318
332
            return dbus.Array(coll_paths, signature="o", variant_level=1)
 
333
        raise InvalidProperty("Invalid property: {}".format(propname))
319
334
 
320
335
 
321
336
class AltItemMock(ItemMock):
335
350
 
336
351
    item_mock_class = AltItemMock
337
352
 
 
353
    item_attrs_property = txsecrets.ITEM_ATTRIBUTES_PROPERTY
 
354
    item_label_property = txsecrets.ITEM_LABEL_PROPERTY
 
355
    clxn_label_property = txsecrets.CLXN_LABEL_PROPERTY
 
356
 
338
357
    @dbus.service.method(dbus_interface=txsecrets.COLLECTION_IFACE,
339
358
                         in_signature="a{sv}(oayays)b", out_signature="oo",
340
359
                         byte_arrays=True)
349
368
 
350
369
    collection_mock_class = AltCollectionMock
351
370
 
 
371
    clxn_label_property = txsecrets.CLXN_LABEL_PROPERTY
 
372
    collections_property = txsecrets.COLLECTIONS_PROPERTY
 
373
 
352
374
 
353
375
def create_object_path(base):
354
376
    """Create a random object path given a base path."""