def setUp(self):
     mock_token = {
         'token': 'foobar',
         'token_secret': 'foobar',
         'consumer_key': 'foobar',
         'consumer_secret': 'foobar',
     }
     self.api = GRatingsAndReviews(mock_token)
Esempio n. 2
0
 def setUp(self):
     mock_token = {'token': 'foobar', 
                   'token_secret': 'foobar',
                   'consumer_key': 'foobar',
                   'consumer_secret': 'foobar',
                  }
     self.api = GRatingsAndReviews(mock_token)
class TestGRatingsAndReviews(unittest.TestCase):
    def setUp(self):
        mock_token = {
            'token': 'foobar',
            'token_secret': 'foobar',
            'consumer_key': 'foobar',
            'consumer_secret': 'foobar',
        }
        self.api = GRatingsAndReviews(mock_token)

    def tearDown(self):
        self.api.shutdown()

    def make_review(self):
        review = Mock()
        review.rating = 4
        review.origin = 'ubuntu'
        review.app.appname = ''
        review.app.pkgname = 'foobar'
        review.text = 'Super awesome app!'
        review.summary = 'Cool'
        review.package_version = '1.0'
        review.date = '2012-01-22'
        review.language = 'en'
        return review

    def wait_for_worker(self):
        while self.api.worker_thread._transmit_state != TRANSMIT_STATE_DONE:
            sleep(0.1)

    @patch('softwarecenter.ui.gtk3.review_gui_helper.RatingsAndReviewsAPI'
           '.submit_review')
    def test_submit_review(self, mock_submit_review):
        mock_submit_review.return_value = ReviewDetails.from_dict(
            {'foo': 'bar'})
        review = self.make_review()

        self.api.submit_review(review)

        self.wait_for_worker()
        self.assertTrue(mock_submit_review.called)
        review_arg = mock_submit_review.call_args[1]['review']
        self.assertEqual(review.text, review_arg.review_text)

    @patch('softwarecenter.ui.gtk3.review_gui_helper.RatingsAndReviewsAPI'
           '.flag_review')
    def test_flag_review(self, mock_flag_review):
        mock_flag_review.return_value = 'Something'

        self.api.report_abuse(1234, 'Far too silly', 'Stop right now.')

        self.wait_for_worker()
        self.assertTrue(mock_flag_review.called)
        self.assertEqual(1234, mock_flag_review.call_args[1]['review_id'])

    @patch('softwarecenter.ui.gtk3.review_gui_helper.RatingsAndReviewsAPI'
           '.submit_usefulness')
    def test_submit_usefulness(self, mock_submit_usefulness):
        mock_submit_usefulness.return_value = 'Something'

        self.api.submit_usefulness(1234, True)

        self.wait_for_worker()
        self.assertTrue(mock_submit_usefulness.called)
        self.assertEqual(1234,
                         mock_submit_usefulness.call_args[1]['review_id'])

    @patch('softwarecenter.ui.gtk3.review_gui_helper.RatingsAndReviewsAPI'
           '.modify_review')
    def test_modify_review(self, mock_modify_review):
        mock_modify_review.return_value = ReviewDetails.from_dict(
            {'foo': 'bar'})
        review = {
            'summary': 'Cool',
            'review_text': 'Super awesome app!',
            'rating': 4,
        }

        self.api.modify_review(1234, review)

        self.wait_for_worker()
        self.assertTrue(mock_modify_review.called)
        self.assertEqual(1234, mock_modify_review.call_args[1]['review_id'])
        self.assertEqual(4, mock_modify_review.call_args[1]['rating'])
        self.assertEqual('Cool', mock_modify_review.call_args[1]['summary'])

    @patch('softwarecenter.ui.gtk3.review_gui_helper.RatingsAndReviewsAPI'
           '.delete_review')
    def test_delete_review(self, mock_delete_review):
        mock_delete_review.return_value = 'Something'

        self.api.delete_review(1234)

        self.wait_for_worker()
        self.assertTrue(mock_delete_review.called)
        self.assertEqual(1234, mock_delete_review.call_args[1]['review_id'])
Esempio n. 4
0
class TestGRatingsAndReviews(unittest.TestCase):
    def setUp(self):
        mock_token = {'token': 'foobar', 
                      'token_secret': 'foobar',
                      'consumer_key': 'foobar',
                      'consumer_secret': 'foobar',
                     }
        self.api = GRatingsAndReviews(mock_token)

    def tearDown(self):
        self.api.shutdown()

    def make_review(self):
        review = Mock()
        review.rating = 4
        review.origin = 'ubuntu'
        review.app.appname = ''
        review.app.pkgname = 'foobar'
        review.text = 'Super awesome app!'
        review.summary = 'Cool'
        review.package_version = '1.0'
        review.date = '2012-01-22'
        review.language = 'en'
        return review        

    def wait_for_worker(self):
        while self.api.worker_thread._transmit_state != TRANSMIT_STATE_DONE:
            sleep(0.1)

    @patch('softwarecenter.ui.gtk3.review_gui_helper.RatingsAndReviewsAPI'
        '.submit_review')
    def test_submit_review(self, mock_submit_review):
        mock_submit_review.return_value = ReviewDetails.from_dict(
            {'foo': 'bar'})
        review = self.make_review()

        self.api.submit_review(review)

        self.wait_for_worker()
        self.assertTrue(mock_submit_review.called)
        review_arg = mock_submit_review.call_args[1]['review']
        self.assertEqual(review.text, review_arg.review_text)

    @patch('softwarecenter.ui.gtk3.review_gui_helper.RatingsAndReviewsAPI'
        '.flag_review')
    def test_flag_review(self, mock_flag_review):
        mock_flag_review.return_value = 'Something'

        self.api.report_abuse(1234, 'Far too silly', 'Stop right now.')

        self.wait_for_worker()
        self.assertTrue(mock_flag_review.called)
        self.assertEqual(1234, mock_flag_review.call_args[1]['review_id'])

    @patch('softwarecenter.ui.gtk3.review_gui_helper.RatingsAndReviewsAPI'
        '.submit_usefulness')
    def test_submit_usefulness(self, mock_submit_usefulness):
        mock_submit_usefulness.return_value = 'Something'

        self.api.submit_usefulness(1234, True)

        self.wait_for_worker()
        self.assertTrue(mock_submit_usefulness.called)
        self.assertEqual(1234, mock_submit_usefulness.call_args[1]['review_id'])

    @patch('softwarecenter.ui.gtk3.review_gui_helper.RatingsAndReviewsAPI'
        '.modify_review')
    def test_modify_review(self, mock_modify_review):
        mock_modify_review.return_value = ReviewDetails.from_dict(
            {'foo': 'bar'})
        review = {
            'summary': 'Cool',
            'review_text': 'Super awesome app!',
            'rating': 4,
        }

        self.api.modify_review(1234, review)

        self.wait_for_worker()
        self.assertTrue(mock_modify_review.called)
        self.assertEqual(1234, mock_modify_review.call_args[1]['review_id'])
        self.assertEqual(4, mock_modify_review.call_args[1]['rating'])
        self.assertEqual('Cool', mock_modify_review.call_args[1]['summary'])

    @patch('softwarecenter.ui.gtk3.review_gui_helper.RatingsAndReviewsAPI'
        '.delete_review')
    def test_delete_review(self, mock_delete_review):
        mock_delete_review.return_value = 'Something'

        self.api.delete_review(1234)

        self.wait_for_worker()
        self.assertTrue(mock_delete_review.called)
        self.assertEqual(1234, mock_delete_review.call_args[1]['review_id'])