# Path: adl_lrs/views.py
# @csrf_protect
# @require_http_methods(["POST", "GET"])
# def register(request):
#     if request.method == 'GET':
#         form = RegisterForm()
#         return render(request, 'register.html', {"form": form})
#     elif request.method == 'POST':
#         form = RegisterForm(request.POST)
#         if form.is_valid():
#             name = form.cleaned_data['username']
#             pword = form.cleaned_data['password']
#             email = form.cleaned_data['email']
# 
#             # If username doesn't already exist
#             if not User.objects.filter(username__exact=name).count():
#                 # if email doesn't already exist
#                 if not User.objects.filter(email__exact=email).count():
#                     User.objects.create_user(name, email, pword)
#                 else:
#                     return render(request, 'register.html', {"form": form, "error_message": "Email %s is already registered." % email})
#             else:
#                 return render(request, 'register.html', {"form": form, "error_message": "User %s already exists." % name})
# 
#             # If a user is already logged in, log them out
#             if request.user.is_authenticated:
#                 logout(request)
# 
#             new_user = authenticate(username=name, password=pword)
#             login(request, new_user)
#             return HttpResponseRedirect(reverse('home'))
#         else:
#             return render(request, 'register.html', {"form": form})


import hashlib
import urllib.request, urllib.parse, urllib.error
import os
import json
import base64
import ast
import uuid
        import ast
from django.test import TestCase
from django.conf import settings
from django.urls import reverse
from adl_lrs.views import register




class ActivityStateTests(TestCase):
    url = reverse('lrs:activity_state')
    testagent = '{"name":"test","mbox":"mailto:test@example.com"}'
    otheragent = '{"name":"other","mbox":"mailto:other@example.com"}'
    activityId = "http://www.iana.org/domains/example/"
    activityId2 = "http://www.google.com"
    stateId = "the_state_id"
    stateId2 = "state_id_2"
    stateId3 = "third_state_id"
    stateId4 = "4th.id"
    registration = str(uuid.uuid1())
    content_type = "application/json"

    @classmethod
    def setUpClass(cls):
        print("\n%s" % __name__)
        super(ActivityStateTests, cls).setUpClass()

    def setUp(self):
        self.username = "test"
        self.email = "test@example.com"
        self.password = "test"
        self.auth = "Basic %s" % base64.b64encode(
            "%s:%s" % (self.username, self.password))
        form = {'username': self.username, 'email': self.email,
                'password': self.password, 'password2': self.password}

# Path: adl_lrs/views.py
# @csrf_protect
# @require_http_methods(["POST", "GET"])
# def register(request):
#     if request.method == 'GET':
#         form = RegisterForm()
#         return render(request, 'register.html', {"form": form})
#     elif request.method == 'POST':
#         form = RegisterForm(request.POST)
#         if form.is_valid():
#             name = form.cleaned_data['username']
#             pword = form.cleaned_data['password']
#             email = form.cleaned_data['email']
# 
#             # If username doesn't already exist
#             if not User.objects.filter(username__exact=name).count():
#                 # if email doesn't already exist
#                 if not User.objects.filter(email__exact=email).count():
#                     User.objects.create_user(name, email, pword)
#                 else:
#                     return render(request, 'register.html', {"form": form, "error_message": "Email %s is already registered." % email})
#             else:
#                 return render(request, 'register.html', {"form": form, "error_message": "User %s already exists." % name})
# 
#             # If a user is already logged in, log them out
#             if request.user.is_authenticated:
#                 logout(request)
# 
#             new_user = authenticate(username=name, password=pword)
#             login(request, new_user)
#             return HttpResponseRedirect(reverse('home'))
#         else:
#             return render(request, 'register.html', {"form": form})


# Path: lrs/tests/test_ActivityState.py
import hashlib
import urllib.request, urllib.parse, urllib.error
import os
import json
import base64
import ast
import uuid
        import ast
from django.test import TestCase
from django.conf import settings
from django.urls import reverse
from adl_lrs.views import register





class ActivityStateTests(TestCase):
    url = reverse('lrs:activity_state')
    testagent = '{"name":"test","mbox":"mailto:test@example.com"}'
    otheragent = '{"name":"other","mbox":"mailto:other@example.com"}'
    activityId = "http://www.iana.org/domains/example/"
    activityId2 = "http://www.google.com"
    stateId = "the_state_id"
    stateId2 = "state_id_2"
    stateId3 = "third_state_id"
    stateId4 = "4th.id"
    registration = str(uuid.uuid1())
    content_type = "application/json"

    @classmethod
    def setUpClass(cls):
        print("\n%s" % __name__)
        super(ActivityStateTests, cls).setUpClass()

    def setUp(self):
        self.username = "test"
        self.email = "test@example.com"
        self.password = "test"
        self.auth = "Basic %s" % base64.b64encode(
            "%s:%s" % (self.username, self.password))
        form = {'username': self.username, 'email': self.email,
                'password': self.password, 'password2': self.password}

        self.client.post(reverse(register), form,