Skip to content

Commit

Permalink
lint and move test class
Browse files Browse the repository at this point in the history
  • Loading branch information
WillNilges committed Nov 3, 2024
1 parent 1ad41d1 commit fbf8256
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 37 deletions.
20 changes: 14 additions & 6 deletions src/meshapi/tests/test_replay_join_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
from django.test import TestCase

from meshapi.models.install import Install
from meshapi.util.join_records import (
JOIN_RECORD_BASE_NAME,
JoinRecord,
MockJoinRecordProcessor,
s3_content_to_join_record,
)
from meshapi.util.join_records import JOIN_RECORD_BASE_NAME, JoinRecord, s3_content_to_join_record


class MockJoinRecordProcessor:
def __init__(self, data: dict[str, JoinRecord]) -> None:
self.bucket_name: str = "mock_bucket"
# Store join record by S3 key and value.
self.bucket: dict[str, JoinRecord] = data

def upload(self, join_record: JoinRecord, key: str) -> None:
self.bucket[key] = join_record

def get_all(self) -> list[JoinRecord]:
return list(self.bucket.values())


# Integration test to ensure that we can fetch JoinRecords from an S3 bucket,
Expand Down
34 changes: 3 additions & 31 deletions src/meshapi/util/join_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import os
import tempfile
from abc import ABC, abstractmethod
from dataclasses import dataclass, fields
from typing import Optional

Expand Down Expand Up @@ -41,27 +40,13 @@ def s3_content_to_join_record(object_key: str, content: str) -> JoinRecord:
return join_record


class JoinRecordProcessorInterface(ABC):
@abstractmethod
def __init__(self) -> None:
pass

@abstractmethod
def upload(self, join_record: JoinRecord, key: str) -> None:
pass

@abstractmethod
def get_all(self) -> list[JoinRecord]:
pass


class JoinRecordProcessor(JoinRecordProcessorInterface):
class JoinRecordProcessor:
def __init__(self) -> None:
self.s3_client = boto3.client(
"s3",
endpoint_url=JOIN_RECORD_ENDPOINT,
#aws_access_key_id=JOIN_RECORD_ACCESS_KEY,
#aws_secret_access_key=JOIN_RECORD_SECRET_KEY,
# aws_access_key_id=JOIN_RECORD_ACCESS_KEY,
# aws_secret_access_key=JOIN_RECORD_SECRET_KEY,
config=Config(signature_version="s3v4"), # Ensure S3 signature v4 is used
)

Expand Down Expand Up @@ -91,16 +76,3 @@ def get_all(self) -> list[JoinRecord]:
print("Bucket is empty or does not exist.")

return join_records


class MockJoinRecordProcessor(JoinRecordProcessorInterface):
def __init__(self, data: dict[str, JoinRecord]) -> None:
self.bucket_name: str = "mock_bucket"
# Store join record by S3 key and value.
self.bucket: dict[str, JoinRecord] = data

def upload(self, join_record: JoinRecord, key: str) -> None:
self.bucket[key] = join_record

def get_all(self) -> list[JoinRecord]:
return list(self.bucket.values())

0 comments on commit fbf8256

Please sign in to comment.