コード例 #1
0
 def setUp(self):
     module_logger.debug('method setUp was called')
     users = CreateUsers()
     users.registerUsers(3)
     self.userList = users.getUserList(3)
     self.fileAddress = '/home/piqto/news_images/The_Hindu/2013_06_24/Chennai/20130624B_00310100501.jpg'
     response = requests.post('https://192.168.1.15/image/upload', 
                               verify = False,
                               data = {'username':'******'},
                               files = {'uploadedfile': open(self.fileAddress, 'rb')})
     responseDict = eval(response.text.replace('null', 'None'))
     articleId = responseDict['matches'][0]['id'] if len(responseDict['matches']) > 0 else None
     self.attribs = ArticleAttrib(articleId, 'testuser')
     self.oldAttribs = self.attribs.getAllAttrib(self.fileAddress)
     module_logger.debug('method setUp completed successfully')
コード例 #2
0
class AttribTest(unittest.TestCase):
    '''
    Test whether the Like and Comment options are working correctly
    '''


    def setUp(self):
        module_logger.debug('method setUp was called')
        users = CreateUsers()
        users.registerUsers(3)
        self.userList = users.getUserList(3)
        self.fileAddress = '/home/piqto/news_images/The_Hindu/2013_06_24/Chennai/20130624B_00310100501.jpg'
        response = requests.post('https://192.168.1.15/image/upload', 
                                  verify = False,
                                  data = {'username':'******'},
                                  files = {'uploadedfile': open(self.fileAddress, 'rb')})
        responseDict = eval(response.text.replace('null', 'None'))
        articleId = responseDict['matches'][0]['id'] if len(responseDict['matches']) > 0 else None
        self.attribs = ArticleAttrib(articleId, 'testuser')
        self.oldAttribs = self.attribs.getAllAttrib(self.fileAddress)
        module_logger.debug('method setUp completed successfully')


    def tearDown(self):
        module_logger.debug('method tearDown was called')
        for userName in self.userList.keys() :
            self.attribs.userName = userName
            self.attribs.modifyLike(0)
        module_logger.debug('method tearDown completed successfully')


    def testLike(self):
        '''Testing whether like/dislike actions are being performed correctly'''
        
        module_logger.debug('method testLike was called')
        
        for userName in self.userList.keys() :
            self.attribs.userName = userName
            self.attribs.modifyLike(1)
            newAttribs = self.attribs.getAllAttrib(self.fileAddress)
            self.assertEqual(newAttribs['currentUserLike'], 1)
           
        self.assertEqual(newAttribs['likeCount'], self.oldAttribs['likeCount'] + len(self.userList))
        
        for userName in self.userList.keys() :
            self.attribs.userName = userName
            self.attribs.modifyLike(-1)
            newAttribs = self.attribs.getAllAttrib(self.fileAddress)
            self.assertEqual(newAttribs['currentUserLike'], -1)
           
        self.assertEqual(newAttribs['dislikeCount'], self.oldAttribs['dislikeCount'] + len(self.userList))
        
        for userName in self.userList.keys() :
            self.attribs.userName = userName
            self.attribs.modifyLike(0)
            newAttribs = self.attribs.getAllAttrib(self.fileAddress)
            self.assertEqual(newAttribs['currentUserLike'], None)
            
        self.assertEqual(newAttribs['likeCount'], self.oldAttribs['likeCount'])
        self.assertEqual(newAttribs['dislikeCount'], self.oldAttribs['dislikeCount'])
        
        module_logger.debug('method testLike completed successfully')


    def testComment(self):
        '''Testing whether comments are placed at right position'''
        
        module_logger.debug('method testComment was called')
        
        for userName in self.userList.keys() :
            self.attribs.userName = userName
            comment = "Just putting comments..  :)"
            commentDict = {'username': userName, 'comment': comment, 'place': '', 'name': self.userList[userName]}
            self.attribs.addComment(comment)
            newAttribs = self.attribs.getAllAttrib(self.fileAddress)
            self.assertDictContainsSubset(commentDict, newAttribs['comments'][0])
        
        module_logger.debug('method testComment completed successfully')


    def runTest(self):
        filePointer = open('Test-Results.txt', 'a')
        suite = unittest.TestLoader().loadTestsFromTestCase(AttribTest)
        result = unittest.TextTestRunner(verbosity=2, stream=filePointer).run(suite)
        filePointer.close()
        return result


#if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testLike']
    #unittest.main(verbosity = 2)