def execute_if_complete(pending_request): if pending_request.pendingverification_set.count(): return False serializer = UpdateRequestSerializer(data=pending_request.request) serializer.is_valid(True) request = serializer.save() request.execute() pending_request.delete() return True
def test_invalid_field(simple_identity): request = { 'identity': simple_identity, 'items': [ make_update_item('emailx', '*****@*****.**'), ] } serializer = UpdateRequestSerializer(data=request) assert not serializer.is_valid()
def test_similar_items(simple_identity): request = { 'identity': simple_identity, 'items': [ make_update_item('email', '*****@*****.**'), make_update_item('email', '*****@*****.**', action='delete') ] } serializer = UpdateRequestSerializer(data=request) assert serializer.is_valid(), serializer.errors
def test_plural_items(simple_identity): request = { 'identity': simple_identity, 'items': [ make_update_item('email', '*****@*****.**'), make_update_item('email', '*****@*****.**'), ] } serializer = UpdateRequestSerializer(data=request) assert not serializer.is_valid() assert 'Duplicate field/action is not allowed: create, email' in serializer.errors['items']
def test_identical_items(simple_identity): request = { 'identity': simple_identity, 'items': [ make_update_item('email', '*****@*****.**'), make_update_item('email', '*****@*****.**') ] } serializer = UpdateRequestSerializer(data=request) assert not serializer.is_valid() assert 'Duplicate update items are not allowed.' in serializer.errors['items']
def test_single_item(simple_identity): request = { 'identity': simple_identity, 'items': [make_update_item('email', '*****@*****.**')] } serializer = UpdateRequestSerializer(data=request) assert serializer.is_valid(), serializer.errors update_request = serializer.save() assert len(update_request.items) == 1 identity = update_request.identity assert identity.public_key == simple_identity['public_key'] assert identity.drop_url == simple_identity['drop_url'] assert identity.alias == simple_identity['alias'] item = update_request.items[0] assert item.action == 'create' assert item.field == 'email' assert item.value == '*****@*****.**'
def test_invalid_request(invalid): serializer = UpdateRequestSerializer(data=invalid) assert not serializer.is_valid()