Setup views and tests
This commit is contained in:
parent
2e8be04328
commit
87ceb5fc0e
|
|
@ -14,11 +14,11 @@ import requests
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MagentoException(Exception):
|
class HepClientException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class MagentoClient:
|
class HepClient:
|
||||||
URL = 'https://stage.hep-verlag.ch'
|
URL = 'https://stage.hep-verlag.ch'
|
||||||
# URL = 'https://www.hep-verlag.ch'
|
# URL = 'https://www.hep-verlag.ch'
|
||||||
WEBSITE_ID = 1
|
WEBSITE_ID = 1
|
||||||
|
|
@ -45,7 +45,7 @@ class MagentoClient:
|
||||||
response = requests.get(request_url, headers=headers)
|
response = requests.get(request_url, headers=headers)
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise MagentoException(response.status_code, response.json())
|
raise HepClientException(response.status_code, response.json())
|
||||||
|
|
||||||
logger.info(response.json())
|
logger.info(response.json())
|
||||||
return response
|
return response
|
||||||
|
|
@ -55,6 +55,9 @@ class MagentoClient:
|
||||||
data={'customerEmail': email, 'websiteId': self.WEBSITE_ID})
|
data={'customerEmail': email, 'websiteId': self.WEBSITE_ID})
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
|
def is_email_verified(self, email):
|
||||||
|
return True
|
||||||
|
|
||||||
def customer_verify_email(self, confirmation_key):
|
def customer_verify_email(self, confirmation_key):
|
||||||
response = self._call('/rest/V1/customers/me', method='put', data={'confirmationKey': confirmation_key})
|
response = self._call('/rest/V1/customers/me', method='put', data={'confirmationKey': confirmation_key})
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
|
||||||
|
|
@ -361,8 +361,13 @@ SENDGRID_API_KEY = os.environ.get("SENDGRID_API_KEY")
|
||||||
SENDGRID_SANDBOX_MODE_IN_DEBUG = False
|
SENDGRID_SANDBOX_MODE_IN_DEBUG = False
|
||||||
DEFAULT_FROM_EMAIL = 'myskillbox <noreply@myskillbox.ch>'
|
DEFAULT_FROM_EMAIL = 'myskillbox <noreply@myskillbox.ch>'
|
||||||
|
|
||||||
|
# Taskbase
|
||||||
TASKBASE_USER = os.environ.get("TASKBASE_USER")
|
TASKBASE_USER = os.environ.get("TASKBASE_USER")
|
||||||
TASKBASE_PASSWORD = os.environ.get("TASKBASE_PASSWORD")
|
TASKBASE_PASSWORD = os.environ.get("TASKBASE_PASSWORD")
|
||||||
TASKBASE_SUPERUSER = os.environ.get("TASKBASE_SUPERUSER")
|
TASKBASE_SUPERUSER = os.environ.get("TASKBASE_SUPERUSER")
|
||||||
TASKBASE_SUPERPASSWORD = os.environ.get("TASKBASE_SUPERPASSWORD")
|
TASKBASE_SUPERPASSWORD = os.environ.get("TASKBASE_SUPERPASSWORD")
|
||||||
TASKBASE_BASEURL = os.environ.get("TASKBASE_BASEURL")
|
TASKBASE_BASEURL = os.environ.get("TASKBASE_BASEURL")
|
||||||
|
|
||||||
|
|
||||||
|
USE_LOCAL_REGISTRATION = False
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,10 @@
|
||||||
# Created on 2019-10-08
|
# Created on 2019-10-08
|
||||||
# @author: chrigu <christian.cueni@iterativ.ch>
|
# @author: chrigu <christian.cueni@iterativ.ch>
|
||||||
import graphene
|
import graphene
|
||||||
|
from django.conf import settings
|
||||||
from graphene import relay
|
from graphene import relay
|
||||||
|
|
||||||
|
from core.hep_client import HepClient, HepClientException
|
||||||
from core.views import SetPasswordView
|
from core.views import SetPasswordView
|
||||||
from registration.models import License
|
from registration.models import License
|
||||||
from registration.serializers import RegistrationSerializer
|
from registration.serializers import RegistrationSerializer
|
||||||
|
|
@ -51,31 +53,31 @@ class Registration(relay.ClientIDMutation):
|
||||||
serializer = RegistrationSerializer(data=registration_data)
|
serializer = RegistrationSerializer(data=registration_data)
|
||||||
|
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
user = User.objects.create_user_with_random_password(serializer.data['first_name'],
|
|
||||||
serializer.data['last_name'],
|
|
||||||
serializer.data['email'])
|
|
||||||
sb_license = License.objects.create(licensee=user, license_type=serializer.context['license_type'])
|
|
||||||
|
|
||||||
if sb_license.license_type.is_teacher_license():
|
if settings.USE_LOCAL_REGISTRATION:
|
||||||
teacher_role = Role.objects.get(key=Role.objects.TEACHER_KEY)
|
return cls.create_local_user(serializer, info)
|
||||||
UserRole.objects.get_or_create(user=user, role=teacher_role)
|
|
||||||
default_class_name = SchoolClass.generate_default_group_name()
|
|
||||||
default_class = SchoolClass.objects.create(name=default_class_name)
|
|
||||||
user.school_classes.add(default_class)
|
|
||||||
else:
|
else:
|
||||||
student_role = Role.objects.get(key=Role.objects.STUDENT_KEY)
|
hep_client = HepClient()
|
||||||
UserRole.objects.get_or_create(user=user, role=student_role)
|
|
||||||
|
|
||||||
password_reset_view = SetPasswordView()
|
try:
|
||||||
password_reset_view.request = info.context
|
email_available = hep_client.is_email_available(serializer['email'])
|
||||||
form = password_reset_view.form_class({'email': user.email})
|
except HepClientException:
|
||||||
|
# Todo: handle error from exception (set on object, code & message)
|
||||||
|
return cls(success=False, errors=None)
|
||||||
|
|
||||||
if not form.is_valid():
|
if not email_available:
|
||||||
return cls(success=False, errors=form.errors)
|
errors = [MutationError(field='email', errors=['already_exists'])]
|
||||||
|
return cls(success=False, errors=errors)
|
||||||
|
|
||||||
password_reset_view.form_valid(form)
|
try:
|
||||||
|
response = hep_client.customer_create(serializer.data, None)
|
||||||
|
except HepClientException:
|
||||||
|
# Todo: handle error from exception (set on object, code & message)
|
||||||
|
return cls(success=False, errors=None)
|
||||||
|
|
||||||
return cls(success=True)
|
# create or update local user
|
||||||
|
|
||||||
|
# show verfiy page
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
for key, value in serializer.errors.items():
|
for key, value in serializer.errors.items():
|
||||||
|
|
@ -87,6 +89,33 @@ class Registration(relay.ClientIDMutation):
|
||||||
|
|
||||||
return cls(success=False, errors=errors)
|
return cls(success=False, errors=errors)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create_local_user(cls, serializer, info):
|
||||||
|
user = User.objects.create_user_with_random_password(serializer.data['first_name'],
|
||||||
|
serializer.data['last_name'],
|
||||||
|
serializer.data['email'])
|
||||||
|
sb_license = License.objects.create(licensee=user, license_type=serializer.context['license_type'])
|
||||||
|
|
||||||
|
if sb_license.license_type.is_teacher_license():
|
||||||
|
teacher_role = Role.objects.get(key=Role.objects.TEACHER_KEY)
|
||||||
|
UserRole.objects.get_or_create(user=user, role=teacher_role)
|
||||||
|
default_class_name = SchoolClass.generate_default_group_name()
|
||||||
|
default_class = SchoolClass.objects.create(name=default_class_name)
|
||||||
|
user.school_classes.add(default_class)
|
||||||
|
else:
|
||||||
|
student_role = Role.objects.get(key=Role.objects.STUDENT_KEY)
|
||||||
|
UserRole.objects.get_or_create(user=user, role=student_role)
|
||||||
|
|
||||||
|
password_reset_view = SetPasswordView()
|
||||||
|
password_reset_view.request = info.context
|
||||||
|
form = password_reset_view.form_class({'email': user.email})
|
||||||
|
|
||||||
|
if not form.is_valid():
|
||||||
|
return cls(success=False, errors=form.errors)
|
||||||
|
|
||||||
|
password_reset_view.form_valid(form)
|
||||||
|
|
||||||
|
return cls(success=True)
|
||||||
|
|
||||||
class RegistrationMutations:
|
class RegistrationMutations:
|
||||||
registration = Registration.Field()
|
registration = Registration.Field()
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
#
|
#
|
||||||
# Created on 2019-10-08
|
# Created on 2019-10-08
|
||||||
# @author: chrigu <christian.cueni@iterativ.ch>
|
# @author: chrigu <christian.cueni@iterativ.ch>
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from rest_framework.fields import CharField, EmailField
|
from rest_framework.fields import CharField, EmailField
|
||||||
|
|
@ -22,7 +23,12 @@ class RegistrationSerializer(serializers.Serializer):
|
||||||
skillbox_license = None
|
skillbox_license = None
|
||||||
|
|
||||||
def validate_email(self, value):
|
def validate_email(self, value):
|
||||||
|
|
||||||
lower_email = value.lower()
|
lower_email = value.lower()
|
||||||
|
|
||||||
|
if not settings.USE_LOCAL_REGISTRATION:
|
||||||
|
return lower_email
|
||||||
|
|
||||||
# the email is used as username
|
# the email is used as username
|
||||||
if len(get_user_model().objects.filter(username=lower_email)) > 0:
|
if len(get_user_model().objects.filter(username=lower_email)) > 0:
|
||||||
raise serializers.ValidationError(_(u'Diese E-Mail ist bereits registriert'))
|
raise serializers.ValidationError(_(u'Diese E-Mail ist bereits registriert'))
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,8 @@ class UserManager(DjangoUserManager):
|
||||||
user, created = self.model.objects.get_or_create(email=email, username=email)
|
user, created = self.model.objects.get_or_create(email=email, username=email)
|
||||||
user.first_name = first_name
|
user.first_name = first_name
|
||||||
user.last_name = last_name
|
user.last_name = last_name
|
||||||
user.set_password(self.model.objects.make_random_password())
|
# Todo: remove if not used
|
||||||
|
# user.set_password(self.model.objects.make_random_password())
|
||||||
|
user.set_unusable_password()
|
||||||
user.save()
|
user.save()
|
||||||
return user
|
return user
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,11 @@
|
||||||
# @author: chrigu <christian.cueni@iterativ.ch>
|
# @author: chrigu <christian.cueni@iterativ.ch>
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
|
from django.conf import settings
|
||||||
from django.contrib.auth import authenticate, login
|
from django.contrib.auth import authenticate, login
|
||||||
from graphene import relay
|
from graphene import relay
|
||||||
|
|
||||||
|
from core.hep_client import HepClient
|
||||||
from registration.models import License
|
from registration.models import License
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -30,10 +32,33 @@ class Login(relay.ClientIDMutation):
|
||||||
@classmethod
|
@classmethod
|
||||||
def mutate_and_get_payload(cls, root, info, **kwargs):
|
def mutate_and_get_payload(cls, root, info, **kwargs):
|
||||||
|
|
||||||
user = authenticate(username=kwargs.get('username_input'), password=kwargs.get('password_input'))
|
# get token
|
||||||
if user is None:
|
# wrong password
|
||||||
error = LoginError(field='invalid_credentials')
|
#
|
||||||
return cls(success=False, errors=[error])
|
# is email verified
|
||||||
|
# -> show screen
|
||||||
|
# local license
|
||||||
|
# -> show coupon
|
||||||
|
# get hep orders
|
||||||
|
# -> show coupon
|
||||||
|
# save role information
|
||||||
|
# login
|
||||||
|
|
||||||
|
if not settings.USE_LOCAL_REGISTRATION:
|
||||||
|
user = authenticate(username=kwargs.get('username_input'), password=kwargs.get('password_input'))
|
||||||
|
if user is None:
|
||||||
|
error = LoginError(field='invalid_credentials')
|
||||||
|
return cls(success=False, errors=[error])
|
||||||
|
|
||||||
|
else:
|
||||||
|
hep_client = HepClient()
|
||||||
|
|
||||||
|
# Todo catch error
|
||||||
|
token = hep_client.customer_token(kwargs.get('username_input'), kwargs.get('password_input'))
|
||||||
|
# Todo save token
|
||||||
|
#verify email
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
user_license = None
|
user_license = None
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,526 @@
|
||||||
|
{
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"base_currency_code": "CHF",
|
||||||
|
"base_discount_amount": 0,
|
||||||
|
"base_grand_total": 46,
|
||||||
|
"base_discount_tax_compensation_amount": 0,
|
||||||
|
"base_shipping_amount": 0,
|
||||||
|
"base_shipping_discount_amount": 0,
|
||||||
|
"base_shipping_incl_tax": 0,
|
||||||
|
"base_shipping_tax_amount": 0,
|
||||||
|
"base_subtotal": 44.88,
|
||||||
|
"base_subtotal_incl_tax": 46,
|
||||||
|
"base_tax_amount": 1.12,
|
||||||
|
"base_total_due": 46,
|
||||||
|
"base_to_global_rate": 1,
|
||||||
|
"base_to_order_rate": 1,
|
||||||
|
"billing_address_id": 83693,
|
||||||
|
"created_at": "2018-07-19 15:05:33",
|
||||||
|
"customer_email": "1heptest19072018@mailinator.com",
|
||||||
|
"customer_firstname": "Test",
|
||||||
|
"customer_gender": 2,
|
||||||
|
"customer_group_id": 4,
|
||||||
|
"customer_id": 49124,
|
||||||
|
"customer_is_guest": 0,
|
||||||
|
"customer_lastname": "Test",
|
||||||
|
"customer_note": "coupon",
|
||||||
|
"customer_note_notify": 1,
|
||||||
|
"customer_prefix": "Frau",
|
||||||
|
"discount_amount": 0,
|
||||||
|
"email_sent": 1,
|
||||||
|
"entity_id": 57612,
|
||||||
|
"global_currency_code": "CHF",
|
||||||
|
"grand_total": 46,
|
||||||
|
"discount_tax_compensation_amount": 0,
|
||||||
|
"increment_id": "1004614768",
|
||||||
|
"is_virtual": 1,
|
||||||
|
"order_currency_code": "CHF",
|
||||||
|
"protect_code": "71aedb",
|
||||||
|
"quote_id": 104401,
|
||||||
|
"shipping_amount": 0,
|
||||||
|
"shipping_discount_amount": 0,
|
||||||
|
"shipping_discount_tax_compensation_amount": 0,
|
||||||
|
"shipping_incl_tax": 0,
|
||||||
|
"shipping_tax_amount": 0,
|
||||||
|
"state": "complete",
|
||||||
|
"status": "complete",
|
||||||
|
"store_currency_code": "CHF",
|
||||||
|
"store_id": 1,
|
||||||
|
"store_name": "hep verlag\nhep verlag\nhep verlag",
|
||||||
|
"store_to_base_rate": 0,
|
||||||
|
"store_to_order_rate": 0,
|
||||||
|
"subtotal": 44.88,
|
||||||
|
"subtotal_incl_tax": 46,
|
||||||
|
"tax_amount": 1.12,
|
||||||
|
"total_due": 46,
|
||||||
|
"total_item_count": 1,
|
||||||
|
"total_qty_ordered": 1,
|
||||||
|
"updated_at": "2018-07-19 15:05:33",
|
||||||
|
"weight": 0,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"amount_refunded": 0,
|
||||||
|
"base_amount_refunded": 0,
|
||||||
|
"base_discount_amount": 0,
|
||||||
|
"base_discount_invoiced": 0,
|
||||||
|
"base_discount_tax_compensation_amount": 0,
|
||||||
|
"base_original_price": 46,
|
||||||
|
"base_price": 44.88,
|
||||||
|
"base_price_incl_tax": 46,
|
||||||
|
"base_row_invoiced": 0,
|
||||||
|
"base_row_total": 44.88,
|
||||||
|
"base_row_total_incl_tax": 46,
|
||||||
|
"base_tax_amount": 1.12,
|
||||||
|
"base_tax_invoiced": 0,
|
||||||
|
"created_at": "2018-07-19 15:05:33",
|
||||||
|
"discount_amount": 0,
|
||||||
|
"discount_invoiced": 0,
|
||||||
|
"discount_percent": 0,
|
||||||
|
"free_shipping": 0,
|
||||||
|
"discount_tax_compensation_amount": 0,
|
||||||
|
"is_qty_decimal": 0,
|
||||||
|
"is_virtual": 1,
|
||||||
|
"item_id": 80317,
|
||||||
|
"name": "Gesellschaft Ausgabe A (eLehrmittel, Neuauflage)",
|
||||||
|
"no_discount": 0,
|
||||||
|
"order_id": 57612,
|
||||||
|
"original_price": 46,
|
||||||
|
"price": 44.88,
|
||||||
|
"price_incl_tax": 46,
|
||||||
|
"product_id": 8652,
|
||||||
|
"product_type": "virtual",
|
||||||
|
"qty_canceled": 0,
|
||||||
|
"qty_invoiced": 0,
|
||||||
|
"qty_ordered": 1,
|
||||||
|
"qty_refunded": 0,
|
||||||
|
"qty_shipped": 0,
|
||||||
|
"quote_item_id": 135166,
|
||||||
|
"row_invoiced": 0,
|
||||||
|
"row_total": 44.88,
|
||||||
|
"row_total_incl_tax": 46,
|
||||||
|
"sku": "978-3-0355-1082-9",
|
||||||
|
"store_id": 1,
|
||||||
|
"tax_amount": 1.12,
|
||||||
|
"tax_invoiced": 0,
|
||||||
|
"tax_percent": 2.5,
|
||||||
|
"updated_at": "2018-07-19 15:05:33",
|
||||||
|
"weight": 0.01
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"billing_address": {
|
||||||
|
"address_type": "billing",
|
||||||
|
"city": "Test",
|
||||||
|
"country_id": "CH",
|
||||||
|
"customer_address_id": 47579,
|
||||||
|
"email": "1heptest19072018@mailinator.com",
|
||||||
|
"entity_id": 83693,
|
||||||
|
"firstname": "Test",
|
||||||
|
"lastname": "Test",
|
||||||
|
"parent_id": 57612,
|
||||||
|
"postcode": "0000",
|
||||||
|
"prefix": "Frau",
|
||||||
|
"street": [
|
||||||
|
"Test"
|
||||||
|
],
|
||||||
|
"telephone": null
|
||||||
|
},
|
||||||
|
"payment": {
|
||||||
|
"account_status": null,
|
||||||
|
"additional_information": [
|
||||||
|
"Rechnung",
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
],
|
||||||
|
"amount_ordered": 46,
|
||||||
|
"base_amount_ordered": 46,
|
||||||
|
"base_shipping_amount": 0,
|
||||||
|
"cc_last4": null,
|
||||||
|
"entity_id": 57612,
|
||||||
|
"method": "checkmo",
|
||||||
|
"parent_id": 57612,
|
||||||
|
"shipping_amount": 0,
|
||||||
|
"extension_attributes": []
|
||||||
|
},
|
||||||
|
"status_histories": [
|
||||||
|
{
|
||||||
|
"comment": "payed by couponcode",
|
||||||
|
"created_at": "2018-07-19 15:05:33",
|
||||||
|
"entity_id": 244885,
|
||||||
|
"entity_name": "order",
|
||||||
|
"is_customer_notified": null,
|
||||||
|
"is_visible_on_front": 0,
|
||||||
|
"parent_id": 57612,
|
||||||
|
"status": "complete"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": "licence-coupon \"ebf81a59b968\"",
|
||||||
|
"created_at": "2018-07-19 15:05:33",
|
||||||
|
"entity_id": 244884,
|
||||||
|
"entity_name": "order",
|
||||||
|
"is_customer_notified": null,
|
||||||
|
"is_visible_on_front": 0,
|
||||||
|
"parent_id": 57612,
|
||||||
|
"status": "complete"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": null,
|
||||||
|
"created_at": "2018-07-19 15:05:33",
|
||||||
|
"entity_id": 244883,
|
||||||
|
"entity_name": "order",
|
||||||
|
"is_customer_notified": 0,
|
||||||
|
"is_visible_on_front": 0,
|
||||||
|
"parent_id": 57612,
|
||||||
|
"status": "complete"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": "Exported to ERP",
|
||||||
|
"created_at": "2018-07-19 15:05:33",
|
||||||
|
"entity_id": 244882,
|
||||||
|
"entity_name": "order",
|
||||||
|
"is_customer_notified": 0,
|
||||||
|
"is_visible_on_front": 0,
|
||||||
|
"parent_id": 57612,
|
||||||
|
"status": "complete"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"extension_attributes": {
|
||||||
|
"shipping_assignments": [
|
||||||
|
{
|
||||||
|
"shipping": {
|
||||||
|
"total": {
|
||||||
|
"base_shipping_amount": 0,
|
||||||
|
"base_shipping_discount_amount": 0,
|
||||||
|
"base_shipping_incl_tax": 0,
|
||||||
|
"base_shipping_tax_amount": 0,
|
||||||
|
"shipping_amount": 0,
|
||||||
|
"shipping_discount_amount": 0,
|
||||||
|
"shipping_discount_tax_compensation_amount": 0,
|
||||||
|
"shipping_incl_tax": 0,
|
||||||
|
"shipping_tax_amount": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"amount_refunded": 0,
|
||||||
|
"base_amount_refunded": 0,
|
||||||
|
"base_discount_amount": 0,
|
||||||
|
"base_discount_invoiced": 0,
|
||||||
|
"base_discount_tax_compensation_amount": 0,
|
||||||
|
"base_original_price": 46,
|
||||||
|
"base_price": 44.88,
|
||||||
|
"base_price_incl_tax": 46,
|
||||||
|
"base_row_invoiced": 0,
|
||||||
|
"base_row_total": 44.88,
|
||||||
|
"base_row_total_incl_tax": 46,
|
||||||
|
"base_tax_amount": 1.12,
|
||||||
|
"base_tax_invoiced": 0,
|
||||||
|
"created_at": "2018-07-19 15:05:33",
|
||||||
|
"discount_amount": 0,
|
||||||
|
"discount_invoiced": 0,
|
||||||
|
"discount_percent": 0,
|
||||||
|
"free_shipping": 0,
|
||||||
|
"discount_tax_compensation_amount": 0,
|
||||||
|
"is_qty_decimal": 0,
|
||||||
|
"is_virtual": 1,
|
||||||
|
"item_id": 80317,
|
||||||
|
"name": "Gesellschaft Ausgabe A (eLehrmittel, Neuauflage)",
|
||||||
|
"no_discount": 0,
|
||||||
|
"order_id": 57612,
|
||||||
|
"original_price": 46,
|
||||||
|
"price": 44.88,
|
||||||
|
"price_incl_tax": 46,
|
||||||
|
"product_id": 8652,
|
||||||
|
"product_type": "virtual",
|
||||||
|
"qty_canceled": 0,
|
||||||
|
"qty_invoiced": 0,
|
||||||
|
"qty_ordered": 1,
|
||||||
|
"qty_refunded": 0,
|
||||||
|
"qty_shipped": 0,
|
||||||
|
"quote_item_id": 135166,
|
||||||
|
"row_invoiced": 0,
|
||||||
|
"row_total": 44.88,
|
||||||
|
"row_total_incl_tax": 46,
|
||||||
|
"sku": "978-3-0355-1082-9",
|
||||||
|
"store_id": 1,
|
||||||
|
"tax_amount": 1.12,
|
||||||
|
"tax_invoiced": 0,
|
||||||
|
"tax_percent": 2.5,
|
||||||
|
"updated_at": "2018-07-19 15:05:33",
|
||||||
|
"weight": 0.01
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"base_currency_code": "CHF",
|
||||||
|
"base_discount_amount": 0,
|
||||||
|
"base_grand_total": 24,
|
||||||
|
"base_discount_tax_compensation_amount": 0,
|
||||||
|
"base_shipping_amount": 0,
|
||||||
|
"base_shipping_discount_amount": 0,
|
||||||
|
"base_shipping_incl_tax": 0,
|
||||||
|
"base_shipping_tax_amount": 0,
|
||||||
|
"base_subtotal": 23.41,
|
||||||
|
"base_subtotal_incl_tax": 24,
|
||||||
|
"base_tax_amount": 0.59,
|
||||||
|
"base_total_due": 24,
|
||||||
|
"base_to_global_rate": 1,
|
||||||
|
"base_to_order_rate": 1,
|
||||||
|
"billing_address_id": 83696,
|
||||||
|
"created_at": "2018-07-19 15:19:00",
|
||||||
|
"customer_email": "1heptest19072018@mailinator.com",
|
||||||
|
"customer_firstname": "Test",
|
||||||
|
"customer_gender": 2,
|
||||||
|
"customer_group_id": 4,
|
||||||
|
"customer_id": 49124,
|
||||||
|
"customer_is_guest": 0,
|
||||||
|
"customer_lastname": "Test",
|
||||||
|
"customer_note": "coupon",
|
||||||
|
"customer_note_notify": 1,
|
||||||
|
"customer_prefix": "Frau",
|
||||||
|
"discount_amount": 0,
|
||||||
|
"email_sent": 1,
|
||||||
|
"entity_id": 57614,
|
||||||
|
"global_currency_code": "CHF",
|
||||||
|
"grand_total": 24,
|
||||||
|
"discount_tax_compensation_amount": 0,
|
||||||
|
"increment_id": "1004614770",
|
||||||
|
"is_virtual": 1,
|
||||||
|
"order_currency_code": "CHF",
|
||||||
|
"protect_code": "1a88e9",
|
||||||
|
"quote_id": 104403,
|
||||||
|
"shipping_amount": 0,
|
||||||
|
"shipping_discount_amount": 0,
|
||||||
|
"shipping_discount_tax_compensation_amount": 0,
|
||||||
|
"shipping_incl_tax": 0,
|
||||||
|
"shipping_tax_amount": 0,
|
||||||
|
"state": "complete",
|
||||||
|
"status": "complete",
|
||||||
|
"store_currency_code": "CHF",
|
||||||
|
"store_id": 1,
|
||||||
|
"store_name": "hep verlag\nhep verlag\nhep verlag",
|
||||||
|
"store_to_base_rate": 0,
|
||||||
|
"store_to_order_rate": 0,
|
||||||
|
"subtotal": 23.41,
|
||||||
|
"subtotal_incl_tax": 24,
|
||||||
|
"tax_amount": 0.59,
|
||||||
|
"total_due": 24,
|
||||||
|
"total_item_count": 1,
|
||||||
|
"total_qty_ordered": 1,
|
||||||
|
"updated_at": "2018-07-19 15:19:00",
|
||||||
|
"weight": 0,
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"amount_refunded": 0,
|
||||||
|
"base_amount_refunded": 0,
|
||||||
|
"base_discount_amount": 0,
|
||||||
|
"base_discount_invoiced": 0,
|
||||||
|
"base_discount_tax_compensation_amount": 0,
|
||||||
|
"base_original_price": 24,
|
||||||
|
"base_price": 23.41,
|
||||||
|
"base_price_incl_tax": 24,
|
||||||
|
"base_row_invoiced": 0,
|
||||||
|
"base_row_total": 23.41,
|
||||||
|
"base_row_total_incl_tax": 24,
|
||||||
|
"base_tax_amount": 0.59,
|
||||||
|
"base_tax_invoiced": 0,
|
||||||
|
"created_at": "2018-07-19 15:19:00",
|
||||||
|
"discount_amount": 0,
|
||||||
|
"discount_invoiced": 0,
|
||||||
|
"discount_percent": 0,
|
||||||
|
"free_shipping": 0,
|
||||||
|
"discount_tax_compensation_amount": 0,
|
||||||
|
"is_qty_decimal": 0,
|
||||||
|
"is_virtual": 1,
|
||||||
|
"item_id": 80320,
|
||||||
|
"name": "Gesellschaft Ausgabe A, Arbeitsheft (eLehrmittel, Neuauflage)",
|
||||||
|
"no_discount": 0,
|
||||||
|
"order_id": 57614,
|
||||||
|
"original_price": 24,
|
||||||
|
"price": 23.41,
|
||||||
|
"price_incl_tax": 24,
|
||||||
|
"product_id": 8654,
|
||||||
|
"product_type": "virtual",
|
||||||
|
"qty_canceled": 0,
|
||||||
|
"qty_invoiced": 0,
|
||||||
|
"qty_ordered": 1,
|
||||||
|
"qty_refunded": 0,
|
||||||
|
"qty_shipped": 0,
|
||||||
|
"quote_item_id": 135169,
|
||||||
|
"row_invoiced": 0,
|
||||||
|
"row_total": 23.41,
|
||||||
|
"row_total_incl_tax": 24,
|
||||||
|
"sku": "978-3-0355-1185-7",
|
||||||
|
"store_id": 1,
|
||||||
|
"tax_amount": 0.59,
|
||||||
|
"tax_invoiced": 0,
|
||||||
|
"tax_percent": 2.5,
|
||||||
|
"updated_at": "2018-07-19 15:19:00",
|
||||||
|
"weight": 0.01
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"billing_address": {
|
||||||
|
"address_type": "billing",
|
||||||
|
"city": "Test",
|
||||||
|
"country_id": "CH",
|
||||||
|
"customer_address_id": 47579,
|
||||||
|
"email": "1heptest19072018@mailinator.com",
|
||||||
|
"entity_id": 83696,
|
||||||
|
"firstname": "Test",
|
||||||
|
"lastname": "Test",
|
||||||
|
"parent_id": 57614,
|
||||||
|
"postcode": "0000",
|
||||||
|
"prefix": "Frau",
|
||||||
|
"street": [
|
||||||
|
"Test"
|
||||||
|
],
|
||||||
|
"telephone": null
|
||||||
|
},
|
||||||
|
"payment": {
|
||||||
|
"account_status": null,
|
||||||
|
"additional_information": [
|
||||||
|
"Rechnung",
|
||||||
|
null,
|
||||||
|
null
|
||||||
|
],
|
||||||
|
"amount_ordered": 24,
|
||||||
|
"base_amount_ordered": 24,
|
||||||
|
"base_shipping_amount": 0,
|
||||||
|
"cc_last4": null,
|
||||||
|
"entity_id": 57614,
|
||||||
|
"method": "checkmo",
|
||||||
|
"parent_id": 57614,
|
||||||
|
"shipping_amount": 0,
|
||||||
|
"extension_attributes": []
|
||||||
|
},
|
||||||
|
"status_histories": [
|
||||||
|
{
|
||||||
|
"comment": "payed by couponcode",
|
||||||
|
"created_at": "2018-07-19 15:19:00",
|
||||||
|
"entity_id": 244890,
|
||||||
|
"entity_name": "order",
|
||||||
|
"is_customer_notified": null,
|
||||||
|
"is_visible_on_front": 0,
|
||||||
|
"parent_id": 57614,
|
||||||
|
"status": "complete"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": "licence-coupon \"ece5e74a2b36\"",
|
||||||
|
"created_at": "2018-07-19 15:19:00",
|
||||||
|
"entity_id": 244889,
|
||||||
|
"entity_name": "order",
|
||||||
|
"is_customer_notified": null,
|
||||||
|
"is_visible_on_front": 0,
|
||||||
|
"parent_id": 57614,
|
||||||
|
"status": "complete"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": null,
|
||||||
|
"created_at": "2018-07-19 15:19:00",
|
||||||
|
"entity_id": 244888,
|
||||||
|
"entity_name": "order",
|
||||||
|
"is_customer_notified": 0,
|
||||||
|
"is_visible_on_front": 0,
|
||||||
|
"parent_id": 57614,
|
||||||
|
"status": "complete"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": "Exported to ERP",
|
||||||
|
"created_at": "2018-07-19 15:19:00",
|
||||||
|
"entity_id": 244887,
|
||||||
|
"entity_name": "order",
|
||||||
|
"is_customer_notified": 0,
|
||||||
|
"is_visible_on_front": 0,
|
||||||
|
"parent_id": 57614,
|
||||||
|
"status": "complete"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"extension_attributes": {
|
||||||
|
"shipping_assignments": [
|
||||||
|
{
|
||||||
|
"shipping": {
|
||||||
|
"total": {
|
||||||
|
"base_shipping_amount": 0,
|
||||||
|
"base_shipping_discount_amount": 0,
|
||||||
|
"base_shipping_incl_tax": 0,
|
||||||
|
"base_shipping_tax_amount": 0,
|
||||||
|
"shipping_amount": 0,
|
||||||
|
"shipping_discount_amount": 0,
|
||||||
|
"shipping_discount_tax_compensation_amount": 0,
|
||||||
|
"shipping_incl_tax": 0,
|
||||||
|
"shipping_tax_amount": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"amount_refunded": 0,
|
||||||
|
"base_amount_refunded": 0,
|
||||||
|
"base_discount_amount": 0,
|
||||||
|
"base_discount_invoiced": 0,
|
||||||
|
"base_discount_tax_compensation_amount": 0,
|
||||||
|
"base_original_price": 24,
|
||||||
|
"base_price": 23.41,
|
||||||
|
"base_price_incl_tax": 24,
|
||||||
|
"base_row_invoiced": 0,
|
||||||
|
"base_row_total": 23.41,
|
||||||
|
"base_row_total_incl_tax": 24,
|
||||||
|
"base_tax_amount": 0.59,
|
||||||
|
"base_tax_invoiced": 0,
|
||||||
|
"created_at": "2018-07-19 15:19:00",
|
||||||
|
"discount_amount": 0,
|
||||||
|
"discount_invoiced": 0,
|
||||||
|
"discount_percent": 0,
|
||||||
|
"free_shipping": 0,
|
||||||
|
"discount_tax_compensation_amount": 0,
|
||||||
|
"is_qty_decimal": 0,
|
||||||
|
"is_virtual": 1,
|
||||||
|
"item_id": 80320,
|
||||||
|
"name": "Gesellschaft Ausgabe A, Arbeitsheft (eLehrmittel, Neuauflage)",
|
||||||
|
"no_discount": 0,
|
||||||
|
"order_id": 57614,
|
||||||
|
"original_price": 24,
|
||||||
|
"price": 23.41,
|
||||||
|
"price_incl_tax": 24,
|
||||||
|
"product_id": 8654,
|
||||||
|
"product_type": "virtual",
|
||||||
|
"qty_canceled": 0,
|
||||||
|
"qty_invoiced": 0,
|
||||||
|
"qty_ordered": 1,
|
||||||
|
"qty_refunded": 0,
|
||||||
|
"qty_shipped": 0,
|
||||||
|
"quote_item_id": 135169,
|
||||||
|
"row_invoiced": 0,
|
||||||
|
"row_total": 23.41,
|
||||||
|
"row_total_incl_tax": 24,
|
||||||
|
"sku": "978-3-0355-1185-7",
|
||||||
|
"store_id": 1,
|
||||||
|
"tax_amount": 0.59,
|
||||||
|
"tax_invoiced": 0,
|
||||||
|
"tax_percent": 2.5,
|
||||||
|
"updated_at": "2018-07-19 15:19:00",
|
||||||
|
"weight": 0.01
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"search_criteria": {
|
||||||
|
"filter_groups": [
|
||||||
|
{
|
||||||
|
"filters": [
|
||||||
|
{
|
||||||
|
"field": "customer_id",
|
||||||
|
"value": "49124",
|
||||||
|
"condition_type": "eq"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"total_count": 2
|
||||||
|
}
|
||||||
|
|
@ -7,15 +7,25 @@
|
||||||
#
|
#
|
||||||
# Created on 2019-10-02
|
# Created on 2019-10-02
|
||||||
# @author: chrigu <christian.cueni@iterativ.ch>
|
# @author: chrigu <christian.cueni@iterativ.ch>
|
||||||
|
import json
|
||||||
|
from unittest.mock import patch
|
||||||
from django.contrib.sessions.middleware import SessionMiddleware
|
from django.contrib.sessions.middleware import SessionMiddleware
|
||||||
from django.test import TestCase, RequestFactory
|
from django.test import TestCase, RequestFactory
|
||||||
from graphene.test import Client
|
from graphene.test import Client
|
||||||
|
|
||||||
from api.schema_public import schema
|
from api.schema_public import schema
|
||||||
from core.factories import UserFactory
|
from core.factories import UserFactory
|
||||||
|
from core.hep_client import HepClient
|
||||||
from registration.factories import LicenseTypeFactory, LicenseFactory
|
from registration.factories import LicenseTypeFactory, LicenseFactory
|
||||||
from users.models import Role
|
from users.models import Role
|
||||||
|
|
||||||
|
FAKE_TOKEN = 'abcd12345!'
|
||||||
|
|
||||||
|
with open('orders.json', 'r') as file:
|
||||||
|
order_data = file.read()
|
||||||
|
|
||||||
|
ORDERS = json.loads(order_data)
|
||||||
|
|
||||||
|
|
||||||
class PasswordResetTests(TestCase):
|
class PasswordResetTests(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
@ -50,12 +60,10 @@ class PasswordResetTests(TestCase):
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
def test_user_can_login(self):
|
@patch.object(HepClient, 'customer_token', return_value={'token': FAKE_TOKEN})
|
||||||
password = 'test123'
|
@patch.object(HepClient, 'customer_orders', return_value=ORDERS)
|
||||||
self.user.set_password(password)
|
def test_user_can_login(self, orders_mock, token_mock):
|
||||||
self.user.save()
|
result = self.make_login_mutation(self.user.email, 'test123')
|
||||||
|
|
||||||
result = self.make_login_mutation(self.user.email, password)
|
|
||||||
self.assertTrue(result.get('data').get('login').get('success'))
|
self.assertTrue(result.get('data').get('login').get('success'))
|
||||||
self.assertTrue(self.user.is_authenticated)
|
self.assertTrue(self.user.is_authenticated)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue