本文整理匯總了Python中flashcardapp.datacontroller.DataController類的典型用法代碼示例。如果您正苦於以下問題:Python DataController類的具體用法?Python DataController怎麽用?Python DataController使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DataController類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_getFlashcardsFromBoxes
def test_getFlashcardsFromBoxes(self):
"""
Steps this test will run:
1. Creates a new DataController
2. Attempts to retreive the json representation of all Flashcard from
the a list of boxes
3. Asserts the number of flashcards is 2
4. Asserts the Flashcard term is "Guten Tag"
5. Asserts the Flashcard defintion is "Good Day"
"""
dc = DataController()
numOfCards = 5
boxes = [1,13]
translationLabel = Label.objects.get(name="Translation")
data = dc.getFlashcardsFromBoxes(boxes)
self.assertEqual(data['message'], DataController.SUCCESS_STR)
cards = data['cards']
self.assertEqual(len(cards), numOfCards)
self.assertEqual(cards[0]['term'], "Der Bauch")
self.assertEqual(cards[0]['defaultSideLabel_id'], translationLabel.Id)
textside = TextSide.objects.get(flashcardKey=cards[0]['id'], labelKey=translationLabel)
self.assertEqual(textside.text, "The Stomach")
self.assertEqual(cards[1]['term'], "Das Wetter")
self.assertEqual(cards[1]['defaultSideLabel_id'], translationLabel.Id)
textside = TextSide.objects.get(flashcardKey=cards[1]['id'], labelKey=translationLabel)
self.assertEqual(textside.text, "The Weather")
self.assertEqual(cards[2]['term'], "Das Essen")
self.assertEqual(cards[2]['defaultSideLabel_id'], translationLabel.Id)
textside = TextSide.objects.get(flashcardKey=cards[2]['id'], labelKey=translationLabel)
self.assertEqual(textside.text, "The Food")
示例2: test_addFlashcard
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))
示例3: test_getContainersWithBoxesFromClass
def test_getContainersWithBoxesFromClass(self):
"""
Steps this test will run:
1. Creates a new DataController
2. Attempts to retrieve a json string that represents the all the
containers with their boxes that are associated with the given class
3. Validates and decodes the json returned
4. Asserts their is only one container
5. Asserts the title of the Container is self.containerName
6. Asserts the number of boxes is 1
7. Asserts the title of of the box is self.boxName
"""
clsId = 1
cntName = "Verbs"
boxName = "Day 1"
numOfContainers = 3
numOfBoxes = 3
dc = DataController()
jsonStr = dc.getContainersWithBoxesFromClass(clsId)
data = json.loads(jsonStr)
self.assertTrue(data['message'] == DataController.SUCCESS_STR, data['message'])
containers = data['containers']
self.assertEqual(len(containers), numOfContainers)
self.assertEqual(containers[0]["title"], cntName)
boxes = containers[0]['boxes']
self.assertEqual(len(boxes), numOfBoxes)
self.assertEqual(boxes[0]['title'], boxName)
示例4: test_addBox
def test_addBox(self):
"""
Steps this test will run:
1. Creates a new DataController
2. Creates a new json string representing the data of a box based
on the specifications of the DataController's addBox method.
3. Passes the json string to the DataController's addBox 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()
boxTitle = "Test Box"
cntId = 1
data = {"title":boxTitle, "containerId":cntId}
resultStr = dc.addBox(data)
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(title=boxTitle)
cnt = Container.objects.get(pk=cntId)
self.assertIn(cnt, box.containers.all())
self.assertIn(box, cnt.box_set.all())
示例5: test_addContainerToMyCardsWithAutoUpdates
def test_addContainerToMyCardsWithAutoUpdates(self):
"""
Steps this test will run:
1.
.
.
.
?.
"""
cntName = "Shared Greetings"
toClassId = 1
fromClassId = 6
cntToGetId = 5
numofcontainers = 4
dc = DataController()
toClass = Class.objects.get(pk=toClassId)
toCopyContainer = Container.objects.get(pk=cntToGetId)
result = dc.addContainerToMyCards(toCopyContainer.Id, toClass.Id, True)
data = json.loads(result)
self.assertTrue(data['added'], data['message'])
self.assertEqual(len(toClass.container_set.all()), numofcontainers)
self.assertIsNotNone(toClass.container_set.get(title=cntName))
copiedContainer = toClass.container_set.get(title=cntName)
self.assertEqual(copiedContainer.Id, toCopyContainer.Id)
self.assertNotEqual(copiedContainer.owner, toClass.user)
self.assertEqual(len(copiedContainer.box_set.all()), len(toCopyContainer.box_set.all()))
self.assertEqual(copiedContainer, toCopyContainer)
self.assertIn(toClass, copiedContainer.classes.all())
self.assertIn(toClass, toCopyContainer.classes.all())
示例6: test_deleteFlashcards
def test_deleteFlashcards(self):
"""
Steps this test will run:
1. Creates a new DataController
2. Calls the data controller method to delete flashcard 1, 2, and 19
3. Receives and validates the returned json string
4. Asserts the returns json says the deleted was successful
5. Asserts the message matches DataController.SUCCESS_STR
"""
persistingFc = Flashcard.objects.get(pk=19)
box1 = Box.objects.get(pk=1)
box2 = Box.objects.get(pk=8)
numofflashcards = 2
dc = DataController()
jsonStr = dc.deleteFlashcards({1:[2,19], 8:[7]})
data = json.loads(jsonStr)
self.assertTrue(data['deleted'], data['message'])
self.assertEqual(data['message'], DataController.SUCCESS_STR)
self.assertEqual(len(box1.flashcard_set.all()), numofflashcards)
self.assertEqual(len(box2.flashcard_set.all()), numofflashcards)
with self.assertRaises(Flashcard.DoesNotExist):
Flashcard.objects.get(pk=2)
with self.assertRaises(Flashcard.DoesNotExist):
Flashcard.objects.get(pk=7)
self.assertIsNotNone(persistingFc)
self.assertEqual(len(persistingFc.boxes.all()), 1)
示例7: test_updateFlashcard
def test_updateFlashcard(self):
"""
Docstring goes here
"""
numoftextsides = 3
data = {'cardId':4, 'term':"New Term",'defaultSideLabel_id':2,\
'otherSides': [{'labelId':8,'type':"text",'data':"None"},\
{'labelId':2,'type':"text",'data':"New Translation"}, \
{'labelId':13,'type':"text",'data':"Das Essen schmeckt mir."}]}
dc = DataController()
response = json.loads(dc.updateFlashcard(data, self.user))
self.assertTrue(response['updated'], response['message'])
self.assertEqual(response['message'], DataController.SUCCESS_STR)
flashcard = Flashcard.objects.get(pk=data['cardId'])
self.assertEquals(flashcard.term, data['term'])
self.assertEquals(flashcard.defaultSideLabel.Id, data['defaultSideLabel_id'])
self.assertEquals(len(flashcard.textside_set.all()), numoftextsides)
for tsinfo in data['otherSides']:
qs = flashcard.textside_set.filter(labelKey__Id=tsinfo['labelId'])
self.assertTrue(qs.exists())
for ts in qs:
self.assertEqual(ts.text, tsinfo['data'])
示例8: test_addClass
def test_addClass(self):
"""
Steps this test will run:
1. Creates a new DataController
2. Creates a new json string representing the data of a class based
on the specifications of the DataController's addClass method.
3. Passes the json string to the DataController's addClass 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()
clsTitle = "New Class"
data = {"title":clsTitle}
resultStr = dc.addClass(data, self.user)
result = json.loads(resultStr)
self.assertTrue('saved' in result)
self.assertTrue(result['saved'], result['message'])
#Check that the associatation was actually made
cls = Class.objects.get(title=clsTitle)
self.assertEquals(cls.user, self.user)
self.assertIn(cls, self.user.class_set.all())
示例9: test_addContainer
def test_addContainer(self):
"""
Steps this test will run:
1. Creates a new DataController
2. Creates a new json string representing the data of a container based
on the specifications of the DataController's addContainer method.
3. Passes the json string to the DataController's addContainer 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()
cName = "Test Container"
clsKey = 1
numofcontainers = 4
data = {"title":cName, "classId":clsKey}
resultStr = dc.addContainer(data, self.user)
result = json.loads(resultStr)
self.assertTrue('saved' in result)
self.assertTrue(result['saved'], result['message'])
#Check that the associatation was actually made
clist = Container.objects.filter(classes__Id=clsKey)
self.assertEqual(len(clist), numofcontainers)
cls = Class.objects.get(pk=clsKey)
cnt = Container.objects.get(title=cName)
self.assertIn(cls, cnt.classes.all())
self.assertTrue(cnt in cls.container_set.all(), "The container is not associated with the class.")
示例10: getPreviewView
def getPreviewView(request, containerId):
'''Docstring goes here
'''
t = loader.get_template('flashcardapp/previewPartial.html')
dc = DataController()
data = dc.getBoxesAndFlashcardsFromContainer(containerId)
c = Context({"boxflashcarddata": data}) #variable name that is referenced in the view
return HttpResponse(t.render(c))
示例11: getSharedContainers
def getSharedContainers(request):
'''Ajax wrapper method for the DataController method 'getSharedContainers'
*Returns*
A json encoded list of Containers
See the DataController documentation for more information.
'''
dc = DataController()
return dc.getSharedContainers()
示例12: getBoxesAndFlashcards
def getBoxesAndFlashcards(request, containerId):
'''Ajax wrapper for the DataController function 'getBoxesAndFlashcards'
*Returns*
A list of boxes with their corresponding flashcards encoded in json.
See the DataController documentation for more information
'''
dc = DataController()
return dc.getBoxesAndFlashcardsFromContainer(containerId)
示例13: getFlashcard
def getFlashcard(request, flashcardId):
''' Ajax wrapper for the DataController function 'getFlashcard'
*Returns*
A Flashcard with the given id encoded in json
See the DataController documentation for more information
'''
dc = DataController()
return dc.getFlashcard(flashcardId)
示例14: getBox
def getBox(request, boxId):
'''Ajax wrapper for the DataController function 'getBox'
*Returns*
A Box with the given id encoded in json
See the DataController documentation for more information
'''
dc = DataController()
return dc.getBox(boxId)
示例15: getTagList
def getTagList(request):
''' Ajax wrapper for the DataController function 'getTagList'
*Returns*
A list of Tags encoded in json
See the DataController documentation for more information
'''
dc = DataController()
return dc.getTagList()