當前位置: 首頁>>代碼示例>>Python>>正文


Python Document.set_default_user方法代碼示例

本文整理匯總了Python中models.Document.set_default_user方法的典型用法代碼示例。如果您正苦於以下問題:Python Document.set_default_user方法的具體用法?Python Document.set_default_user怎麽用?Python Document.set_default_user使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在models.Document的用法示例。


在下文中一共展示了Document.set_default_user方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: DocumentsViewsTest

# 需要導入模塊: from models import Document [as 別名]
# 或者: from models.Document import set_default_user [as 別名]
class DocumentsViewsTest(TestCase):
    username = "test"
    password = "password"

    def setUp(self):
        self.group, created = Group.objects.get_or_create(name='test')
        self.user, created = DjangoUser.objects.get_or_create(username=self.username)
        self.user.set_password(self.password)
        self.user.save()
        perspective, created = Perspective.objects.get_or_create(
            name='default')
        perspective.set_default_user()
        perspective.save()

        ModuleSetting.set('default_perspective', perspective.id)

        self.folder = Folder(name='test')
        self.folder.set_default_user()
        self.folder.save()

        self.document = Document(title='test_document', folder=self.folder)
        self.document.set_default_user()
        self.document.save()

        self.file = File(name='test_file', folder=self.folder)
        self.file.set_default_user()
        self.file.save()

        self.link = WebLink(title='test', folder=self.folder, url='test')
        self.link.set_default_user()
        self.link.save()

    ######################################
    # Testing views when user is logged in
    ######################################
    def test_index_login(self):
        "Test index page with login at /documents/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('document_index'))
        self.assertEquals(response.status_code, 200)

    def test_index_documents_login(self):
        "Test index page with login at /documents/documents/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('index_documents'))
        self.assertEquals(response.status_code, 200)

    def test_index_files_login(self):
        "Test index page with login at /documents/files/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('index_files'))
        self.assertEquals(response.status_code, 200)

    def test_index_weblinks_login(self):
        "Test index page with login at /documents/weblinks/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('index_weblinks'))
        self.assertEquals(response.status_code, 200)

    # Folders

    def test_folder_add(self):
        "Test index page with login at /documents/folder/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('documents_folder_add'))
        self.assertEquals(response.status_code, 200)
        # form
        self.assertEqual(Folder.objects.count(), 1)
        post_data = {'name': 'test'}
        response = self.client.post(reverse('documents_folder_add'), post_data)
        self.assertEquals(response.status_code, 302)  # redirect somewhere
        self.assertEquals(Folder.objects.count(), 2)

    def test_folder_view_login(self):
        "Test index page with login at /documents/folder/view/<folder_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('documents_folder_view', args=[self.folder.id]))
        self.assertEquals(response.status_code, 200)

    def test_folder_edit_login(self):
        "Test index page with login at /documents/folder/edit/<folder_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password})
        self.assertRedirects(response, '/')
        response = self.client.get(
            reverse('documents_folder_edit', args=[self.folder.id]))
        self.assertEquals(response.status_code, 200)
#.........這裏部分代碼省略.........
開發者ID:tovmeod,項目名稱:anaf,代碼行數:103,代碼來源:tests.py


注:本文中的models.Document.set_default_user方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。