def test_get_default_currency(self):
        self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY] = 'BRL'
        with patch.object(sys, 'argv', 'program --get-default-currency'.split()):
            rates.main(self.wf)

        self.assertEqual(len(self.wf._items), 1)
        self.assertEqual(self.wf._items[0].title, 'Your default currency is: BRL')
    def test_get_default_divisor(self):
        self.wf.settings.clear()

        with patch.object(sys, 'argv', 'program --get-default-divisor'.split()):
            rates.main(self.wf)

        self.assertEqual(self.wf._items[0].title, "No number divisor set, using the default '.'")
    def test_get_default_divisor_setted(self):
        self.wf.settings[rates.SETTINGS_DEFAULT_NUMBER_DIVISOR] = ','

        with patch.object(sys, 'argv', 'program --get-default-divisor'.split()):
            rates.main(self.wf)

        self.assertEqual(self.wf._items[0].title, "The number divisor is: ','")
 def test_convert_from_other_to_default_multi_query(self):
     with patch.object(sys, 'argv', ['program', '100 BRL CLP; GBP 100; 100 GBP CAD']):
         rates.main(self.wf)
     self.assertEqual(len(self.wf._items), 3)
     self.assertNotEqual(self.wf._items[0].subtitle.find('(Brazilian real) -> (Chilean peso) with rate'), -1)
     self.assertNotEqual(self.wf._items[1].subtitle.find('(British pound [B]) -> (Brazilian real) with rate'), -1)
     self.assertNotEqual(self.wf._items[2].subtitle.find('(British pound [B]) -> (Canadian dollar) with rate'), -1)
Пример #5
0
    def test_convert_from_default_to_other_without_values(self):
        self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY] = 'USD'

        with patch.object(sys, 'argv', ['program', 'BRL']):
            rates.main(self.wf)

        self.assertTrue(len(self.wf._items), 1)
        self.assertNotEqual(self.wf._items[0].subtitle.find('USD (United States dollar) -> BRL (Brazilian real)'), -1)
    def test_convert_from_detault_to_other_without_values_multi_query(self):
        self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY] = 'USD'

        with patch.object(sys, 'argv', ['program', '100 BRL CLP; GBP; 100 GBP CAD']):
            rates.main(self.wf)
        self.assertEqual(len(self.wf._items), 3)
        self.assertNotEqual(self.wf._items[0].subtitle.find('(Brazilian real) -> (Chilean peso) with rate'), -1)
        self.assertNotEqual(self.wf._items[1].subtitle.find('(United States dollar) -> (British pound [B]) with rate'), -1)
        self.assertNotEqual(self.wf._items[2].subtitle.find('(British pound [B]) -> (Canadian dollar) with rate'), -1)
Пример #7
0
 def test_clear_caches(self):
     self.wf.cache_data('test_cache', 'testing cache')
     self.wf.store_data('test_store', 'testing store')
     with patch.object(sys, 'argv', 'program --clear'.split()):
         rates.main(self.wf)
     self.assertEqual(len(self.wf._items), 1)
     self.assertEqual(self.wf._items[0].title, 'Caches cleared!')
     self.assertIsNone(self.wf.stored_data('test_store'))
     self.assertIsNone(self.wf.cached_data('test_cache'))
 def test_convert_high_rates(self):
     # Test the problem reported in #14, converting from idr to usd
     # Yahoo will return as rate 0.0001, because it's the minimum
     # but the rate is something around 0.000007...
     with patch.object(sys, 'argv', ['program', '1 idr usd']):
             rates.main(self.wf)
     # must have only 1 item
     self.assertEqual(len(self.wf._items), 1)
     # must not be rate 0.0001 for query
     self.assertEqual(self.wf._items[0].subtitle.find('(Indonesian rupiah) -> (United States dollar) with rate 0.0001 for query'), -1)
     # must be a conversion message
     self.assertNotEqual(self.wf._items[0].subtitle.find('(Indonesian rupiah) -> (United States dollar) with rate'), -1)
Пример #9
0
 def test_convert_eur(self):
     # This test is because of a bug with displaying EUR symbol
     with patch.object(sys, 'argv', 'program 1 USD EUR'.split()):
         rates.main(self.wf)
     self.assertEqual(len(self.wf._items), 1)
     self.assertNotEqual(self.wf._items[0].subtitle.find('USD (United States dollar) -> EUR (Euro) with rate'), -1)
Пример #10
0
 def test_full_convert(self):
     with patch.object(sys, 'argv', ['program', '100', 'BRL', 'CLP']):
         rates.main(self.wf)
     self.assertEqual(len(self.wf._items), 1)
     self.assertNotEqual(self.wf._items[0].subtitle.find('BRL (Brazilian real) -> CLP (Chilean peso) with rate'), -1)
 def test_invalid_currency_number_to_convert(self):
     with patch.object(sys, 'argv', ['program', 'zupa BRL USD']):
         ret = rates.main(self.wf)
     self.assertTrue(ret, 100)
Пример #12
0
    def test_set_default_divisor_dot(self):
        with patch.object(sys, 'argv', 'program --set-default-divisor .'.split()):
            rates.main(self.wf)

        self.assertEqual(self.wf._items[0].title, "Default divisor updated to: '.'")
Пример #13
0
    def test_set_wrong_default_divisor(self):
        with patch.object(sys, 'argv', 'program --set-default-divisor ;'.split()):
            rates.main(self.wf)

        self.assertEqual(self.wf._items[0].title, "Wrong divisor, please specify '.' or ','.")
Пример #14
0
    def test_set_invalid_currency(self):
        with patch.object(sys, 'argv', 'program --set-default-currency zupa'.split()):
            rates.main(self.wf)

        self.assertEqual(len(self.wf._items), 1)
        self.assertEqual(self.wf._items[0].title, 'You entered a invalid currency...')
Пример #15
0
 def test_convert_from_other_to_default(self):
     with patch.object(sys, 'argv', ['program', 'CLP', '100']):
         rates.main(self.wf)
     self.assertEqual(len(self.wf._items), 1)
     self.assertNotEqual(self.wf._items[0].subtitle.find('CLP (Chilean peso) -> BRL (Brazilian real) with rate'), -1)
Пример #16
0
    def test_set_default_currency(self):
        with patch.object(sys, 'argv', ['program', '--set-default-currency', 'BRL']):
            rates.main(self.wf)

        self.assertEqual(self.wf.settings[rates.SETTINGS_DEFAULT_CURRENCY], 'BRL')
Пример #17
0
    def test_default_currency(self):
        with patch.object(sys, 'argv', ['program', '--get-default-currency']):
            rates.main(self.wf)

        self.assertEqual(len(self.wf._items), 1)
        self.assertEqual(self.wf._items[0].title, 'No default currency.')
Пример #18
0
 def test_invalid_currency_number_to_convert_using_default(self):
     with patch.object(sys, 'argv', 'program zupa BRL'.split()):
         ret = rates.main(self.wf)
     self.assertTrue(ret, 100)
Пример #19
0
 def test_convert_case_insensitive(self):
     with patch.object(sys, 'argv', 'program 1 brl clp'.split()):
         rates.main(self.wf)
     self.assertEqual(len(self.wf._items), 1)
     self.assertNotEqual(self.wf._items[0].subtitle.find('BRL (Brazilian real) -> CLP (Chilean peso) with rate'), -1)
Пример #20
0
 def test_invalid_argument(self):
     with patch.object(sys, 'argv', 'program zupa'.split()):
         ret = rates.main(self.wf)
     # 100 means auto complete
     self.assertEqual(ret, 100)