def setUp(self):
     from cpsection.modemconfiguration.model import ServiceProvidersParser,\
         PROVIDERS_PATH
     self.tree = ElementTree(file=PROVIDERS_PATH)
     self.countries_from_xml = self.tree.findall('country')
     self.db = ServiceProvidersParser()
     self.countries_from_class = self.db.get_countries()
 def setUp(self):
     self.tree = ElementTree(file=PROVIDERS_PATH)
     self.countries_from_xml = self.tree.findall('country')
     self.db = ServiceProvidersParser()
     self.countries_from_class = self.db.get_countries()
class ServiceProvidersParserTest(unittest.TestCase):
    def setUp(self):
        self.tree = ElementTree(file=PROVIDERS_PATH)
        self.countries_from_xml = self.tree.findall('country')
        self.db = ServiceProvidersParser()
        self.countries_from_class = self.db.get_countries()

    def test_get_countries(self):
        for country in self.countries_from_class:
            self.assertEqual(country.tag, 'country')

    def test_get_country_idx_by_code(self):
        for idx, country in enumerate(self.countries_from_class):
            country_code = country.attrib['code']
            country_idx = self.db.get_country_idx_by_code(country_code)
            self.assertEqual(idx, country_idx)

    def test_get_country_name_by_idx(self):
        for idx, country in enumerate(self.countries_from_class):
            country_code = country.attrib['code']
            self.assertEqual(
                CountryCodeParser().get(country_code),
                self.db.get_country_name_by_idx(idx)
            )

    def test_get_providers(self):
        for country_idx, country in enumerate(self.countries_from_class):
            providers = self.db.get_providers(country_idx)
            for provider in providers:
                self.assertEqual(provider.tag, 'provider')
                self.assertIsNotNone(provider.find('.//gsm'))

    def test_get_plans(self):
        for country_idx, country in enumerate(self.countries_from_class):
            providers = self.db.get_providers(country_idx)
            for provider_idx, provider in enumerate(providers):
                plans = self.db.get_plans(country_idx, provider_idx)
                for plan in plans:
                    self.assertEqual(plan.tag, 'apn')

    def get_providers(self, country_xml):
        """Given a country element find all provider with a gsm tag."""
        idx = 0
        for provider in country_xml.findall('provider'):
            if provider.find('.//gsm'):
                yield idx, provider
                idx = idx + 1

    def get_plans(self, provider_xml):
        """Given a provider element find all apn elements."""
        for idx, plan in enumerate(provider_xml.findall('.//apn')):
            yield idx, plan

    def test_get_some_specific_values(self):
        for country in self.countries_from_xml:
            country_code = country.attrib['code']
            country_idx = self.db.get_country_idx_by_code(country_code)

            for provider_idx, provider in self.get_providers(country):
                plans_from_class = self.db.get_plans(country_idx,
                                                     provider_idx)

                for plan_idx, plan in self.get_plans(provider):
                    plan_from_class = plans_from_class[plan_idx]
                    self.assertEqual(plan.attrib['value'],
                                     plan_from_class.attrib['value'])
Example #4
0
 def setUp(self):
     self.tree = ElementTree(file=PROVIDERS_PATH)
     self.countries_from_xml = self.tree.findall('country')
     self.db = ServiceProvidersParser()
     self.countries_from_class = self.db.get_countries()
Example #5
0
class ServiceProvidersParserTest(unittest.TestCase):
    def setUp(self):
        self.tree = ElementTree(file=PROVIDERS_PATH)
        self.countries_from_xml = self.tree.findall('country')
        self.db = ServiceProvidersParser()
        self.countries_from_class = self.db.get_countries()

    def test_get_countries(self):
        for country in self.countries_from_class:
            self.assertEqual(country.tag, 'country')

    def test_get_country_idx_by_code(self):
        for idx, country in enumerate(self.countries_from_class):
            country_code = country.attrib['code']
            country_idx = self.db.get_country_idx_by_code(country_code)
            self.assertEqual(idx, country_idx)

    def test_get_country_name_by_idx(self):
        for idx, country in enumerate(self.countries_from_class):
            country_code = country.attrib['code']
            self.assertEqual(CountryCodeParser().get(country_code),
                             self.db.get_country_name_by_idx(idx))

    def test_get_providers(self):
        for country_idx, country in enumerate(self.countries_from_class):
            providers = self.db.get_providers(country_idx)
            for provider in providers:
                self.assertEqual(provider.tag, 'provider')
                self.assertIsNotNone(provider.find('.//gsm'))

    def test_get_plans(self):
        for country_idx, country in enumerate(self.countries_from_class):
            providers = self.db.get_providers(country_idx)
            for provider_idx, provider in enumerate(providers):
                plans = self.db.get_plans(country_idx, provider_idx)
                for plan in plans:
                    self.assertEqual(plan.tag, 'apn')

    def get_providers(self, country_xml):
        """Given a country element find all provider with a gsm tag."""
        idx = 0
        for provider in country_xml.findall('provider'):
            if provider.find('.//gsm'):
                yield idx, provider
                idx = idx + 1

    def get_plans(self, provider_xml):
        """Given a provider element find all apn elements."""
        for idx, plan in enumerate(provider_xml.findall('.//apn')):
            yield idx, plan

    def test_get_some_specific_values(self):
        for country in self.countries_from_xml:
            country_code = country.attrib['code']
            country_idx = self.db.get_country_idx_by_code(country_code)

            for provider_idx, provider in self.get_providers(country):
                plans_from_class = self.db.get_plans(country_idx, provider_idx)

                for plan_idx, plan in self.get_plans(provider):
                    plan_from_class = plans_from_class[plan_idx]
                    self.assertEqual(plan.attrib['value'],
                                     plan_from_class.attrib['value'])