# coding=utf-8

from __future__ import unicode_literals

import unittest

from faker import Factory
from .. import string_types


class TestJaJP(unittest.TestCase):
    """ Tests phone_number in the ja_JP locale """

    def setUp(self):
        self.factory = Factory.create('ja')

    def test_phone_number(self):
        pn = self.factory.phone_number()
        formats = ('070', '080', '090')

        assert pn
        assert isinstance(pn, string_types)
        first, second, third = pn.split('-')
        assert first
        assert first.isdigit()
        assert second
        assert second.isdigit()
        assert third
        assert third.isdigit()
        if len(first) == 2:
            assert len(second) == 4
            assert len(third) == 4
        else:
            assert len(first) == 3
            assert len(second) == 4
            assert len(third) == 4
            assert first in formats


class TestMSISDN(unittest.TestCase):
    """ Tests MSISDN in the pt_br locale """

    def setUp(self):
        self.factory = Factory.create('pt_br')

    def test_msisdn(self):
        msisdn = self.factory.msisdn()
        formats = ('5511', '5521', '5531', '5541', '5551', '5561', '5571', '5581')

        assert msisdn is not None
        assert isinstance(msisdn, string_types)
        assert len(msisdn) == 13
        assert msisdn.isdigit()
        assert msisdn[0:4] in formats

@@ -87,21 +87,19 @@
 mport Fa
-ctory
+ker
 %0Afrom ..
@@ -135,12 +135,19 @@
 Test
-JaJP
+PhoneNumber
 (uni
@@ -265,25 +265,12 @@
 = Fa
-ctory.create('ja'
+ker(
 )%0A%0A 
@@ -341,16 +341,182 @@
 number()
+%0A%0A        assert pn%0A        assert isinstance(pn, string_types)%0A%0A    def test_phone_number_ja(self):%0A        factory = Faker('ja')%0A        pn = factory.phone_number()
 %0A       
@@ -1074,158 +1074,220 @@
 ts%0A%0A
-%0Aclass TestMSISDN(unittest.TestCase):%0A    %22%22%22 Tests MSISDN in the pt_br locale %22%22%22%0A%0A    def setUp(self):%0A        self.factory = Factory.create('pt_br'
+    def test_msisdn(self):%0A        msisdn = self.factory.msisdn()%0A%0A        assert msisdn is not None%0A        assert isinstance(msisdn, string_types)%0A        assert len(msisdn) == 13%0A        assert msisdn.isdigit(
 )%0A%0A 
@@ -1300,32 +1300,38 @@
  test_msisdn
+_pt_br
 (self):%0A
         msis
@@ -1310,32 +1310,65 @@
 dn_pt_br(self):%0A
+        factory = Faker('pt_br')%0A
         msisdn =
@@ -1360,37 +1360,32 @@
        msisdn = 
-self.
 factory.msisdn()

refactor phone number tests