dj-stripe / dj-stripe

dj-stripe automatically syncs your Stripe Data to your local database as pre-implemented Django Models allowing you to use the Django ORM, in your code, to work with the data making it easier and faster.
https://dj-stripe.dev
MIT License
1.56k stars 476 forks source link

Tests Fail with Django 1.9 #275

Closed alexphelps closed 8 years ago

alexphelps commented 8 years ago

Tests fail with Django 1.9 meaning that all new Pull Requests will fail given that the current requirements_test.txt has django>=1.7 which will result in 1.9 being installed during the build.

Example build - https://travis-ci.org/pydanny/dj-stripe/jobs/94795855

I wish I knew how to fix this but it's a little over my head as to how these tests actually work. :confounded:

======================================================================
ERROR: test_change_sub_stripe_error (tests.test_views.ChangePlanViewTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.5.0/lib/python3.5/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/home/travis/build/pydanny/dj-stripe/tests/test_views.py", line 333, in test_change_sub_stripe_error
    self.assertIn("No such plan: test_id_3", response.context["form"].errors["__all__"])
KeyError: '__all__'
======================================================================
ERROR: test_post_new_sub_no_proration (tests.test_views.ChangePlanViewTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.5.0/lib/python3.5/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/home/travis/build/pydanny/dj-stripe/tests/test_views.py", line 273, in test_post_new_sub_no_proration
    self.assertIn("You must already be subscribed to a plan before you can change it.", response.context["form"].errors["__all__"])
KeyError: '__all__'
======================================================================
ERROR: test_post_no_card (tests.test_views.ConfirmFormViewTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.5.0/lib/python3.5/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/home/travis/build/pydanny/dj-stripe/tests/test_views.py", line 235, in test_post_no_card
    self.assertIn("Invalid source object:", response.context["form"].errors["__all__"])
KeyError: '__all__'
pydanny commented 8 years ago

@alexphelps, thanks for letting us know about this issue. We're working on it right now (and deprecating 1.7 while we are at it per #278 278).

kavdev commented 8 years ago

This is due to a regression in 1.9 that will be fixed in 1.9.1. See the bug report and the commit.

I'll make a note of it in the documentation.

kavdev commented 8 years ago

Tested with 1.9.1 dev; no issues. Give it a shot if you'd like:

pip uninstall django
pip install git+https://github.com/django/django.git@0154702a987bd06d20e53fe23284b2c4a93b9063
alexphelps commented 8 years ago

Nice :+1:

kavdev commented 8 years ago

Good news! 1.9.1 just released

patroqueeet commented 7 years ago

why am I seeing

~/.ve/local/lib/python2.7/site-packages/djstripe/__init__.py:23: UserWarning: dj-stripe deprecation notice: Django 1.7 and lower are no longer
supported. Please upgrade to Django 1.8 or higher.
Reference: https://github.com/pydanny/dj-stripe/issues/275

in my Django 1.10.7 installation? shouldn't that be void?

tobydeh commented 7 years ago

Why am I being asked to upgrade to django 1.8 or higher when I'm running django 1.11.1?

kavdev commented 7 years ago

@tobydeh see #307. We haven't cherry-picked that fix into master and won't because we're about to release 1.0.0

the-webguys commented 6 years ago

Hello

I am receiving two different errors, this: UserWarning: dj-stripe deprecation notice: Django 1.7 and lower are no longer supported. Please upgrade to Django 1.8 or higher. Reference: https://github.com/pydanny/dj-stripe/issues/275 warnings.warn(msg) I am using: Django==1.11.3 | stripe==1.62.0

And this, when running the final command 'python manage.py djstripe_init_customers' i receive the following if ("email" not in subscriber_model._meta.get_all_field_names()) and not hasattr(subscriber_model, 'email'): AttributeError: 'Options' object has no attribute 'get_all_field_names'

kavdev commented 6 years ago

@the-webguys Go ahead and switch to the 1.0.0 branch. You'll find the errors will disappear

the-webguys commented 6 years ago

@kavdev sorry for my ignorance, how do i switch? since i used pip install, is there a different command i need to run?

kavdev commented 6 years ago

@the-webguys no worries! We've been slow to release the major version change.

pip install git+https://github.com/dj-stripe/dj-stripe.git@1.0.0

the-webguys commented 6 years ago

you are a legend, thank you

the-webguys commented 6 years ago

@kavdev any reason i am seeing this error ?: (djstripe.C003) Bad Stripe test API key. HINT: STRIPE_TEST_SECRET_KEY should start with "sktest" The key is a test key lol

the-webguys commented 6 years ago

solved it, i needed to change STRIPE_SECRET_KEY to STRIPE_TEST_SECRET_KEY

the-webguys commented 6 years ago

@kavdev but i have a load of new issues, where is the best place to put this, do you have slack?

kavdev commented 6 years ago

@the-webguys stackoverflow is the best place to post the question, then just ping us about it on gitter

In the meantime, this is the setup I've used for a multi-server (prod, staging, etc.) setup that doesn't keep track of live and test data in the same db. I change the key in the environment for each server.

STRIPE_SECRET_KEY = get_env_variable("STRIPE_SECRET_KEY")
STRIPE_PUBLISHABLE_KEY = get_env_variable("STRIPE_PUBLISHABLE_KEY")
STRIPE_PUBLIC_KEY = STRIPE_PUBLISHABLE_KEY
STRIPE_LIVE_SECRET_KEY = STRIPE_TEST_SECRET_KEY = STRIPE_SECRET_KEY
STRIPE_LIVE_MODE = get_env_variable("STRIPE_LIVE_MODE")
kavdev commented 6 years ago

@the-webguys only go to stackoverflow if it's a question on how to configure or set up dj-stripe; if you find a possible bug, file an issue 👍

the-webguys commented 6 years ago

@kavdev what would be the test mode for this? STRIPE_LIVE_MODE = get_env_variable("STRIPE_LIVE_MODE") STRIPE_TEST_MODE ?

kavdev commented 6 years ago

@the-webguys STRIPE_LIVE_MODE is a boolean

the-webguys commented 6 years ago

@kavdev would this work? STRIPE_LIVE_MODE = false

kavdev commented 6 years ago

@the-webguys with a capital F, yes 😉

the-webguys commented 6 years ago

@kavdev In the install / setup, the examples are STRIPE_PUBLIC_KEY = os.environ.get("STRIPE_PUBLIC_KEY", "pk_test_XXXXXXXXXXXXXXXXX") but here you use STRIPE_SECRET_KEY = get_env_variable("STRIPE_SECRET_KEY") i just receive an error NameError: name 'get_env_variable' is not defined

kavdev commented 6 years ago

@the-webguys yeah sorry that's just an example from a product of mine (I'm essentially using the env method described in Two Scoops).

Go ahead and use the format described in the docs

the-webguys commented 6 years ago

@kavdev which should be just the following 2 lines, of do i need the STRIPE_LIVE_MODE = False also

STRIPE_PUBLIC_KEY = os.environ.get("STRIPE_PUBLIC_KEY", "pk_test_XXXXXXXXXX")
STRIPE_SECRET_KEY = os.environ.get("STRIPE_SECRET_KEY", "sk_test_XXXXXXXXXX")
kavdev commented 6 years ago

yep. also STRIPE_LIVE_SECRET_KEY = STRIPE_TEST_SECRET_KEY = STRIPE_SECRET_KEY if you're not splitting up the keys

the-webguys commented 6 years ago

that's a little confusing, the way i have it now with STRIPE_LIVE_MODE = False will or should work, as they are? Sorry, I am fairly new to django

the-webguys commented 6 years ago

as follows:

STRIPE_PUBLIC_KEY = os.environ.get("STRIPE_PUBLIC_KEY", "pk_test_XXXXXXXXXX")
STRIPE_SECRET_KEY = os.environ.get("STRIPE_SECRET_KEY", "sk_test_XXXXXXXXXX")
STRIPE_LIVE_MODE = False

gives the following error HINT: STRIPE_TEST_SECRET_KEY should start with "sk_test_"

kavdev commented 6 years ago

@the-webguys it has to do with the way we're reading the variables. Technically you should be adding in both test and live keys explicitly.

For this to work as is, just add the following line: STRIPE_LIVE_SECRET_KEY = STRIPE_TEST_SECRET_KEY = STRIPE_SECRET_KEY

the-webguys commented 6 years ago

Do i replace STRIPE_TEST_SECRET_KEY with my test key?

kavdev commented 6 years ago

Ideally, you would set

STRIPE_LIVE_SECRET_KEY STRIPE_LIVE_PUBLIC_KEY STRIPE_TEST_SECRET_KEY STRIPE_TEST_PUBLIC_KEY STRIPE_LIVE_MODE

And populate them from the environment (hard-coding keys is bad practice)

the-webguys commented 6 years ago

Think i have that correct, thanks again