Ejemplo n.º 1
0
 def testPiazzaToUserIntIdMapping(self):
     importer = PiazzaImporter('unittest', # MySQL user
                               '',         # MySQL pwd
                               'unittest', # MySQL db
                               None,       # MySQL table
                               'data/test_PiazzaContent.json', # JSON Piazza content file path
                               usersFileName='data/test_PiazzaUsers.json', # JSON Piazza user info file path
                               unittesting=True)
     importer.importJsonUsersFromPiazzaZip('data/test_PiazzaUsers.json')        
     self.assertEqual(210129, importer.idPiazza2UserIntId('hqyjmaplhAK'))
     self.assertEqual(211516, importer.idPiazza2UserIntId('hc19qkoyc9C'))
Ejemplo n.º 2
0
    def testHighLevelAccessors(self):

        piazzaImporter = PiazzaImporter('unittest',       # MySQL user 
                                        '',               # MySQL pwd
                                        'unittest',       # MySQL db
                                        'piazza_content', # MySQL table
                                        'data/test_PiazzaContent.json', # Test file from Piazza
                                        'data/test_PiazzaUsers.json',
                                        )


        firstPostObj = piazzaImporter[0]
        
        self.assertEqual('hr7xjaytsC8',firstPostObj['piazza_id'])

        #   --- Getting Children --- 
        children = firstPostObj['children']
        self.assertEqual(1, len(children))
        child = children[0]
        self.assertEqual('wABgOWyIDVYn-8kzkgMnNw==', child['oid'])

        childHistArr = child['history']
        self.assertEqual(1, len(childHistArr))
        childHistContentObj = childHistArr[0]
        self.assertEqual('2014-01-26T18:13:50Z', childHistContentObj['created'])

        self.assertEqual('hqq8e4mn3fp115',childHistContentObj['piazza_id'])
        self.assertGreater(childHistContentObj['user_int_id'],-1)

        #   --- Getting Subject --- 
        
        # Getting subject from a PiazzaPost instance:
        subject = firstPostObj['subject']
        self.assertEqual('wireshark shows same packet sent twice', subject)
        
        # Getting subject from a PiazzaPost OID:
        subject = piazzaImporter.getSubject(firstPostObj)
        self.assertEqual('wireshark shows same packet sent twice', subject)
        
        # Getting subject from a PiazzaPost JSON object:
        subject = piazzaImporter.getSubject(firstPostObj.nameValueDict)
        self.assertEqual('wireshark shows same packet sent twice', subject)
        
        # Getting the subject of the first post:
        subject = piazzaImporter[0]['subject']
        self.assertEqual('wireshark shows same packet sent twice', subject)
        
        # Date of second entry in first object's history array:
        theDate = firstPostObj['history'][1]['create_date']
        self.assertEqual('2014-01-26T10:08:18Z', theDate)
        
        # Test history arrays with more than one entry:
        thirdPostObj = piazzaImporter[2]
        
        self.assertEqual('2014-01-22T08:09:32Z', thirdPostObj['updated'])
        self.assertEqual('<p>64-bit Waterfox</p>', thirdPostObj['subject'])
        
        thirdPostKeys = [
                        'folders',
                        'updated',
                        'no_upvotes',
                        'uid',
                        'no_answer',
                        'config',
                        'created',
                        'piazza_id',
                        'user_int_id',
                        'anon_screen_name',
                        'id',
                        'change_log',
                        'anon',
                        'bucket_name',
                        'type',
                        'bucket_order',
                        'data',
                        'children',
                        'subject',
                        'oid'
                        ]
        self.assertItemsEqual(thirdPostKeys, thirdPostObj.keys())

        
        fourthPostObj = piazzaImporter[3]
        
        self.assertEqual(241, fourthPostObj['unique_views'])
        
        #****** Test: nr == 9 when nr is renamed

        fourthObjSubj = fourthPostObj['subject']
        self.assertEqual('pre-course survey is not viewing', fourthObjSubj)

        self.assertEqual('h814wubnNmj',fourthPostObj['history'][4]['piazza_id'])

        
        
        #   --- Getting Content --- 

        # Getting content from a PiazzaPost instance:
        fourthObjContent = ['Content objFour 5th from bottom.',
                            'Content objFour 4th from bottom.',
                            'Content objFour 3rd from bottom.',
                            'Content objFour 2nd from bottom.',
                            'Content objFour 1st from bottom.'
                            ]

        
        
        contentArr = fourthPostObj['content']
        self.assertItemsEqual(fourthObjContent, contentArr)
        
        # Getting content from a PiazzaPost OID:
        contentArr = piazzaImporter.getContent(fourthPostObj['oid'])
        self.assertItemsEqual(fourthObjContent, contentArr)
        
        # Get first post's content (i.e. body):
        content = piazzaImporter[-1]['body']    # For compatibility with OpenEdX forum
        self.assertEqual(fourthObjContent, content)

        
        # Get first post's tags:
        tags = piazzaImporter[0]['tags']
        self.assertEqual([u'lectures',u'student'], tags)
        
        # First post's Piazze UID:
        piazzaUID = piazzaImporter[0]['id']
        self.assertEqual('hr7xjaytsC8', piazzaUID)
        
        # First post's status:
        status = piazzaImporter[0]['status']
        self.assertEqual('active', status)
        
        # First post's 'no answer followup':
        noAnswerFollowup = piazzaImporter[0]['no_answer_followup']
        self.assertEqual(0, noAnswerFollowup)
        
        # First post's creation date:
        cDate = piazzaImporter[0]['created']
        self.assertEqual('2014-01-26T10:08:18Z', cDate)
        
        # First post's creation date using get()
        cDate = piazzaImporter[0].get('created', '0000-00-00T00:00:00')
        self.assertEqual('2014-01-26T10:08:18Z', cDate)
        
        # First post's type:
        theType = piazzaImporter[0]['type']
        self.assertEqual('question', theType)
        
        # First post's good-tags-array of user_int_id's;
        # In original json these are arrays of Piazza Ids.
        # That raw is ['hc19qkoyc9C']; get the user_int_id
        # we expect:
        user_int_id = PiazzaImporter.idPiazza2UserIntId('hc19qkoyc9C')
        tagGoodArr = piazzaImporter[0]['tag_good_arr']
        self.assertEqual([user_int_id], tagGoodArr)
        # Synonym for tag_good_arr: good_tags:
        tagGoodArr = piazzaImporter[0]['good_tags']
        self.assertEqual([user_int_id], tagGoodArr)
        
        # First endorse-tags array:
        tagEndorseArr = piazzaImporter[0]['tag_endorse_arr']
        self.assertEqual([232871], tagEndorseArr)
        # Synonym for tag_endorse_arr: endorse_tags:
        tagEndorseArr = piazzaImporter[0]['endorse_tags']
        self.assertEqual([232871], tagEndorseArr)
        
        
        # Second post's number of up-votes received:
        numVotes = piazzaImporter[1]['no_upvotes'] # second JSON obj!
        self.assertEqual(2, numVotes)
        
        # Second post's number of answers received:
        numAnswers = piazzaImporter[1]['no_answer'] # second JSON obj!
        self.assertEqual(0, numAnswers)
        
        # Second post's number of followup answers received:
        numAnswers = piazzaImporter[1]['no_answer_followup'] # second JSON obj!
        self.assertEqual(0, numAnswers)
        
        # Second post's 'is anonymous post':
        anonLevel = piazzaImporter[1]['anon']
        self.assertEqual('no', anonLevel)
        
        # First post's bucket name property does not exist:
        self.assertIsNone(piazzaImporter[0]['bucket_name'])
        
        self.assertFalse(piazzaImporter[0].has_key('bucket_name'))

        # Second post's bucket name:
        self.assertTrue(piazzaImporter[1].has_key('bucket_name'))
        bucketName = piazzaImporter[1]['bucket_name'] # second JSON obj!
        self.assertEqual('Week 1/19 - 1/25', bucketName)

        # Second post's 'updated' field:
        updated = piazzaImporter[1]['updated'] # second JSON obj!
        self.assertEqual('2014-01-22T06:55:56Z', updated)

        # First post's 'folders' (names) array:
        folders = piazzaImporter[0]['folders']
        self.assertEqual(['lectures'], folders)

        # Test idPiazza2Anon():
        self.assertEqual(260005, piazzaImporter.idPiazza2UserIntId('hr7xjaytsC8'))