Add comments, clean up code

This commit is contained in:
Christian Cueni 2020-03-17 16:13:00 +01:00
parent 0e52ab6f49
commit 737b682855
4 changed files with 8 additions and 9 deletions

View File

@ -36,6 +36,9 @@ class Registration(relay.ClientIDMutation):
try:
hep_client.customer_activate(confirmation_key, user_id)
user_data = hep_client.customers_by_id(admin_token, user_id)
# double check if user has verified his email. If the "confirmation" field is present, the email address
# is not verified. Note that the user should not be able to see this page without verified email.
if 'confirmation' in user_data:
return cls.return_registration_msg('invalid_key')
except HepClientException:
@ -53,7 +56,7 @@ class Registration(relay.ClientIDMutation):
@classmethod
def return_registration_msg(cls, message):
# even if the user has no valid license treat it like a success
# even if the user has no valid license on the hep server treat it like a success as registration has succeeded
if message == UNKNOWN_ERROR:
raise Exception(message)

View File

@ -74,7 +74,7 @@ class ProxyTest(TestCase):
@patch.object(HepClient, 'customer_create', return_value=RESPONSE)
def test_proxy_filters_confirmation_key(self, create_mock):
response = self.client.post(reverse('api:registration:proxy'), DATA)
response = self.client.post(reverse('api:registration:proxy'), json.dumps(DATA), content_type="application/json")
found = 'confirmation' in response.json().keys()
self.assertFalse(found)
@ -82,5 +82,5 @@ class ProxyTest(TestCase):
data={'message': 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.'}))
def test_handles_400(self, create_mock):
response = self.client.post(reverse('api:registration:proxy'), DATA)
response = self.client.post(reverse('api:registration:proxy'), json.dumps(DATA), content_type="application/json")
self.assertEquals(response.json()['message'], 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.')

View File

@ -19,11 +19,7 @@ class RegistrationProxyView(View):
def post(self, request, *args, **kwargs):
hep_client = HepClient()
if request.POST:
data = request.POST
else:
data = json.loads(request.body)
data = json.loads(request.body)
try:
hep_data = hep_client.customer_create(data)

View File

@ -225,4 +225,4 @@ class License(models.Model):
self.for_role.key)
def __str__(self):
return 'License for role: %s' % self.for_role
return f'License for role: {self.for_role}'