def test_register_check_with_duplicate_id(self):
        """
        Checking register check
        :return:
        """
        client = Client()
        create_user()
        user = User(username=context.get('username'),
                    user_first_name=context.get('user_first_name'),
                    user_last_name=context.get('user_last_name'),
                    user_phone=context.get('user_phone'),
                    user_dob=context.get('user_dob'))
        user.save()

        response = client.post(reverse('service:register_check'), context, follow=True)
        self.assertEqual(response.status_code, 200)
        # Testing redirection
        redirect_chain = list()
        redirect_chain.append(("/register/", 302))
        self.assertEqual(response.redirect_chain, redirect_chain)

        # Test if user is created in models
        try:
            get_object_or_404(User, username=context.get('username'))
        except Http404:
            raise Http404

        user.delete()
        user = authenticate(username=context.get('username'), password=context.get('password'))
        self.assertEqual(user.is_active, True)
Beispiel #2
0
    def test_get_user(self):
        user = User(first_name='Paco',
                    last_name='Murcia',
                    phone_number='415-694-7777',
                    email='*****@*****.**',
                    address='55 Main St.',
                    password='')
        user.save()
        user_id = user.id

        url = reverse('user-detail', kwargs={'pk': user_id})
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual('Paco', response.data['first_name'])
Beispiel #3
0
    def test_activate_user_with_missing_data(self):
        user = User(first_name='Amparo',
                    last_name='Mondragon',
                    phone_number='415-694-5555',
                    email='*****@*****.**',
                    address='55 Main St.',
                    password='')
        user.save()
        user_id = user.id

        data = {'activation_code': user.activation_code}

        url = reverse('user-activate', kwargs={'pk': user_id})
        response = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def register_check_arena(request):
    username = request.POST['username']
    user_first_name = request.POST['user_first_name']
    user_last_name = request.POST['user_last_name']
    user_phone = request.POST['user_phone']
    user_dob = request.POST['user_dob']
    password = request.POST['password']
    repassword = request.POST['repassword']

    if username is None or \
                    user_first_name is None or \
                    user_last_name is None or \
                    user_phone is None or \
                    user_dob is None or \
                    password is None or \
                    password != repassword:
        message = "The password should be same in both the fields"
        alert_type = "danger"
        request.session['alert_message'] = message
        request.session['alert_type'] = alert_type
        return HttpResponseRedirect(reverse('service:register'))

    try:
        get_object_or_404(UserModel, username=username)
    except Http404:
        pass
    else:
        message = "User ID already present"
        alert_type = "danger"
        request.session['alert_message'] = message
        request.session['alert_type'] = alert_type
        return HttpResponseRedirect(reverse('service:register'))

    User.objects.create_user(username, password)
    user = UserModel(username=username,
                     user_first_name=user_first_name,
                     user_last_name=user_last_name,
                     user_phone=user_phone,
                     user_dob=user_dob)
    user.save()
    message = " ".join([user_first_name, user_last_name, "registered successfully"])
    alert_type = "success"
    request.session['alert_message'] = message
    request.session['alert_type'] = alert_type
    return HttpResponseRedirect(reverse('service:main_home'))
Beispiel #5
0
    def test_activate_user_previously_activated_with_valid_data(self):
        user = User(first_name='Paco',
                    last_name='Murcia',
                    phone_number='415-694-7777',
                    email='*****@*****.**',
                    address='55 Main St.',
                    password='')
        user.save()
        user_id = user.id

        data = {
            'activation_code': user.activation_code,
            'password': '******'
        }

        url = reverse('user-activate', kwargs={'pk': user_id})
        response = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        response = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Beispiel #6
0
 def create_and_save_model(username, first_name="", last_name="", phone="", dob=""):
     """
     Creates and saves new user for the database
     :param username:
     :param first_name:
     :param last_name:
     :param phone:
     :param dob:
     :return: True if new user created or already present else false
     """
     if not username or not username.strip():
         raise ValueError("User model cannot be created. Parameter missing.")
     if UserAdapter.exists(username=username):
         raise ValueError("User Model already present")
     else:
         user = User(username=username,
                     user_first_name=first_name,
                     user_last_name=last_name,
                     user_phone=phone,
                     user_dob=dob)
         user.save()
     return user
Beispiel #7
0
    def test_duplicate_user_email_error(self):
        user1 = User(first_name='Paula',
                     last_name='Rubio',
                     phone_number='415-694-8888',
                     email='*****@*****.**',
                     address='55 Main St.',
                     password='')
        user1.save()

        url = reverse('user-list')
        data = {
            'first_name': 'Paco',
            'last_name': 'Murcia',
            'phone_number': '415-694-7777',
            'email': '*****@*****.**',
            'address': '55 Main St.',
            'password': ''
        }

        response = self.client.post(url, data, format='json')

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Beispiel #8
0
    def test_populated_user_list(self):
        user1 = User(first_name='Paula',
                     last_name='Rubio',
                     phone_number='415-694-8888',
                     email='*****@*****.**',
                     address='55 Main St.',
                     password='')
        user1.save()

        user2 = User(first_name='Paco',
                     last_name='Murcia',
                     phone_number='415-694-7777',
                     email='*****@*****.**',
                     address='55 Main St.',
                     password='')
        user2.save()

        url = reverse('user-list')
        response = self.client.get(url, format='json')

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(User.objects.count(), len(response.data))
Beispiel #9
0
 def create_and_save_model(username, first_name="", last_name="", phone="", dob=""):
     """
     Creates and saves new user for the database
     :param username:
     :param first_name:
     :param last_name:
     :param phone:
     :param dob:
     :return: True if new user created or already present else false
     """
     if not username or not username.strip():
         raise ValueError("User model cannot be created. Parameter missing.")
     if UserAdapter.exists(username=username):
         raise ValueError("User Model already present")
     else:
         user = User(username=username,
                     user_first_name=first_name,
                     user_last_name=last_name,
                     user_phone=phone,
                     user_dob=dob)
         user.save()
     return user