示例#1
0
    def test_run_several_ids(self, m_status, m_coinmarketcap) -> None:
        m_coinmarketcap.return_value = TestTweets.build_coinmarket_response()
        s3_utils.create_bucket(TestTweets.bucket)
        test_file_path = os.path.join(dir_path, "resources",
                                      "test_tweets_successfully.json")
        test_file = TestTweets.read_local_object(test_file_path)
        s3_utils.put_s3_object(test_file, TestTweets.bucket, TestTweets.key)

        os.environ["TWITTER_TOKEN"] = TestTweets.twitter_token
        os.environ["COINMARKETCAP_TOKEN"] = TestTweets.coinmarketcap_token
        os.environ["SKIPTWEET"] = "False"

        conn = boto3.client("secretsmanager")
        twitter_keys = {
            "app_key": "app-key",
            "app_secret": "app_secret",
            "oauth_token": "oauth_token",
            "oauth_token_secret": "oauth_token_secret",
        }
        conn.create_secret(Name=TestTweets.twitter_token,
                           SecretString=json.dumps(twitter_keys))
        conn.create_secret(Name=TestTweets.coinmarketcap_token,
                           SecretString="some-key")
        tweets.lambda_handler(
            event=TestTweets.build_event(bucket=TestTweets.bucket,
                                         key=TestTweets.key),
            context=None,
        )
    def test_lambda_handler_write_if_destination_does_exist(self) -> None:

        # os.environ["AWS_PROFILE"] = "serverless"
        os.environ["DESTINATION_BUCKET"] = TestFilterForNewcomers.bucket
        os.environ["DESTINATION_KEY"] = TestFilterForNewcomers.destination_key
        s3_utils.create_bucket(TestFilterForNewcomers.bucket)
        test_file_path = os.path.join(dir_path, "resources",
                                      "test_filter_for_newcomers.json")
        test_file = TestFilterForNewcomers.read_local_object(test_file_path)
        s3_utils.put_s3_object(test_file, TestFilterForNewcomers.bucket,
                               TestFilterForNewcomers.source_key)
        filter_for_newcomers.lambda_handler(
            event=TestFilterForNewcomers.build_event(
                bucket=TestFilterForNewcomers.bucket,
                key=TestFilterForNewcomers.source_key),
            context=None,
        )
        filter_for_newcomers.lambda_handler(
            event=TestFilterForNewcomers.build_event(
                bucket=TestFilterForNewcomers.bucket,
                key=TestFilterForNewcomers.source_key),
            context=None,
        )
        df = wr.s3.read_parquet(
            build_s3_url(TestFilterForNewcomers.bucket,
                         TestFilterForNewcomers.destination_key))
        self.assertListEqual(df.columns.tolist(), ['id', 'rank', 'uuid'])
        self.assertEqual(df.shape, (400, 3))
示例#3
0
    def test_handler(self):
        os.environ[
            S3Enums.DESTINATION_BUCKET.name] = S3Enums.DESTINATION_BUCKET.value
        os.environ[
            S3Enums.DESTINATION_KEY.name] = S3Enums.DESTINATION_KEY.value
        create_bucket(S3Enums.DESTINATION_BUCKET.name)

        bucket, key = get_coinmarketcap_data.lambda_handler(event=None,
                                                            context=None)
        result = get_object_from_s3(bucket, key)
        result = json.loads(result)
        self.assertTrue(result.get("status"))
        self.assertEqual(len(result.get("data")), 200)
    def test_handler(self, m_max_uuid, m_latest, m_tail):
        bucket = "bucket"
        os.environ["ATHENA_DB"] = "db"
        os.environ["ATHENA_TABLE"] = "table"
        os.environ["BUCKET_DATA"] = bucket
        os.environ["KEY_DATA"] = "stg/newcomers"
        os.environ["RANK"] = '["100", "200"]'

        create_bucket(bucket)
        m_max_uuid.return_value = "1570896046"
        m_latest.return_value = ["bitcoin", "ethereum", "ripple"]
        m_tail.return_value = ["iota", "ethereum", "ripple"]
        newcomers.lambda_handler(event={}, context=None)
        objects = get_objects_in_bucket(bucket)
        key = objects[0]["Key"]
        newcomer = get_object_from_s3(bucket, key)
        self.assertTrue(newcomer, "bitcoin")