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'))
    def testUsersImport(self):
        # Get an importer with minimal initialization;
        # accomplished by the 'unittesting=True':
        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')
        
        # Test retrieval of one PiazzaUser instance by Piazza uid.
        hc19qkoyc9C_UserObj = PiazzaImporter.usersByPiazzaId['hc19qkoyc9C']

        # To make this test work even if the underlying database
        # does not have a mapping from the LTI to user int,
        # force correctness, but at least check for correct type:
        if type(hc19qkoyc9C_UserObj) != int:
            assert("A PiazzaUser's user_int_id must be an integer.")
        
        truth = [(u'asks', 0), 
                 (u'views', 7), 
                 ('ext_id', u'47bf69315b7391dace7ccbc344690969'), 
                 ('piazza_id', u'hc19qkoyc9C'), 
                 (u'posts', 0), 
                 (u'days', 7), 
                 (u'answers', 0),
                 ('anon_screen_name', 'anon_screen_name_redacted'),
                 ('user_int_id', hc19qkoyc9C_UserObj['user_int_id']),
                 ]
        
        self.assertItemsEqual(truth, hc19qkoyc9C_UserObj.items())
        
        # Check that PiazzaImporter created the proper number of PiazzaUser
        # instances. It should equal the number of top level JSON 
        # structs in the test file for this test method:
        with open('data/test_PiazzaUsers.json', 'r') as fd:
            numJsonLines = len(json.load(fd))
        self.assertEqual(numJsonLines, len(importer))
        
        hc19qkoyc9C_UserObj.keys()