-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
38 lines (30 loc) · 1.24 KB
/
conftest.py
File metadata and controls
38 lines (30 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from datetime import datetime
import boto3
import pytest
from botocore.exceptions import ClientError
ENDPOINT_URL = 'http://localhost:4566'
@pytest.fixture
def init_bucket():
s3_client = boto3.client("s3",
aws_access_key_id='mock',
aws_secret_access_key='mock',
region_name='us-east-1',
endpoint_url=ENDPOINT_URL)
try:
response = s3_client.create_bucket(Bucket="raw")
response = s3_client.create_bucket(Bucket="bronze")
except ClientError as ce:
print("Could not create S3 bucket.")
raise ce
filename = os.path.join(os.path.dirname(__file__), '7e0d748b-17f3-389b-a8aa-3990bf2bb4e2-2023-01-06T07_20_51.csv')
try:
timestamp = datetime.now()
partition_str = f"year={timestamp.strftime('%Y')}/month={timestamp.strftime('%m')}/day={timestamp.strftime('%d')}"
response = s3_client.\
upload_file(filename,
"raw", f"input/{partition_str}/7e0d748b-17f3-389b-a8aa-3990bf2bb4e2-2023-01-06T07_20_51.csv")
except ClientError as ce:
print("Could not upload file to S3 bucket.")
raise ce
print("file upload to s3")