Fix unit tests
This commit is contained in:
parent
03a5a522dd
commit
40f4883f60
|
|
@ -14,7 +14,7 @@ class Oauth2TokenFactory(factory.django.DjangoModelFactory):
|
|||
class Meta:
|
||||
model = OAuth2Token
|
||||
|
||||
token_type = 'hep'
|
||||
token_type = 'Bearer'
|
||||
access_token = 'asdfgghh'
|
||||
refresh_token = 'yxcvbnnm'
|
||||
expires_at = IN_A_HOUR_UNIX
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
from django.utils.dateparse import parse_datetime
|
||||
from datetime import timedelta
|
||||
|
||||
from django.conf import settings
|
||||
import logging
|
||||
import requests
|
||||
|
||||
from oauth.oauth_client import oauth
|
||||
from users.licenses import MYSKILLBOX_LICENSES, is_myskillbox_product, TEACHER_KEY
|
||||
|
|
@ -139,9 +137,6 @@ class HepClient:
|
|||
return None
|
||||
|
||||
response_data = response.json()
|
||||
|
||||
# todo handle 404, 402
|
||||
|
||||
return response_data
|
||||
|
||||
def _extract_myskillbox_products(self, eorders):
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class Coupon(relay.ClientIDMutation):
|
|||
raise Exception('not_authenticated')
|
||||
|
||||
try:
|
||||
response = hep_client.redeem_coupon(coupon_code, hep_id, request=info)
|
||||
response = hep_client.redeem_coupon(coupon_code, hep_id, request=info.context)
|
||||
except HepClientException:
|
||||
raise Exception('unknown_error')
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
import requests
|
||||
from authlib.integrations.base_client import BaseApp
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.contrib.sessions.middleware import SessionMiddleware
|
||||
from django.test import TestCase, RequestFactory
|
||||
|
|
@ -90,7 +91,7 @@ class CouponTests(TestCase):
|
|||
}
|
||||
})
|
||||
|
||||
@patch.object(requests, 'post', return_value=MockResponse(200, data=REDEEM_MYSKILLBOX_SUCCESS_RESPONSE))
|
||||
@patch.object(BaseApp, 'post', return_value=MockResponse(200, data=REDEEM_MYSKILLBOX_SUCCESS_RESPONSE))
|
||||
def test_user_has_valid_skillbox_coupon(self, response_mock):
|
||||
result = self.make_coupon_mutation('COUPON--1234', self.client)
|
||||
|
||||
|
|
@ -105,7 +106,7 @@ class CouponTests(TestCase):
|
|||
self.assertTrue(result.get('data').get('coupon').get('success'))
|
||||
self.assertTrue(self.user.is_authenticated)
|
||||
|
||||
@patch.object(requests, 'post', return_value=MockResponse(200, data=REDEEM_OTHER_LICENSE_RESPONSE))
|
||||
@patch.object(BaseApp, 'post', return_value=MockResponse(200, data=REDEEM_OTHER_LICENSE_RESPONSE))
|
||||
def test_user_has_valid_non_skillbox_coupon(self, response_mock):
|
||||
result = self.make_coupon_mutation('COUPON--1234', self.client)
|
||||
|
||||
|
|
@ -124,19 +125,19 @@ class CouponTests(TestCase):
|
|||
self.assertEqual(result.get('errors')[0].get('message'), 'non_myskillbox_product')
|
||||
self.assertTrue(self.user.is_authenticated)
|
||||
|
||||
@patch.object(requests, 'post', return_value=MockResponse(404, data=INVALID_LICENSE))
|
||||
@patch.object(BaseApp, 'post', return_value=MockResponse(404, data=INVALID_LICENSE))
|
||||
def test_user_has_invalid_coupon(self, response_mock):
|
||||
result = self.make_coupon_mutation('COUPON--1234', self.client)
|
||||
|
||||
self.assertEqual(result.get('errors')[0].get('message'), 'invalid_coupon')
|
||||
|
||||
@patch.object(requests, 'post', return_value=MockResponse(422, data=INVALID_LICENSE))
|
||||
@patch.object(BaseApp, 'post', return_value=MockResponse(422, data=INVALID_LICENSE))
|
||||
def test_user_has_already_used_coupon(self, response_mock):
|
||||
result = self.make_coupon_mutation('COUPON--1234', self.client)
|
||||
|
||||
self.assertEqual(result.get('errors')[0].get('message'), 'invalid_coupon')
|
||||
|
||||
@patch.object(requests, 'put', return_value=MockResponse(200, data=['201', 'Invalid Coupon']))
|
||||
@patch.object(BaseApp, 'put', return_value=MockResponse(200, data=['201', 'Invalid Coupon']))
|
||||
def test_unauthenticated_user_cannot_redeem(self, response_mock):
|
||||
request = RequestFactory().post('/')
|
||||
middleware = SessionMiddleware()
|
||||
|
|
|
|||
Loading…
Reference in New Issue