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


Python DataController.addFlashcard方法代碼示例

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


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

示例1: test_addFlashcard

# 需要導入模塊: from flashcardapp.datacontroller import DataController [as 別名]
# 或者: from flashcardapp.datacontroller.DataController import addFlashcard [as 別名]
    def test_addFlashcard(self):
        """
        Steps this test will run:

        1. Creates a new DataController
        2. Creates a new json string representing the data of a flashcard based
           on the specifications of the DataController's addFlashcard method.
        3. Passes the json string to the DataController's addFlashcard method
           and gets the result of the method (response).
        4. Asserts that there is a 'saved' key in the response.
        5. Asserts that the value of 'saved' is True.
        """
        dc = DataController()
        fcTerm = "Term"
        fcDefaultSideLabelId = 1
        boxId = 1
        otherSides = [{"type":"text", "labelId":1, "data":"Definition"}, {"type":"text", "labelId":2, "data":"Translation"}, {"type":"text", "labelId":7, "data":"Conjugation"}]
        data = {"term":fcTerm, "defaultSideLabelId":1, "boxId":boxId, "otherSides":otherSides}
        resultStr = dc.addFlashcard(data, self.user)
        result = json.loads(resultStr)
        self.assertTrue('saved' in result)
        self.assertTrue(result['saved'], result['message'])

        #Check the association was done correctly
        box = Box.objects.get(pk=boxId)
        fc = Flashcard.objects.get(term=fcTerm)

        self.assertIn(fc, box.flashcard_set.all())
        self.assertIn(box, fc.boxes.all())

        self.assertEqual(len(fc.textside_set.all()), len(otherSides))
開發者ID:hrusza01,項目名稱:Flash-Card-Website-2013,代碼行數:33,代碼來源:tests.py

示例2: addFlashcard

# 需要導入模塊: from flashcardapp.datacontroller import DataController [as 別名]
# 或者: from flashcardapp.datacontroller.DataController import addFlashcard [as 別名]
def addFlashcard(request, FlashcardData):
    ''' Ajax wrapper for the DataController function 'addFlashcard'

    *Takes*
      A dictionary representing a flashcard
    *Returns*
      A json string declaring saved data success or failure

    See the DataController documentation for more information
    '''
    dc = DataController()
    return dc.addFlashcard(FlashcardData, request.user)
開發者ID:hrusza01,項目名稱:Flash-Card-Website-2013,代碼行數:14,代碼來源:ajax.py


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