Пример #1
0
 def test_verify_response_status_is_true(self, auth_mock, verify_mock):
     auth_json = {
         'status': True,
         'message': 'Authorization URL created',
         'data': {
             'authorization_url':
             'https://checkout.paystack.com/9mzlnrn30akanzp',
             'access_code': '9mzlnrn30akanzp',
             'reference': 'yzlei4h480'
         }
     }
     verify_json = {
         "status": True,
         "message": "Verification successful",
         "data": {
             "amount": 27000,
             "currency": "NGN",
             "transaction_date": "2020-10-01T11:03:09.000Z",
             "status": "success",
             "reference": "yzlei4h480",
             "domain": "test",
             "metadata": 0,
             "gateway_response": "Successful",
             "message": None,
             "channel": "card"
         }
     }
     auth_mock.return_value.json.return_value = auth_json
     verify_mock.return_value.json.return_value = verify_json
     auth_response = authorize(self.passenger, 27000)
     reference = auth_response['data'].get("reference")
     verify_response = verify(self.passenger, reference)
     self.assertTrue(verify_response.get('status'))
Пример #2
0
    def test_paystack_verification_response_keys(self):
        auth_response = authorize(self.passenger, 27000)
        auth_url = auth_response['data'].get('authorization_url')
        response = requests.get(auth_url)
        reference = auth_response['data'].get('reference')
        verify_response = verify(self.passenger, reference)
        verify_keys = verify_response.keys()
        with patch('main.paystack_api.requests.get') as verify_mock:
            verify_json = {
                "status": True,
                "message": "Verification successful",
                "data": {
                    "amount": 27000,
                    "currency": "NGN",
                    "transaction_date": "2020-10-01T11:03:09.000Z",
                    "status": "success",
                    "reference": "DG4uishudoq9OLD",
                    "domain": "test",
                    "metadata": 0,
                    "gateway_response": "Successful",
                    "message": None,
                    "channel": "card"
                }
            }
            verify_mock.return_value.json.return_value = verify_json
            mocked_keys = verify_json.keys()

        print(list(verify_keys))
        print(list(mocked_keys))
        self.assertListEqual(list(verify_keys), list(mocked_keys))
Пример #3
0
    def form_valid(self, form):
        auth_response = authorize(self.request.user,
                                  form.cleaned_data.get('amount', 0))
        if auth_response is not None:
            return redirect(auth_response['data'].get('authorization_url'))

        messages.add_message(
            self.request, messages.ERROR,
            "An Error Occured, Paystack cannot be reached at this time")
        return self.render_to_response(self.get_context_data())
Пример #4
0
 def test_account_is_not_funded_if_status_is_false(self, auth_mock):
     auth_json = {
         'status': False,
         'message': 'Some error',
         'data': {
             'authorization_url': 'not avaliable',
             'access_code': 'not avaliable',
             'reference': 'not avaliable'
         }
     }
     auth_mock.return_value.json.return_value = auth_json
     auth_response = authorize(self.passenger,
                               fake.random_int(min=100, max=10000))
     self.assertEqual(self.passenger.account_balance, self.old_balance)
Пример #5
0
    def test_auth_response_status_is_true(self, auth_mock):
        auth_json = {
            'status': True,
            'message': 'Authorization URL created',
            'data': {
                'authorization_url':
                'https://checkout.paystack.com/9mzlnrn30akanzp',
                'access_code': '9mzlnrn30akanzp',
                'reference': 'yzlei4h480'
            }
        }

        auth_mock.return_value.json.return_value = auth_json
        auth_response = authorize(user=self.passenger,
                                  amount=fake.random_int(min=1000, max=5000))
        self.assertTrue(auth_response.get('status'))
Пример #6
0
    def test_paystack_initialization_response_keys(self):
        auth_response = authorize(self.passenger,
                                  fake.random_int(min=200, max=3000))
        auth_keys = auth_response.keys()
        with patch('main.paystack_api.requests.post') as auth_mock:
            auth_json = {
                'status': True,
                'message': 'Authorization URL created',
                'data': {
                    'authorization_url':
                    'https://checkout.paystack.com/9mzlnrn30akanzp',
                    'access_code': '9mzlnrn30akanzp',
                    'reference': 'yzlei4h480'
                }
            }
            auth_mock.return_value.json.return_value = auth_json
            mocked_keys = auth_json.keys()

        print(list(auth_keys))
        print(list(mocked_keys))
        self.assertListEqual(list(auth_keys), list(mocked_keys))
Пример #7
0
    def test_auth_returns_none_if_response_not_ok(self, auth_mock):
        auth_mock.return_value = Mock(ok=False)
        auth_response = authorize(self.passenger,
                                  fake.random_int(min=100, max=2000))

        self.assertEqual(auth_response, None)
Пример #8
0
 def test_auth_returns_none_if_unseccessful_request(self):
     auth_response = authorize(self.passenger,
                               fake.random_int(min=100, max=4000))
     self.assertEqual(auth_response, None)