write test method + fix

main
Laurent 8 months ago
parent 17de97d987
commit ad0b677b56
  1. 2
      README.md
  2. 2
      subscriptions/urls.py
  3. 34
      subscriptions/views.py

@ -1,2 +1,4 @@
# pokeranalytics_backend # pokeranalytics_backend
CRITIQUE!
Sur le serveur alwaysdata, toutes les commandes python utilisent la commande python3.12

@ -6,5 +6,5 @@ urlpatterns = [
path("", views.index, name="index"), path("", views.index, name="index"),
path('app-store-webhook/', views.app_store_webhook, name='app_store_webhook'), path('app-store-webhook/', views.app_store_webhook, name='app_store_webhook'),
# path('app-store-webhook-prod/', views.app_store_webhook_prod, name='app_store_webhook_prod'), # path('app-store-webhook-prod/', views.app_store_webhook_prod, name='app_store_webhook_prod'),
# path('test/', views.test, name='test'), path('test/', views.test, name='test'),
] ]

@ -26,6 +26,30 @@ g6_cert_bytes: bytes = requests.get(G6_CER_URL).content
def index(request): def index(request):
return HttpResponse("Hello, world. You're at the subs index.") return HttpResponse("Hello, world. You're at the subs index.")
@csrf_exempt
def test(request):
try:
# Construct the path to payload.txt at the root of the Django project
payload_file_path = os.path.join(settings.BASE_DIR, 'payload.txt')
# Read the content of the file
with open(payload_file_path, 'r') as file:
payload_content = file.read()
# Call save_payload_file with the content
save_payload_file(payload_content)
# Return success response
return JsonResponse({'status': 'success', 'message': 'Payload processed successfully'})
except FileNotFoundError:
return JsonResponse({'status': 'error', 'message': 'payload.txt file not found'}, status=404)
except Exception as e:
# Log the exception
logging.error(f"Error in test endpoint: {str(e)}")
return JsonResponse({'status': 'error', 'message': str(e)}, status=500)
# @csrf_exempt # @csrf_exempt
# def app_store_webhook_prod(request): # def app_store_webhook_prod(request):
@ -92,12 +116,12 @@ def decodePayload(signedPayload):
revocationDateTime = datetime.datetime.fromtimestamp(transaction_info.revocationDate / 1000) revocationDateTime = datetime.datetime.fromtimestamp(transaction_info.revocationDate / 1000)
offer_type = None offer_type = None
if payload.offerType is not None: if transaction_info.offerType is not None:
offer_type = int(payload.offerType) offer_type = int(transaction_info.offerType)
offer_discount_type = None offer_discount_type = None
if payload.offerDiscountType is not None: if transaction_info.offerDiscountType is not None:
offer_discount_type = payload.offerDiscountType.value offer_discount_type = transaction_info.offerDiscountType.value
notification = ASSNotification( notification = ASSNotification(
notificationType=payload.notificationType, notificationType=payload.notificationType,
@ -118,7 +142,7 @@ def decodePayload(signedPayload):
transactionId=transaction_info.transactionId, transactionId=transaction_info.transactionId,
transactionReason=transaction_info.rawTransactionReason, transactionReason=transaction_info.rawTransactionReason,
offerDiscountType=offer_discount_type, offerDiscountType=offer_discount_type,
offerIdentifier=payload.offerIdentifier, offerIdentifier=transaction_info.offerIdentifier,
offerType=offer_type, offerType=offer_type,
) )
notification.save() notification.save()

Loading…
Cancel
Save