Пример #1
0
 def test_no_config_get_transactions_works_as_normal(self):
     whale = WhaleAlert()
     whale.transactions.get_transactions = mock.MagicMock().method()
     whale.transactions.get_transactions.return_value = (False, {}, {})
     expected = [mock.call(0, None, 'asdf', None, 500000, 100)]
     whale.get_transactions(0, api_key='asdf')
     self.assertEqual(whale.transactions.get_transactions.mock_calls,
                      expected)
Пример #2
0
class WhaleAlertAPICall(unittest.TestCase):
    """ Testing setup for whale alert api call"""
    def setUp(self):
        self.whale = WhaleAlert(TEST_WORKING_DIR)
        self.config = self.whale.get_configuration()
        self.status = self.whale.get_status()
        self.database = self.whale.get_database()

    def tearDown(self):
        cleanup_working_directories()

    def test_configuration_values_are_used_if_working_directory_supplied(self):
        self.whale.transactions.get_transactions = mock.MagicMock().method()
        self.whale.transactions.get_transactions.return_value = (False, {}, {})
        self.config.set_value(settings.API_section_name,
                              settings.API_option_private_key, '1234')
        self.config.set_value(settings.API_section_name,
                              settings.API_option_minimum_value, 10)
        expected = [mock.call(0, None, '1234', None, 10, 100)]
        self.whale.get_transactions(0)
        self.assertEqual(self.whale.transactions.get_transactions.mock_calls,
                         expected)

    def test_configuration_values_are_overwrite_config_values_if_supplied(
            self):
        self.whale.transactions.get_transactions = mock.MagicMock().method()
        self.whale.transactions.get_transactions.return_value = (False, {}, {})
        self.config.set_value(settings.API_section_name,
                              settings.API_option_private_key, '1234')
        self.config.set_value(settings.API_section_name,
                              settings.API_option_minimum_value, 10)
        expected = [mock.call(0, None, '7890', None, 500, 100)]
        self.whale.get_transactions(0, api_key='7890', min_value=500)
        self.assertEqual(self.whale.transactions.get_transactions.mock_calls,
                         expected)

    def test_no_config_value_raises_exception_if_api_key_not_supplied(self):
        whale = WhaleAlert()
        self.assertRaises(ValueError, whale.get_transactions, 0)

    def test_raises_exception_if_start_time_is_not_int(self):
        whale = WhaleAlert()
        self.assertRaises(ValueError,
                          whale.get_transactions,
                          'not_an_int',
                          api_key='1234')

    def test_raises_exception_if_end_time_is_not_int(self):
        whale = WhaleAlert()
        self.assertRaises(ValueError,
                          whale.get_transactions,
                          0,
                          end_time='not_an_int',
                          api_key='1234')

    def test_no_config_get_transactions_works_as_normal(self):
        whale = WhaleAlert()
        whale.transactions.get_transactions = mock.MagicMock().method()
        whale.transactions.get_transactions.return_value = (False, {}, {})
        expected = [mock.call(0, None, 'asdf', None, 500000, 100)]
        whale.get_transactions(0, api_key='asdf')
        self.assertEqual(whale.transactions.get_transactions.mock_calls,
                         expected)