def test_path_limit_addition(self): first = {} second = {'author': {'last_name': 'Doe', 'first_name': 'John'}} p = PathLimit([('author',)]) diffed = list(diff(first, second, path_limit=p)) res = [('add', '', [('author', {'first_name': 'John', 'last_name': 'Doe'})])] assert res == diffed first = {} second = {'author': {'last_name': 'Doe', 'first_name': 'John'}} p = PathLimit([('author',)]) diffed = list(diff(first, second, path_limit=p, expand=True)) res = [('add', '', [('author', {'first_name': 'John', 'last_name': 'Doe'})])] assert res == diffed first = {} second = {'author': {'last_name': 'Doe', 'first_name': 'John'}} p = PathLimit() diffed = list(diff(first, second, path_limit=p, expand=True)) res = [('add', '', [('author', {})]), ('add', 'author', [('first_name', 'John')]), ('add', 'author', [('last_name', 'Doe')])] assert len(diffed) == 3 for patch in res: assert patch in diffed
def test_path_limit_change(self): first = {"author": {"last_name": "Do", "first_name": "John"}} second = {"author": {"last_name": "Doe", "first_name": "John"}} p = PathLimit([("author", )]) diffed = list(diff(first, second, path_limit=p, expand=True)) res = [( "change", ["author"], ({ "first_name": "John", "last_name": "Do" }, { "first_name": "John", "last_name": "Doe" }), )] assert res == diffed first = {"author": {"last_name": "Do", "first_name": "John"}} second = {"author": {"last_name": "Doe", "first_name": "John"}} p = PathLimit() diffed = list(diff(first, second, path_limit=p, expand=True)) res = [("change", "author.last_name", ("Do", "Doe"))] assert res == diffed
def test_pathlimit(self): path_limit = PathLimit([('author', 'name')]) self.assertFalse(path_limit.path_is_limit(('author'))) self.assertTrue(path_limit.path_is_limit(('author', 'name'))) self.assertFalse(path_limit.path_is_limit(('author', 'name', 'foo'))) path_limit = PathLimit([('authors', '*')]) self.assertFalse(path_limit.path_is_limit(('authors'))) self.assertTrue(path_limit.path_is_limit(('authors', 'name'))) self.assertTrue(path_limit.path_is_limit(('authors', 1))) self.assertTrue(path_limit.path_is_limit(('authors', 2))) self.assertFalse(path_limit.path_is_limit(('authors', 'name', 'foo')))
def test_path_limit_deletion(self): first = {'author': {'last_name': 'Doe', 'first_name': 'John'}} second = {} p = PathLimit([('author',)]) diffed = list(diff(first, second, path_limit=p, expand=True)) res = [('remove', '', [('author', {'first_name': 'John', 'last_name': 'Doe'})])] assert res == diffed
def test_path_limit_deletion(self): first = {"author": {"last_name": "Doe", "first_name": "John"}} second = {} p = PathLimit([("author", )]) diffed = list(diff(first, second, path_limit=p, expand=True)) res = [("remove", "", [("author", { "first_name": "John", "last_name": "Doe" })])] assert res == diffed
def test_path_limit_change(self): first = {'author': {'last_name': 'Do', 'first_name': 'John'}} second = {'author': {'last_name': 'Doe', 'first_name': 'John'}} p = PathLimit([('author',)]) diffed = list(diff(first, second, path_limit=p, expand=True)) res = [('change', ['author'], ({'first_name': 'John', 'last_name': 'Do'}, {'first_name': 'John', 'last_name': 'Doe'}))] assert res == diffed first = {'author': {'last_name': 'Do', 'first_name': 'John'}} second = {'author': {'last_name': 'Doe', 'first_name': 'John'}} p = PathLimit() diffed = list(diff(first, second, path_limit=p, expand=True)) res = [('change', 'author.last_name', ('Do', 'Doe'))] assert res == diffed
def test_path_limit_addition(self): first = {} second = {"author": {"last_name": "Doe", "first_name": "John"}} p = PathLimit([("author", )]) diffed = list(diff(first, second, path_limit=p)) res = [("add", "", [("author", { "first_name": "John", "last_name": "Doe" })])] assert res == diffed first = {} second = {"author": {"last_name": "Doe", "first_name": "John"}} p = PathLimit([("author", )]) diffed = list(diff(first, second, path_limit=p, expand=True)) res = [("add", "", [("author", { "first_name": "John", "last_name": "Doe" })])] assert res == diffed first = {} second = {"author": {"last_name": "Doe", "first_name": "John"}} p = PathLimit() diffed = list(diff(first, second, path_limit=p, expand=True)) res = [ ("add", "", [("author", {})]), ("add", "author", [("first_name", "John")]), ("add", "author", [("last_name", "Doe")]), ] assert len(diffed) == 3 for patch in res: assert patch in diffed
def test_pathlimit(self): path_limit = PathLimit([('author', 'name')]) self.assertFalse(path_limit.path_is_limit(('author'))) self.assertTrue(path_limit.path_is_limit(('author', 'name'))) self.assertFalse(path_limit.path_is_limit(('author', 'name', 'foo'))) path_limit = PathLimit([('authors', '*')]) self.assertFalse(path_limit.path_is_limit(('authors'))) self.assertTrue(path_limit.path_is_limit(('authors', 'name'))) self.assertTrue(path_limit.path_is_limit(('authors', 1))) self.assertTrue(path_limit.path_is_limit(('authors', 2))) self.assertFalse(path_limit.path_is_limit(('authors', 'name', 'foo')))