Exemplo n.º 1
0
 def test_can_get_passphrase(self):
     # Test if passphrase can be retrieved from settings
     self.assertEqual(get_config().get_passphrase(), PAYFAST_PASSPHRASE,
                      "Unable to get passphrase from settings")
     # Unset passphrase
     del settings.PAYFAST_PASSPHRASE
     # Test if passphrase is None when not set in settings
     self.assertIsNone(get_config().get_passphrase(),
                       "Passphrase does not default to none if")
Exemplo n.º 2
0
    def test_can_get_merchant_key(self):
        # Return the merchant key from the settings module
        self.assertEqual(get_config().get_merchant_key(), PAYFAST_MERCHANT_KEY,
                         "Unable to retrieve merchant key from settings")

        # Remove PAYFAST_MERCHANT_KEY and PAYFAST_MERCHANT_ID from settings
        del settings.PAYFAST_MERCHANT_KEY
        del settings.PAYFAST_MERCHANT_ID

        # Return the development key if PAYFAST_MERCHANT_KEY is not present in settings
        self.assertEqual(
            get_config().get_merchant_key(), Constants.MERCHANT_KEY_DEV,
            "Cannot retrieve default development merchant key from Constants")
Exemplo n.º 3
0
    def test_can_get_merchant_id(self):
        # Return the merchant id from the settings module
        self.assertEqual(get_config().get_merchant_id(), PAYFAST_MERCHANT_ID,
                         "Unable to retrieve merchant id from settings")

        # Remove the merchant id from settings
        del settings.PAYFAST_MERCHANT_ID
        del settings.PAYFAST_MERCHANT_KEY

        # Return the development id if setting is not present in settings
        self.assertEqual(
            get_config().get_merchant_id(), Constants.MERCHANT_ID_DEV,
            "Cannot retrieve default development merchant id from Constants")
Exemplo n.º 4
0
    def test_can_get_ip_address_header(self):
        # Test if header can be retrieved from settings
        self.assertEqual(get_config().get_ip_address_header(),
                         PAYFAST_IP_ADDRESS_HTTP_HEADER,
                         "Unable to get http header from settings")

        # Remove https header from settings
        del settings.PAYFAST_IP_ADDRESS_HTTP_HEADER

        # Test if header is 'REMOTE_ADDR' when http header is not set
        self.assertEqual(
            get_config().get_ip_address_header(), 'REMOTE_ADDR',
            "Unable to get default http header REMOTE_ADDR if not in settings")
Exemplo n.º 5
0
    def test_can_detect_incorrect_settings_configuration(self):

        # Both settings should not raise an exception
        try:
            get_config()
        except ImproperlyConfigured:
            self.fail("get_config() raised ImproperlyConfigured unexpectedly!")

        # Remove the merchant key setting
        del settings.PAYFAST_MERCHANT_KEY

        # Test for exception raised by only setting PAYFAST_MERCHANT_ID
        with self.assertRaises(ImproperlyConfigured):
            get_config()

        # Remove the merchant id setting
        del settings.PAYFAST_MERCHANT_ID

        # Absence of both merchant id and merchant key should not raise an exception
        try:
            get_config()
        except ImproperlyConfigured:
            self.fail("get_config() raised ImproperlyConfigured unexpectedly!")

        # Set PAYFAST_MERCHANT_KEY
        settings.PAYFAST_MERCHANT_KEY = PAYFAST_MERCHANT_KEY

        # Test for exception raised by only setting PAYFAST_MERCHANT_KEY
        with self.assertRaises(ImproperlyConfigured):
            get_config()
Exemplo n.º 6
0
    def test_can_get_action_url(self):
        # Return live server url if merchant key and id are set
        self.assertEqual(
            get_config().get_action_url(), Constants.ACTION_URL_LIVE,
            'Cannot get live server url when merchant key and id are set')

        # Remove PAYFAST_MERCHANT_KEY and PAYFAST_MERCHANT_ID from settings
        del settings.PAYFAST_MERCHANT_KEY
        del settings.PAYFAST_MERCHANT_ID

        # Return development server url if merchant key and id are NOT set
        self.assertEqual(
            get_config().get_action_url(), Constants.ACTION_URL_DEV,
            "Cannot get development server url when merchant key and id are NOT set"
        )