Example #1
0
    def test_login_fail(self):
        """
        Tests that a user cannot login when the email is not confirmed, or
        username/password are wrong
        """

        # missing password
        assert (
            app.post("/session", data=dict(username="******", password=""), follow_redirects=True).status_code == 400
        )

        # not existing user
        assert (
            app.post("/session", data=dict(username="******", password="******"), follow_redirects=True).status_code
            == 404
        )

        create_test_user(app)
        # wrong password
        assert (
            app.post(
                "/session", data=dict(username="******", password="******"), follow_redirects=True
            ).status_code
            == 404
        )

        # email is not confirmed
        assert (
            app.post("/session", data=dict(username="******", password="******"), follow_redirects=True).status_code
            == 403
        )
        delete_test_user(app)
Example #2
0
 def test_api_user_post_fails_when_no_args(self):
     """
     Tests that user-post request fails when none of possible args is given
     """
     create_test_user(app)
     assert app.post("/user/1").status_code == 400
     delete_test_user(app)
Example #3
0
    def test_login_fail(self):
        """
        Tests that a user cannot login when the email is not confirmed, or
        username/password are wrong
        """

        # missing password
        assert app.post('/session',
                        data=dict(username='******', password=''),
                        follow_redirects=True).status_code == 400

        # not existing user
        assert app.post('/session',
                        data=dict(username='******', password='******'),
                        follow_redirects=True).status_code == 404

        create_test_user(app)
        # wrong password
        assert app.post('/session',
                        data=dict(username='******', password='******'),
                        follow_redirects=True).status_code == 404

        # email is not confirmed
        assert app.post('/session',
                        data=dict(username='******', password='******'),
                        follow_redirects=True).status_code == 403
        delete_test_user(app)
Example #4
0
 def test_api_user_post_fails_when_no_args(self):
     """
     Tests that user-post request fails when none of possible args is given
     """
     create_test_user(app)
     assert app.post('/user/1').status_code == 400
     delete_test_user(app)
Example #5
0
    def test_delete_user(self):
        # no password
        assert app.delete("/user/200").status_code == 400

        # no password or wrong password
        create_test_user(app)
        assert app.delete("/user/1", data=dict(password="")).status_code == 400
        assert app.delete("/user/1", data=dict(password="******")).status_code == 400
        delete_test_user(app)
Example #6
0
 def test_api_new_user_confirm_failed_post(self):
     """
     Tests that a new user is created
     and their email cannot be confirmed with a wrong hash
     """
     create_test_user(app)
     assert app.post('/user/1',
                     data=dict(confirm='wrong_testing_confirmation_hash'),
                     follow_redirects=True).status_code == 400
     delete_test_user(app)
Example #7
0
 def test_api_new_user_confirm_failed_post(self):
     """
     Tests that a new user is created
     and their email cannot be confirmed with a wrong hash
     """
     create_test_user(app)
     assert (
         app.post("/user/1", data=dict(confirm="wrong_testing_confirmation_hash"), follow_redirects=True).status_code
         == 400
     )
     delete_test_user(app)
Example #8
0
    def test_delete_user(self):
        # no password
        assert app.delete('/user/200').status_code == 400

        # no password or wrong password
        create_test_user(app)
        assert (app.delete('/user/1',
                           data=dict(password='')).status_code == 400)
        assert (app.delete('/user/1',
                           data=dict(password='******')).status_code == 400)
        delete_test_user(app)
Example #9
0
 def test_api_user_update(self):
     """
     Tests that the users' data is updated
     """
     create_test_user(app)
     assert app.post('/user/1',
                     data=dict(name='Marcus',
                               last_name='Aurelius',
                               profession='Emperor',
                               birthday='0121-04-26')).status_code == 201
     # TODO test that the user has really been updated,
     # when a json-response exists
     delete_test_user(app)
Example #10
0
 def test_api_user_update(self):
     """
     Tests that the users' data is updated
     """
     create_test_user(app)
     assert (
         app.post(
             "/user/1", data=dict(name="Marcus", last_name="Aurelius", profession="Emperor", birthday="0121-04-26")
         ).status_code
         == 201
     )
     # TODO test that the user has really been updated,
     # when a json-response exists
     delete_test_user(app)
