Ejemplo n.º 1
0
    def test_publish_config_with_topic(self):
        event_id = "fakeeventid"
        failed_count = 0
        url_list = []
        topic = "tech"

        for loop_index in range(2):
            url = f"fakeurl{loop_index}.com"
            data = create_event_data(url, topic=topic)

            url_list.append(url)

            expected_params = create_expected_params(data)
            response = {
                "Entries": [{"EventId": event_id}],
                "FailedEntryCount": failed_count,
            }
            self.stubber.add_response("put_events", response, expected_params)

        self.stubber.activate()

        config_event = ConfigEvent(
            platform="fakeplatform", account="fakeaccount", query="fakequery", url_list=url_list, topic=topic
        )
        self.assertIsNone(publish_config(config_event, event_bus=self.event_bus))
Ejemplo n.º 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}")
Ejemplo n.º 3
0
    def test_publish_config_with_failures(self):
        failed_count = 1

        for loop_index in range(2):
            data = create_event_data(f"fakeurl{loop_index}.com")
            expected_params = create_expected_params(data)

            response = {"FailedEntryCount": failed_count}
            self.stubber.add_response("put_events", response, expected_params)

        self.stubber.activate()

        config_event = ConfigEvent(
            platform="fakeplatform", account="fakeaccount", query="fakequery", url_list=["fakeurl0.com", "fakeurl1.com"]
        )
        self.assertIsNone(publish_config(config_event, event_bus=self.event_bus))
Ejemplo n.º 4
0
    def test_fail_event_bus(self):
        url = "fakeurl4.com"
        data = create_event_data(url)

        expected_params = create_expected_params(data)
        self.stubber.add_client_error(
            "put_events",
            service_error_code="",
            service_message="",
            http_status_code=400,
            expected_params=expected_params,
        )

        self.stubber.activate()

        config_event = ConfigEvent(platform="fakeplatform", account="fakeaccount", query="fakequery", url_list=[url])
        with self.assertRaises(ClientError):
            self.assertIsNone(publish_config(config_event, event_bus=self.event_bus))
Ejemplo n.º 5
0
 def test_no_stubber(self):
     config_event = ConfigEvent(
         platform="fakeplatform", account="fakeaccount", query="fakequery", url_list=["fakeurl5.com"]
     )
     with self.assertRaises(ClientError):
         publish_config(config_event)