def test_invalid_amount_create_money_transfer(self): # Create account for sender request = self.factory.post('/create-account/', data={ 'holder': 'Arisha Barron', 'balance': '1000', }) request.user = AnonymousUser() response = AccountViewSet.as_view({'post': 'create'})(request) # Create an account for receiver request = self.factory.post('/create-account/', data={ 'holder': 'Branden Gibson', 'balance': '1000', }) request.user = AnonymousUser() response = AccountViewSet.as_view({'post': 'create'})(request) # Create an instance of POST - create money transfer request = self.factory.post('/create-transfer/', data={ 'sender': '1', 'receiver': '2', 'amount': '-1500', }) # Create an anonymous user request.user = AnonymousUser() # Testing MoneyTransferViewSet response = MoneyTransferViewSet.as_view({'post': 'create'})(request) self.assertEqual(response.status_code, 400)
def test_same_customer_create_money_transfer(self): """ Same customer, different accounts situation """ # Create account for sender request = self.factory.post('/create-account/', data={ 'holder': 'Arisha Barron', 'balance': '1000', }) request.user = AnonymousUser() response = AccountViewSet.as_view({'post': 'create'})(request) # Create an account for receiver request = self.factory.post('/create-account/', data={ 'holder': 'Arisha Barron', 'balance': '1000', }) request.user = AnonymousUser() response = AccountViewSet.as_view({'post': 'create'})(request) # Create an instance of POST - create money transfer request = self.factory.post('/create-transfer/', data={ 'sender': '1', 'receiver': '2', 'amount': '500', }) # Create an anonymous user request.user = AnonymousUser() # Testing MoneyTransferViewSet response = MoneyTransferViewSet.as_view({'post': 'create'})(request) self.assertEqual(response.status_code, 201)
def test_account_retreive_action(self): # Create account for sender request = self.factory.post('/create-account/', data={ 'holder': 'Arisha Barron', 'balance': '1000', }) request.user = AnonymousUser() response = AccountViewSet.as_view({'post': 'create'})(request) # Create an account for receiver request = self.factory.post('/create-account/', data={ 'holder': 'Branden Gibson', 'balance': '1000', }) request.user = AnonymousUser() response = AccountViewSet.as_view({'post': 'create'})(request) # Create an action as sender request = self.factory.post('/create-transfer/', data={ 'sender': '1', 'receiver': '2', 'amount': '500', }) request.user = AnonymousUser() response = MoneyTransferViewSet.as_view({'post': 'create'})(request) # Create an action as receiver request = self.factory.post('/create-transfer/', data={ 'sender': '1', 'receiver': '2', 'amount': '500', }) request.user = AnonymousUser() response = MoneyTransferViewSet.as_view({'post': 'create'})(request) # Create a GET request to retreive transfer history request = self.factory.get('/retrieve-action/', data={ 'account_id': '1', }) # Create an anonymous user request.user = AnonymousUser() # Testing ActionViewSet response = ActionViewSet.as_view({'get': 'list'})(request) self.assertEqual(response.status_code, 200)
def test_invalid_customer_create_account(self): # Create an instance of POST - create account request = self.factory.post('/create-account/', data={ 'holder': 'Michael Scott', 'balance': '10000', }) # Create an anonymous user request.user = AnonymousUser() # Testing AccountViewSet response = AccountViewSet.as_view({'post': 'create'})(request) self.assertEqual(response.status_code, 400)
def test_customer_create_another_account(self): # Create the first account of customer request = self.factory.post('/create-account/', data={ 'holder': 'Arisha Barron', 'balance': '1000', }) request.user = AnonymousUser() response = AccountViewSet.as_view({'post': 'create'})(request) # Create an instance of POST - create account request = self.factory.post('/create-account/', data={ 'holder': 'Arisha Barron', 'balance': '1000', }) # Create an anonymous user request.user = AnonymousUser() # Testing AccountViewSet response = AccountViewSet.as_view({'post': 'create'})(request) self.assertEqual(response.status_code, 201)
def get_account_list_response(self, user, data=None): """ Generate a response for a get-list on the AccountViewSet. Args: user (User): Django auth user performing the request data (dict): optional data to use as query params Returns: Response: the generated response for this request """ request = self.factory.get("/accounts/", data) force_authenticate(request, user=user) view = AccountViewSet.as_view(actions={"get": "list"}) response = view(request) return response
def get_account_get_response(self, user, account_id): """ Generate a response for a get-retrieve on the AccountViewSet. Args: user (User): Django auth user performing the request account_id (int): the id of the account to retrieve data (dict): optional data to use as query params Returns: Response: the generated response for this request """ request = self.factory.get("/accounts/") force_authenticate(request, user=user) view = AccountViewSet.as_view(actions={"get": "retrieve"}) response = view(request, pk=account_id) return response
def test_account_check_balance(self): # Create an account to check balance request = self.factory.post('/create-account/', data={ 'holder': 'Arisha Barron', 'balance': '1000', }) request.user = AnonymousUser() response = AccountViewSet.as_view({'post': 'create'})(request) # Create an instance of GET - checking balance request = self.factory.get('/check-balance/', data={ 'account_id': '1', }) # Create an anonymous user request.user = AnonymousUser() # Testing BalanceViewSet response = BalanceViewSet.as_view({'get': 'list'})(request) self.assertEqual(response.status_code, 200)