forked from dj-stripe/dj-stripe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_api_keys.py
79 lines (71 loc) · 3.06 KB
/
test_api_keys.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from importlib import reload
from django.conf import settings
from django.test import TestCase
from django.test.utils import override_settings
from djstripe import models
from djstripe import settings as djstripe_settings
class TestCheckApiKeySettings(TestCase):
@override_settings(
STRIPE_LIVE_SECRET_KEY="sk_live_foo",
STRIPE_LIVE_PUBLIC_KEY="sk_live_foo",
STRIPE_LIVE_MODE=True,
)
def test_global_api_keys_live_mode(self):
reload(djstripe_settings)
self.assertEqual(djstripe_settings.STRIPE_LIVE_MODE, True)
self.assertEqual(djstripe_settings.STRIPE_SECRET_KEY, "sk_live_foo")
self.assertEqual(djstripe_settings.LIVE_API_KEY, "sk_live_foo")
self.assertEqual(
models.StripeModel(livemode=True).default_api_key, "sk_live_foo"
)
@override_settings(
STRIPE_TEST_SECRET_KEY="sk_test_foo",
STRIPE_TEST_PUBLIC_KEY="pk_test_foo",
STRIPE_LIVE_MODE=False,
)
def test_global_api_keys_test_mode(self):
reload(djstripe_settings)
self.assertEqual(djstripe_settings.STRIPE_LIVE_MODE, False)
self.assertEqual(djstripe_settings.STRIPE_SECRET_KEY, "sk_test_foo")
self.assertEqual(djstripe_settings.TEST_API_KEY, "sk_test_foo")
self.assertEqual(
models.StripeModel(livemode=False).default_api_key, "sk_test_foo"
)
@override_settings(
STRIPE_TEST_SECRET_KEY="sk_test_foo",
STRIPE_LIVE_SECRET_KEY="sk_live_foo",
STRIPE_TEST_PUBLIC_KEY="pk_test_foo",
STRIPE_LIVE_PUBLIC_KEY="pk_live_foo",
STRIPE_LIVE_MODE=True,
)
def test_api_key_live_mode(self):
del settings.STRIPE_SECRET_KEY, settings.STRIPE_TEST_SECRET_KEY
del settings.STRIPE_PUBLIC_KEY, settings.STRIPE_TEST_PUBLIC_KEY
reload(djstripe_settings)
self.assertEqual(djstripe_settings.STRIPE_LIVE_MODE, True)
self.assertEqual(djstripe_settings.STRIPE_SECRET_KEY, "sk_live_foo")
self.assertEqual(djstripe_settings.STRIPE_PUBLIC_KEY, "pk_live_foo")
self.assertEqual(djstripe_settings.LIVE_API_KEY, "sk_live_foo")
self.assertEqual(
models.StripeModel(livemode=True).default_api_key, "sk_live_foo"
)
@override_settings(
STRIPE_TEST_SECRET_KEY="sk_test_foo",
STRIPE_LIVE_SECRET_KEY="sk_live_foo",
STRIPE_TEST_PUBLIC_KEY="pk_test_foo",
STRIPE_LIVE_PUBLIC_KEY="pk_live_foo",
STRIPE_LIVE_MODE=False,
)
def test_secret_key_test_mode(self):
del settings.STRIPE_SECRET_KEY
del settings.STRIPE_PUBLIC_KEY
reload(djstripe_settings)
self.assertEqual(djstripe_settings.STRIPE_LIVE_MODE, False)
self.assertEqual(djstripe_settings.STRIPE_SECRET_KEY, "sk_test_foo")
self.assertEqual(djstripe_settings.STRIPE_PUBLIC_KEY, "pk_test_foo")
self.assertEqual(djstripe_settings.TEST_API_KEY, "sk_test_foo")
self.assertEqual(
models.StripeModel(livemode=False).default_api_key, "sk_test_foo"
)
def tearDown(self):
reload(djstripe_settings)