'Test user permissions are automatically applied when a user permission
is created'

def test_automatic_apply_user_permissions(self):

    frappe.get_doc(dict(doctype=u'User', email=u'test_user_perm@example.com', first_name=u'tester')).insert(ignore_if_duplicate=True)
    frappe.get_doc(dict(doctype=u'Role', role_name=u'Test    Role    User    Perm')).insert(ignore_if_duplicate=True)
    add_permission(u'DocType', u'Test    Role    User    Perm')
    frappe.get_doc(u'User', u'test_user_perm@example.com').add_roles(u'Test    Role    User    Perm')
    add_user_permission(u'Module    Def', u'Core', u'test_user_perm@example.com', True)
    _perm = None
    for perm in get_valid_perms(u'DocType', u'test_user_perm@example.com'):
        if (perm.role == u'Test    Role    User    Perm'):
            _perm = perm
    self.assertEqual(_perm.apply_user_permissions, 1)
    self.assertTrue((u'Module    Def' in json.loads(_perm.user_permission_doctypes)))
