Repository: lk-geimfari/mimesis

Issue:
Locale not respected for business.currency_iso_code()
# Bug report

## What's wrong

I'm trying to use mimesis to generate mock data for tests I'm going to develop and am writing [schema](https://mimesis.readthedocs.io/getting_started.html#schema-and-fields) to do so.

I set the locale when instantiating an object of class `Field()`, but on calling `business.currency_iso_code()` I get random ISO currency codes, whilst I was expecting (or hoping!) to get those for the current locale.

    import random
    from mimesis.schema import Field, Schema

    class SlotData2():
        def __init__(self, locale, max_currency=10):
            self.field = Field(locale)
            self.max_currency = max_currency

        def _generate_cost(self):
            cost = (
                lambda: {
                    'amount': self.field('business.price'),
                    'currency': self.field('business.currency_iso_code'),
                }
            )
            cost_schema = Schema(schema=cost)
            return cost_schema.create(random.randint(1, self.max_currency))

The `business.price` is always the correct locale, but the `business.currency_iso_code` varies as the following shows...

    In [200]: test2 = SlotData2('en-gb', 10)
    
    In [201]: test2._generate_cost()
    Out[201]: 
    [{'amount': '196.66 £', 'currency': 'BZD'},
     {'amount': '223.12 £', 'currency': 'VUV'}]

    In [202]: test2._generate_cost()
    Out[202]: 
    [{'amount': '626.08 £', 'currency': 'XCD'},
     {'amount': '904.78 £', 'currency': 'BOV'},
     {'amount': '836.96 £', 'currency': 'XUA'},
     {'amount': '529.19 £', 'currency': 'LYD'},
     {'amount': '341.14 £', 'currency': 'ILS'},
     {'amount': '136.68 £', 'currency': 'MGA'},
     {'amount': '691.84 £', 'currency': 'KHR'},
     {'amount': '493.02 £', 'currency': 'SDG'},
     {'amount': '250.04 £', 'currency': 'BGN'},
     {'amount': '649.36 £', 'currency': 'AUD'}]
    
    In [203]: test2._generate_cost()
    Out[203]: 
    [{'amount': '963.86 £', 'currency': 'MNT'},
     {'amount': '707.13 £', 'currency': 'TRY'},
     {'amount': '322.74 £', 'currency': 'SHP'}]

I checked with `Generic('en-gb')` and it too returns random ISO currency codes rather than the expected `GBP`...

    In [204]: g = Generic('en-gb')
    
    In [205]: g.business.currency_iso_code()
    Out[205]: 'AFN'
    
    In [206]: g.business.currency_iso_code()
    Out[206]: 'USD'
    
    In [207]: g.business.currency_iso_code()
    Out[207]: 'ALL'


## How is that should be

I would expect `business.currency_iso_code()` to return the code for the specified locale.

## System information

    python --version
    Python 3.6.7
    In [209]: mimesis.__version__
    Out[209]: '3.1.0'



Discussion:
@slackline Hi! Thanks for your interest. It [seems like](https://github.com/lk-geimfari/mimesis/blob/master/mimesis/providers/business.py#L61) at this moment we do not count locale on generating currency iso code.
@ceccoemi Are you interesting? It's can be done easily, but I'm busy until this weekends.
@slackline We will work on it ASAP. Thanks again for your report.
Thanks for the rapid response @lk-geimfari. I've started looking at the code to see if I could come up with a solution, if I can work it out before then I'll submit a PR.
What we need to do:

1. Add currency code for all locales to file `business.json`
2. Return code from json file, not from the list
3. Add parameter `allow_random=True` to have availability of support much more currency codes (so as not to limit their number - the number of languages supported.).
@lk-geimfari @slackline I'm working on this
@ceccoemi Great! Thank you very much!

Resolving patch:
diff --git a/mimesis/providers/business.py b/mimesis/providers/business.py
--- a/mimesis/providers/business.py
+++ b/mimesis/providers/business.py
@@ -58,12 +58,16 @@ def copyright(self) -> str:  # noqa: A003
             self.company_type(abbr=True),
         )
 
-    def currency_iso_code(self) -> str:
-        """Get code of the currency.
+    def currency_iso_code(self, allow_random: bool = False) -> str:
+        """Get code of the currency for current locale.
 
+        :param allow_random: Get a random ISO code.
         :return: Currency code.
         """
-        return self.random.choice(CURRENCY_ISO_CODES)
+        if allow_random:
+            return self.random.choice(CURRENCY_ISO_CODES)
+        else:
+            return self._data['currency-code']
 
     def cryptocurrency_iso_code(self) -> str:
         """Get symbol of random cryptocurrency.


Test patch:
diff --git a/tests/test_providers/test_business.py b/tests/test_providers/test_business.py
--- a/tests/test_providers/test_business.py
+++ b/tests/test_providers/test_business.py
@@ -27,8 +27,12 @@ def test_copyright(self, business):
         result = business.copyright()
         assert '©' in result
 
-    def test_currency_iso_code(self, _business):
-        result = _business.currency_iso_code()
+    def test_currency_iso_code(self, business):
+        result1 = business.currency_iso_code()
+        result2 = business.currency_iso_code()
+        assert result1 == result2
+
+        result = business.currency_iso_code(allow_random=True)
         assert result in CURRENCY_ISO_CODES
 
     def test_cryptocurrency_iso_code(self, _business):