def test_get_transaction_dtos_with_valid_details_return_dtos( create_users, create_transactions): # Arrange user_id = 1 transaction1 = TransactionDto(transaction_id=111111, user_id=1, date=datetime.datetime( 2020, 10, 10, 0, 0, 0), amount=100, status="APPROVED", payment_type="PHONE_PAY", transaction_type="CREDITED", screen_shot="12/12", remark="wallet") transaction2 = TransactionDto(transaction_id=222222, user_id=1, date=datetime.datetime( 2020, 10, 10, 0, 0, 0), amount=200, status="PENDING", payment_type="GOOGLE_PAY", transaction_type="CREDITED", screen_shot="12/12", remark="snacks") expected_transaction_dtos = [transaction1, transaction2] storage = UserStorageImplementation() # Act actual_transaction_dtos = storage.get_transaction_dtos(user_id=user_id) # Assert assert actual_transaction_dtos == expected_transaction_dtos
def test_create_transaction_request_db_with_valid_details_create_request( create_users): # Arrange user_id = 1 transaction_id = 333333 amount_paid = 100 payment_type = PaymentTypeEnum.PAYTM.value transaction_screenshot = "urls/photo.png" status = TransactionStatusEnum.PENDING.value transaction_request_dto = TransactionRequestDto( amount_paid=amount_paid, transaction_id=transaction_id, payment_type=payment_type, transaction_screenshot=transaction_screenshot) storage = UserStorageImplementation() # Act actual_transaction_dtos = storage.create_transaction_request_db( user_id=user_id, transaction_request_dto=transaction_request_dto) # Assert transaction_obj = Transaction.objects.get(transaction_id=transaction_id) assert transaction_obj.transaction_id == transaction_id assert transaction_obj.user_id == user_id assert transaction_obj.amount == amount_paid assert transaction_obj.payment_type == payment_type assert transaction_obj.status == status assert transaction_obj.screen_shot == transaction_screenshot
def test_validate_password_with_invalid_details(create_users): # Arrange invalid_password = "******" storage = UserStorageImplementation() # Act with pytest.raises(InvalidPassword): storage.validate_password(password=invalid_password)
def test_validate_username_with_invalid_details(create_users): # Arrange invalid_username = 98765 password = "******" storage = UserStorageImplementation() # Act with pytest.raises(InvalidUsername): storage.validate_username(username=invalid_username, password=password)
def test_is_valid_payment_with_invalid_payment_return_false(): # Arrange invalid_payment = -10 storage = UserStorageImplementation() # Act is_valid_payment = storage.is_valid_payment(amount=invalid_payment) # Assert assert is_valid_payment is False
def test_is_valid_payment_with_valid_payment_return_true(): # Arrange invalid_payment = 100 storage = UserStorageImplementation() # Act is_valid_payment = storage.is_valid_payment(amount=invalid_payment) # Assert assert is_valid_payment is True
def test_get_account_dto(create_account): # Arrange expected_account_dto = AccountDetailsDto(upi_id="1234567890@SBI", account_holder="") storage = UserStorageImplementation() # Act actual_account_dto = storage.get_admin_account_dto() # Assert assert actual_account_dto == expected_account_dto
def test_validate_password_with_valid_details(create_users): # Arrange password = "******" storage = UserStorageImplementation() # Act storage.validate_password(password=password) # Assert is_valid_password = User.objects.filter(password=password).exists() assert is_valid_password is True
def test_is_username_already_exists_with_existed_username_return_true( create_users): # Arrange existed_username = "******" storage = UserStorageImplementation() # Act is_username_already_exists = storage.is_username_already_exists( username=existed_username) # Assert assert is_username_already_exists is True
def test_is_username_already_exists_with_not_existed_username_return_false( create_users): # Arrange not_existed_username = "******" storage = UserStorageImplementation() # Act is_username_already_exists = storage.is_username_already_exists( username=not_existed_username) # Assert assert is_username_already_exists is False
def test_is_transaction_id_exists_with_existed_transaction_id_return_true( create_users, create_transactions): # Arrange transaction_id = 111111 storage = UserStorageImplementation() # Act is_transaction_already_exists = storage.is_transaction_id_exists( transaction_id=transaction_id) # Assert assert is_transaction_already_exists is True
def test_validate_username_with_valid_details_return_user_id(create_users): # Arrange username = "******" password = "******" storage = UserStorageImplementation() # Act actual_user_id = storage.validate_username(username=username, password=password) # Assert user_obj = User.objects.get(id=actual_user_id) user_id = user_obj.id assert actual_user_id == user_id assert user_obj.username == username assert user_obj.password == password
def api_wrapper(*args, **kwargs): user_storage = UserStorageImplementation() user_presenter = UserPresenterImplementation() interactor = GetAdminAccountDetailsInteractor( user_storage=user_storage, user_presenter=user_presenter) upi_id_dict = interactor.get_admin_account_details() upi_id_dict_json = json.dumps(upi_id_dict) response_data = HttpResponse(upi_id_dict_json, status=200) return response_data
def api_wrapper(*args, **kwargs): user = kwargs["user"] user_id = user.id transaction_dict = kwargs["request_data"] user_storage = UserStorageImplementation() user_presenter = UserPresenterImplementation() interactor = CreateTransactionRequestInteractor( user_storage=user_storage, user_presenter=user_presenter) interactor.create_transaction_request(user_id=user_id, transaction_dict=transaction_dict) response_data = HttpResponse(status=201) return response_data
def api_wrapper(*args, **kwargs): user = kwargs["user"] user_id = user.id user_storage = UserStorageImplementation() user_presenter = UserPresenterImplementation() interactor = GetUserTransactionsInteractor(user_storage=user_storage, user_presenter=user_presenter) transaction_details_dict = interactor.get_user_transactions( user_id=user_id) transaction_details_dict_json = json.dumps(transaction_details_dict) response_data = HttpResponse(transaction_details_dict_json, status=200) return response_data
def api_wrapper(*args, **kwargs): request_data = kwargs["request_data"] username = request_data["username"] password = request_data["password"] user_storage = UserStorageImplementation() user_presenter = UserPresenterImplementation() oauth2_storage = OAuth2SQLStorage() interactor = UserLoginInteractor(user_storage=user_storage, user_presenter=user_presenter, oauth2_storage=oauth2_storage) access_token_dict = interactor.user_login(username=username, password=password) access_token_dict_json = json.dumps(access_token_dict) response = HttpResponse(access_token_dict_json, status=200) return response
def api_wrapper(*args, **kwargs): request_data = kwargs["request_data"] name = request_data["name"] username = request_data["username"] password = request_data["password"] user_storage = UserStorageImplementation() user_presenter = UserPresenterImplementation() oauth2_storage = OAuth2SQLStorage() interactor = CreateUserSignUpInteractor(user_storage=user_storage, user_presenter=user_presenter, oauth2_storage=oauth2_storage) access_tocken_dict = interactor.create_signup(name=name, username=username, password=password) access_tocken_dict_json = json.dumps(access_tocken_dict) response_data = HttpResponse(access_tocken_dict_json, status=201) return response_data