Exemplo n.º 1
0
def get_orders(request):
    if not request.user.is_authenticated:
        messages.info(request, "Log in first!")
        return redirect("authorise")
    if CustomUser.get_by_email(request.user.email).role == 1:
        return render(request, "get_orders.html", {"orders": Order.objects.all()})
    return render(request, "get_orders.html", {"orders": Order.objects.all().filter(user_id=request.user.id)})
Exemplo n.º 2
0
def create_new_order(request):
    req = request.POST
    user = CustomUser.get_by_email(req.get('user_email'))
    book = Book.get_by_id(req.get('book_id'))
    plated_end_at = req.get('plated_end_at')
    new_order = Order.create(user, book, plated_end_at)
    return render(request,
                  'order/neworder.html',
                  context={'new_order': new_order})
Exemplo n.º 3
0
    def test_get_by_email_positive(self):
        user = CustomUser.get_by_email('*****@*****.**')

        self.assertEqual(user.id, 1)
        self.assertEqual(user.first_name, 'Bohdan')
        self.assertEqual(user.last_name, 'Dubas')
        self.assertEqual(user.phone, '123456789')
        self.assertEqual(user.email, '*****@*****.**')
        self.assertFalse(user.is_active)
Exemplo n.º 4
0
 def test_get_by_email_positive(self):
     """Positive test of the CustomUser.get_by_email() method"""
     user_returned = CustomUser.get_by_email('*****@*****.**')
     self.assertEqual(user_returned.id, 111)
     self.assertEqual(user_returned.email, '*****@*****.**')
     self.assertEqual(user_returned.password, '1234')
     self.assertEqual(user_returned.first_name, 'fname')
     self.assertEqual(user_returned.middle_name, 'mname')
     self.assertEqual(user_returned.last_name, 'lname')
     self.assertEqual(user_returned.created_at, TEST_DATE)
     self.assertEqual(user_returned.updated_at, TEST_DATE)
     self.assertEqual(user_returned.is_active, False)
Exemplo n.º 5
0
    def test_get_by_email_negative(self):
        user = CustomUser.get_by_email('*****@*****.**')

        self.assertIsNone(user)
Exemplo n.º 6
0
 def test_get_by_email_negative(self):
     """Negative test of the CustomUser.get_by_email() method"""
     user_to_expect = CustomUser.get_by_email('*****@*****.**')
     self.assertIsNone(user_to_expect)