def test_provide_incorrect_iso_code(self):
        param_str_incorrect_country = '{"country":"AB", "language":"en", "topic": "entertainment"}'
        self.assertEqual(
            len(
                config_helper.retrieve_urls_using_json(
                    param_str_incorrect_country)), 0)

        param_str_incorrect_language = '{"country":"AB", "language":"jk", "topic": "entertainment"}'
        self.assertEqual(
            len(
                config_helper.retrieve_urls_using_json(
                    param_str_incorrect_language)), 0)

        param_str_incorrect_country_and_language = '{"country":"AB", "language":"jk", "topic": "entertainment"}'
        self.assertEqual(
            len(
                config_helper.retrieve_urls_using_json(
                    param_str_incorrect_country_and_language)), 0)
Example #2
0
def publish_config_handler(event, context):
    """ If lambda environment variable is set to read from os.environ, if not read from DDB """
    if os.environ.get("CONFIG_PARAM", None):
        """
        This condition is executed if the config is setup through lambda environment variable. This allows for
        only 1 configuration item to be created with a query parameter
        """
        url_list = config_helper.retrieve_urls_using_json(
            os.environ["CONFIG_PARAM"])
        logger.debug(f"Print url list: {url_list}")
        config_event = ConfigEvent(platform="newsfeeds",
                                   account="url_params",
                                   query=os.environ["SEARCH_QUERY"],
                                   url_list=url_list)
        event_bus_helper.publish_config(config_event)

        logger.debug(f"Event published is: {config_event}")
    else:
        """
        If the lambda environment variable is not set, it will look for configuration in the dynamodb table
        """
        config_list = ddb_helper.get_config()
        for item in config_list:

            url_list = config_helper.retrieve_urls(
                country=item.get("country", None),
                language=item.get("language", None),
                topic=item.get("topic", None))

            config_event = ConfigEvent(platform=item["platform"],
                                       account=item["account"],
                                       query=item["query"],
                                       url_list=url_list)
            event_bus_helper.publish_config(config_event)

            logger.debug(f"Event published is: {config_event}")
 def test_retrieve_urls_to_log_exception_and_return_none(self):
     param_str = '{"country":"ABC", "language":"en", "topic": "entertainment"}'
     with self.assertRaises(TypeError):
         config_helper.retrieve_urls_using_json(param_str)
 def test_retrieve_urls_with_topic(self):
     param_str = '{"country":"US", "language":"en", "topic": "entertainment"}'
     self.assertListEqual(config_helper.retrieve_urls_using_json(param_str),
                          ["ew.com"])
 def test_retrieve_urls_with_no_urls(self):
     param_str = '{"country":"US", "language":"es"}'
     self.assertIsNone(config_helper.retrieve_urls_using_json(param_str))
 def test_retrieve_urls_with_json_str(self):
     param_str = '{"country":"CA", "language":"fr"}'
     self.assertListEqual(config_helper.retrieve_urls_using_json(param_str),
                          ["lapresse.ca"])
     self.assertEqual(
         len(config_helper.retrieve_urls_using_json(param_str)), 1)