Skip to content

Commit

Permalink
implement hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
aidangannon committed Jun 18, 2023
1 parent 77e1826 commit fdfaa38
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/web/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
from src.web import PinfluencerContext, valid_path_resource_id, ErrorCapsule
from src.web.constants import AudienceAgeCacheKey, InfluencerDetailsCacheKey, AudienceGenderCacheKey
from src.web.error_capsules import AudienceDataAlreadyExistsErrorCapsule, BrandNotFoundErrorCapsule, \
InfluencerNotFoundErrorCapsule, ListingNotFoundErrorCapsule
from src.web.views import RawImageRequestDto, ImageRequestDto, ListingResponseDto, NotificationCreateRequestDto
InfluencerNotFoundErrorCapsule, ListingNotFoundErrorCapsule, BrandNotAuthorized
from src.web.views import RawImageRequestDto, ImageRequestDto, ListingResponseDto, NotificationCreateRequestDto, \
CollaborationResponseDto

S3_URL = "https://pinfluencer-product-images.s3.eu-west-2.amazonaws.com"

Expand Down Expand Up @@ -480,11 +481,16 @@ def __init__(self, repository: AudienceGenderRepository):

class CollaborationAfterHooks(SaveableHook):

def __init__(self, repository: CollaborationRepository):
def __init__(self,
repository: CollaborationRepository,
mapper: PinfluencerObjectMapper):
super().__init__(repository)
self.__mapper = mapper

def validate_brand(self, context: PinfluencerContext):
...
if context.auth_user_id != self.__mapper.map_from_dict(_from=context.response.body,
to=CollaborationResponseDto).brand_auth_user_id:
context.error_capsule = [BrandNotAuthorized(auth_user_id=context.auth_user_id)]


class AudienceAgeBeforeHooks:
Expand Down
6 changes: 4 additions & 2 deletions tests/test_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from src._types import AuthUserRepository, BrandRepository, ImageRepository, NotificationRepository, \
AudienceAgeRepository, InfluencerRepository, AudienceGenderRepository, ListingRepository, CollaborationRepository
from src.crosscutting import JsonCamelToSnakeCaseDeserializer, AutoFixture
from src.crosscutting import JsonCamelToSnakeCaseDeserializer, AutoFixture, PinfluencerObjectMapper
from src.domain.models import User, ValueEnum, CategoryEnum, AudienceAgeSplit, AudienceGenderSplit, \
AudienceAge, Listing
from src.domain.validation import InfluencerValidator, BrandValidator, ListingValidator
Expand Down Expand Up @@ -1170,7 +1170,9 @@ class TestCollaborationAfterHooks(TestCase):

def setUp(self) -> None:
self.__repo: CollaborationRepository = Mock()
self.__sut = CollaborationAfterHooks(repository=self.__repo)
self.__mapper = PinfluencerObjectMapper(logger=Mock())
self.__sut = CollaborationAfterHooks(repository=self.__repo,
mapper=self.__mapper)

def test_validate_brand_when_valid(self):
# arrange
Expand Down

0 comments on commit fdfaa38

Please sign in to comment.