Example #11
0
    def test_index_shows_books_and_reviews(self):
        # Creates a test book
        test_book = create_test_book()

        # Checks if the book appears in main page
        response = self.client.get(reverse('index'))
        self.assertTrue(len(response.context['highest_rated']) > 0)
        self.assertTrue(len(response.context['most_viewed']) > 0)
        # Test book is named Tango with Django just for testing purposes
        self.assertIn(b'Tango with Django', response.content)

        # Creates a test user
        test_user = create_test_user("Vlad")

        # Creates a test review
        test_review = create_test_review(
            test_user, test_book,
            "It was a pleasure reading this book and helped me a lot for a Web App Development course I took"
        )

        # Checks if a review appears in main page
        response = self.client.get(reverse('index'))
        self.assertTrue(len(response.context['recent_reviewed']) > 0)
        # Review's author should be displayed
        self.assertIn(b'Vlad', response.content)
        # Checks if at least a portion of review's text is shown
        self.assertIn(b'Web App Development course', response.content)
Example #12
0
	def setUp(self):
		self.to_delete = []
		self.user = create_test_user(username=TEST_USERNAME)
		self.jetpack = Jet(name=TEST_JETPACK_NAME, creator=self.user)
		self.jetpack.save()
		self.version = JetVersion(jetpack=self.jetpack, name='first', author=self.user)
		self.version.save()
Example #13
0
	def setUp(self):
		self.to_delete = []
		self.user = create_test_user(username=TEST_USERNAME)
		self.capability = Cap(name=TEST_CAP_NAME, creator=self.user)
		self.capability.save()
		self.version = CapVersion(capability=self.capability, name='first', author=self.user)
		self.version.save()
Example #14
0
    def test_profile_no_avatar(self):
        # Creates a test user
        test_user = create_test_user("Vlad")

        # Checks that a default avatar is shown when a user has not set an avatar yet
        response = self.client.get(
            reverse('profile', kwargs={'username': test_user.username}))
        self.assertIn(b'img src="/static/images/default_avatar.png"',
                      response.content)
Example #15
0
    def test_empty_reading_list(self):
        # Creates a test user
        test_user = create_test_user("Vlad")

        # Checks that a default avatar is shown when a user has not set an avatar yet
        response = self.client.get(
            reverse('reading_list', kwargs={'username': test_user.username}))
        self.assertIn(
            b'You currently don\'t have any books in your reading list',
            response.content)
Example #16
0
    def test_profile_favourite_book(self):
        # Creates a test user
        test_user = create_test_user("Vlad")
        # Creates a test book
        test_book = create_test_book()

        # Sets test user's favourite book
        userprofile = UserProfile.objects.get_or_create(user=test_user)[0]
        userprofile.favouriteBook = test_book.bookid
        userprofile.save()

        # Checks that a favourite book is displayed on profile page if it is set
        response = self.client.get(
            reverse('profile', kwargs={'username': test_user.username}))
        self.assertIn(
            b'src="https://s3.amazonaws.com/titlepages.leanpub.com/tangowithdjango19/hero?1518073904"',
            response.content)
Example #17
0
	def setUp(self):
		self.to_delete = []
		self.user = create_test_user(username=TEST_USERNAME)
		self.addon = Package(
			full_name=TEST_ADDON_FULLNAME, 
			author=self.user, 
			type='a'
		)
		self.addon.save()
		self.to_delete.append(self.addon)
		self.library = Package(
			full_name=TEST_LIBRARY_FULLNAME, 
			author=self.user, 
			type='l'
		)
		self.library.save()
		self.to_delete.append(self.library)
Example #18
0
    def test_filled_reading_list(self):
        # Creates a test user
        test_user = create_test_user("Vlad")
        # Creates a test book
        test_book = create_test_book()

        # Sets test book in user's reading list
        test_reading_list = ReadingList()
        test_reading_list.user = test_user
        test_reading_list.book = test_book
        test_reading_list.save()

        # Checks that a reading list shows books when they are added
        response = self.client.get(
            reverse('reading_list', kwargs={'username': test_user.username}))
        self.assertTrue(len(response.context['reading_data']) > 0)
        # Test book is called Tango with Django
        self.assertIn(b'Tango with Django', response.content)