Ejemplo n.º 1
0
 def setUp(self):
     self.client = Client()
     self.factory = RequestFactory()
     self.user = create_random_user()
     self.admin = create_random_user()
     self.admin[0].is_staff = True
     self.admin[0].save()
     self.urls_to_test = ['mainpage', 'openid-login', 'openid-complete', 'landing_page', 'thanks', 'auth_login']
Ejemplo n.º 2
0
 def setUp(self):
     self.factory = RequestFactory()
     self.client = Client()
     self.users = [create_random_user() for item in range(1, random.randint(1, MAX_NUMBER_OF_USERS))]
     self.admins = list()
     for item in range(1, random.randint(1, MAX_NUMBER_OF_ADMINS)):
         user = create_random_user()
         user[0].is_staff = True
         user[0].save()
         self.admins.append(user)
     urls_to_test = ['profile:all']
     for user in User.objects.all():
         urls_to_test.append((('profile:profile', user.pk)))
         urls_to_test.append((('profile:change', user.pk)))
     self.urls_to_test = urls_to_test
Ejemplo n.º 3
0
 def test_user_rights(self):
     restricted_urls = [
         x
         for x in self.urls_to_test
         if x in ("books:add", "books:add_tag", "books:add_author")
         or (type(x) is TupleType and x[0] in ("books:delete", "books:change"))
     ]
     allowed_urls = list(set(self.urls_to_test) - set(restricted_urls))
     user = create_random_user()
     self.client.login(username=user[0].username, password=user[1])
     delta_percent = count_delta(len(self.urls_to_test))
     percentage = delta_percent
     for url in allowed_urls:
         percentage = write_percentage(percentage, delta_percent)
         if type(url) is TupleType:
             urln = url[0]
             urlp = url[1]
             request = self.client.get(reverse(urln, kwargs={"pk": urlp}))
         else:
             urln = url
             request = self.client.get(reverse(urln))
         if request.status_code == 200:
             self.assertEqual(request.status_code, 200)
         else:
             self.assertTrue(not request["location"].startswith("http://testserver/auth/login?next="))
     for url in restricted_urls:
         percentage = write_percentage(percentage, delta_percent)
         if type(url) is TupleType:
             urln = url[0]
             urlp = url[1]
             request = self.client.get(reverse(urln, kwargs={"pk": urlp}))
         else:
             urln = url
             request = self.client.get(reverse(urln))
         self.assertEqual(request.status_code, 302)
Ejemplo n.º 4
0
 def setUp(self):
     self.client = Client()
     self.factory = RequestFactory()
     self.users = [create_random_user() for item in range(1, random.randint(1, MAX_NUMBER_OF_USERS))]
     self.urls_to_test = ['auth_login', 'auth_logout', 'registration_register', 'registration_activation_complete',
                          'registration_complete', 'registration_disallowed',
                          'password_change', 'auth_password_change_done']
Ejemplo n.º 5
0
 def setUp(self):
     self.client = Client()
     self.factory = RequestFactory()
     admin = create_random_user()
     self.admin = admin[0]
     self.admin.is_staff = True
     self.admin.save()
     self.client.login(username=admin[0].username, password=admin[1])
Ejemplo n.º 6
0
 def test_admin_rights(self):
     user = create_random_user()
     user[0].is_staff = True
     user[0].save()
     authenticate(username=user[0].username, password=user[1])
     self.client.login(username=user[0].username, password=user[1])
     delta_percent = count_delta(len(self.urls_to_test))
     percentage = delta_percent
     for url in self.urls_to_test:
         percentage = write_percentage(percentage, delta_percent)
         if type(url) is TupleType:
             urln = url[0]
             urlp = url[1]
             request = self.client.get(reverse(urln, kwargs={"pk": urlp}))
         else:
             urln = url
             request = self.client.get(reverse(urln))
         if request.status_code == 200:
             self.assertEqual(request.status_code, 200)
         else:
             self.assertTrue(not request["location"].startswith("http://testserver/auth/login?next="))
Ejemplo n.º 7
0
    def test_take_return_ask_successfully(self):
        user1 = create_random_user()
        user2 = create_random_user()
        delta_percent = count_delta(NUMBER_OF_ITERATIONS_A_T_R)
        percentage = delta_percent
        for i in range(1, NUMBER_OF_ITERATIONS_A_T_R):
            percentage = write_percentage(percentage, delta_percent)
            book = Book.books.create(title="test_book" + str(i))
            # first_user asks free book
            self.client.login(username=user1[0].username, password=user1[1])
            request = self.client.get(reverse("books:ask", kwargs={"pk": book.pk}))
            self.assertEqual(request.status_code, 302)
            self.assertTrue(request["location"] == "http://testserver/books/")  # You can't ask free book
            # and take it
            request = self.client.get(reverse("books:take", kwargs={"pk": book.pk}))
            self.assertTrue(request["location"] == "http://testserver/books/")  # You can take free book
            # book really taken by him
            book = Book.books.get(pk=i)
            self.assertTrue(book.busy and book in user1[0].get_users_books())
            # second user logs in
            self.client.logout()
            self.client.login(username=user2[0].username, password=user2[1])
            # and tried to take busy book
            request = self.client.get(reverse("books:take", kwargs={"pk": book.pk}))
            self.assertEqual(request.status_code, 302)
            self.assertEqual(request["location"], "http://testserver/books/")  # You can't take busy book
            book = Book.books.get(pk=i)
            self.assertTrue(book not in user2[0].get_users_books())
            # and to return
            request = self.client.get(reverse("books:return", kwargs={"pk": book.pk}))
            self.assertEqual(request.status_code, 302)
            self.assertEqual(request["location"], "http://testserver/books/")  # You can't return busy (not yours) book
            book = Book.books.get(pk=i)
            self.assertTrue(book.busy and book in user1[0].get_users_books())
            # he asks this book
            request = self.client.get(reverse("books:ask", kwargs={"pk": book.pk}))
            self.assertEqual(request.status_code, 200)  # You can ask busy book
            # and secondone logs in
            self.client.logout()
            self.client.login(username=user1[0].username, password=user1[1])
            # he returns book and book is returned
            request = self.client.get(reverse("books:return", kwargs={"pk": book.pk}))
            self.assertEqual(request["location"], "http://testserver/books/")  # You can return book
            book = Book.books.get(pk=i)
            self.assertTrue(not book.busy and book not in user1[0].get_users_books())
            # first user logs in
            self.client.logout()
            self.client.login(username=user2[0].username, password=user2[1])
            # takes book
            request = self.client.get(reverse("books:take", kwargs={"pk": book.pk}))
            self.assertEqual(request["location"], "http://testserver/books/")
            book = Book.books.get(pk=i)
            self.assertTrue(
                book.busy and (book in user2[0].get_users_books())
            )  # You can take free book after it was taken
            # looks at it in his profile
            request = self.client.get(reverse("profile:profile", kwargs={"pk": user2[0].pk}))
            self.assertEqual(request.status_code, 200)
            # and returns it
            request = self.client.get(reverse("books:return", kwargs={"pk": book.pk}))
            self.assertEqual(request["location"], "http://testserver/books/")
            book = Book.books.get(pk=i)
            books = user2[0].get_users_books()
            self.assertTrue(not book.busy and (book not in user2[0].get_users_books()))

            self.client.logout()