Ejemplo n.º 1
0
 def _changes():
     changes = Changes()
     changes.deleted['deleted'] = Resource(None, 'old_content')
     changes.deleted['renamed'] = Resource(
         SimpleCell('usr/block/renamed'),
         Content(ID((1234, )), load=Blob('old_content2')))
     changes.created['created'] = Resource(
         SimpleCell('usr/block/created'),
         Content(id_=None, load=Blob('created')))
     changes.created['renamed2'] = Resource(
         SimpleCell('usr/block/renamed2'),
         Content(id_=None, load=Blob('old_content2')))
     changes.modified['modified_cont'] = Modification(
         Resource(SimpleCell('usr/block/modified_cont'),
                  Content(id_=None, load=Blob('mod_content'))),
         Resource(SimpleCell('usr/block/modified_cont'),
                  Content(id_=None, load=Blob('mod_content2'))))
     changes.modified['modified_cell'] = Modification(
         Resource(SimpleCell('usr/block/modified_cell'),
                  Content(id_=None, load=Blob('mod_cell'))),
         Resource(SimpleCell('usr/block/modified_cell', CPP),
                  Content(id_=None, load=Blob('mod_cell'))))
     changes.modified['modified_both'] = Modification(
         Resource(SimpleCell('usr/block/modified_both'),
                  Content(id_=None, load='mod_both')),
         Resource(SimpleCell('usr/block/modified_both', CPP),
                  Content(id_=None, load=Blob('mod_both2'))))
     changes.renames = Renames({'renamed': 'renamed2'})
     return changes
 def _changes():
     changes = Changes()
     changes.deleted['deleted'] = Resource(None, 'old_content')
     changes.deleted['renamed'] = Resource(SimpleCell('usr/block/renamed'),
                                           Content(ID((1234,)), load=Blob('old_content2')))
     changes.created['created'] = Resource(SimpleCell('usr/block/created'),
                                           Content(id_=None, load=Blob('created')))
     changes.created['renamed2'] = Resource(SimpleCell('usr/block/renamed2'),
                                            Content(id_=None, load=Blob('old_content2')))
     changes.modified['modified_cont'] = Modification(
                                                 Resource(SimpleCell('usr/block/modified_cont'),
                                                          Content(id_=None, load=Blob('mod_content'))),
                                                 Resource(SimpleCell('usr/block/modified_cont'),
                                                          Content(id_=None, load=Blob('mod_content2'))))
     changes.modified['modified_cell'] = Modification(
                                                 Resource(SimpleCell('usr/block/modified_cell'),
                                                          Content(id_=None, load=Blob('mod_cell'))),
                                                 Resource(SimpleCell('usr/block/modified_cell',
                                                                     CPP),
                                                          Content(id_=None, load=Blob('mod_cell'))))
     changes.modified['modified_both'] = Modification(
                                                 Resource(SimpleCell('usr/block/modified_both'),
                                                          Content(id_=None, load='mod_both')),
                                                 Resource(SimpleCell('usr/block/modified_both',
                                                                     CPP),
                                                          Content(id_=None, load=Blob('mod_both2'))))
     changes.renames = Renames({'renamed': 'renamed2'})
     return changes
Ejemplo n.º 3
0
 def test_nonzero_one_file_content(self):
     changes = Changes()
     changes.modified['modified_cont'] = Modification(
         Resource(SimpleCell('usr/block/pretty.js'),
                  Content(id_=None, load=Blob('mod_content'))),
         Resource(SimpleCell('usr/block/pretty.js'),
                  Content(id_=None, load=Blob('mod_content2'))))
     p = PublishRequest(BlockVersion.loads('usr/block: 3'))
     p.msg = "Test Msg"
     p.changes = changes
     self.assertTrue(bool(p))
 def test_nonzero_one_file_content(self):
     changes = Changes()
     changes.modified['modified_cont'] = Modification(
                                                 Resource(SimpleCell('usr/block/pretty.js'),
                                                          Content(id_=None, load=Blob('mod_content'))),
                                                 Resource(SimpleCell('usr/block/pretty.js'),
                                                          Content(id_=None, load=Blob('mod_content2'))))
     p = PublishRequest(BlockVersion.loads('usr/block: 3'))
     p.msg = "Test Msg"
     p.changes = changes
     self.assertTrue(bool(p))
Ejemplo n.º 5
0
def compare(base_resources, other_resources):
    """Generic compare items and return a Changes object.
    base_resources and other_resources can be any dict {ID: Value}"""

    changes = Changes()
    if base_resources is None:
        base_resources = {}

    # Check for deleted & modified, when modified keeps other
    for key, value in base_resources.iteritems():
        other_value = other_resources.get(key)
        if other_value is None:
            changes.deleted[key] = value
        elif other_value != value:
            changes.modified[key] = Modification(value, other_value)

    # check for created
    for key, value in other_resources.iteritems():
        if key not in base_resources:
            changes.created[key] = value

    return changes
Ejemplo n.º 6
0
def compare(base_resources, other_resources):
    """Generic compare items and return a Changes object.
    base_resources and other_resources can be any dict {ID: Value}"""

    changes = Changes()
    if base_resources is None:
        base_resources = {}

    # Check for deleted & modified, when modified keeps other
    for key, value in base_resources.iteritems():
        other_value = other_resources.get(key)
        if other_value is None:
            changes.deleted[key] = value
        elif other_value != value:
            changes.modified[key] = Modification(value, other_value)

    # check for created
    for key, value in other_resources.iteritems():
        if key not in base_resources:
            changes.created[key] = value

    return changes