예제 #1
0
    def test_user_can_update_a_bucketlist_item(self):
        """Test that a user can update bucketlist items"""
        response = self.login()
        message = json.loads(response.data)
        token = message['token']

        # create a test Bucketlist
        self.client.post(api.url_for(Allbucketlists),
                         data=json.dumps({"name": "Life goals"}),
                         content_type='application/json',
                         headers={'Authorization': token})

        # create a test Bucketlist item
        response1 = self.client.post(api.url_for(Bucketlistitem, id=1),
                                     data=json.dumps(
                                         {"name": "Travel to Iceland."}),
                                     content_type='application/json',
                                     headers={'Authorization': token})

        # update the item
        response2 = self.client.put(
            api.url_for(Bucketitemsactions, id=1, item_id=1),
            data=json.dumps({"name": "Travel to Iceland updated."}),
            content_type='application/json',
            headers={'Authorization': token})

        # test item was updated
        self.assertEqual(response2.status_code, 200)
        data = json.loads(response2.data)
        self.assertIn("Travel to Iceland updated.", data['name'])
    def test_user_can_update_a_bucketlist_item(self):
        """Test that a user can update bucketlist items"""
        response = self.login()
        message = json.loads(response.data)
        token = message['token']

        # create a test Bucketlist
        self.client.post(
                         api.url_for(Allbucketlists),
                         data=json.dumps({"name": "Life goals"}),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        # create a test Bucketlist item
        response1 = self.client.post(
                         api.url_for(Bucketlistitem, id=1),
                         data=json.dumps({"name": "Travel to Iceland."}),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        # update the item
        response2 = self.client.put(
                         api.url_for(Bucketitemsactions, id=1, item_id=1),
                         data=json.dumps({"name": "Travel to Iceland updated."}),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        # test item was updated
        self.assertEqual(response2.status_code, 200)
        data = json.loads(response2.data)
        self.assertIn("Travel to Iceland updated.", data['name'])
    def test_for_error_conditions(self):
        """Test for error conditions."""
        response = self.login()
        message = json.loads(response.data)
        token = message['token']

        # create a test Bucketlist
        self.client.post(
                         api.url_for(Allbucketlists),
                         data=json.dumps({"name": "Life goals"}),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        # create a test Bucketlist item
        response1 = self.client.post(
                         api.url_for(Bucketlistitem, id=1),
                         data=json.dumps({"name": "Travel to Iceland."}),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        # test someone can't update item in nonexistent bucketlist
        response2 = self.client.put(
                         api.url_for(Bucketitemsactions, id=10, item_id=1),
                         data=json.dumps({"name": "Travel to Iceland updated."}),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        self.assertEqual(response2.status_code, 404)
        data = json.loads(response2.data)
        self.assertIn("Bucketlist item not found", data['Error'])

        # test someone can't delete nonexistent item
        response3 = self.client.delete(
                         api.url_for(Bucketitemsactions, id=1, item_id=2),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        self.assertEqual(response3.status_code, 404)
        data = json.loads(response3.data)
        self.assertIn("Bucketlist has no item with id 2", data['Error'])
예제 #4
0
    def logout(self, token):
        """
        Method to logout a test user.

        Returns:
            The response of the logout action
        """
        logout_response = self.client.get(api.url_for(Logout),
                                          content_type='application/json',
                                          headers={'Authorization': token})

        return logout_response
예제 #5
0
    def test_for_error_conditions(self):
        """Test for error conditions."""
        response = self.login()
        message = json.loads(response.data)
        token = message['token']

        # create a test Bucketlist
        self.client.post(api.url_for(Allbucketlists),
                         data=json.dumps({"name": "Life goals"}),
                         content_type='application/json',
                         headers={'Authorization': token})

        # create a test Bucketlist item
        response1 = self.client.post(api.url_for(Bucketlistitem, id=1),
                                     data=json.dumps(
                                         {"name": "Travel to Iceland."}),
                                     content_type='application/json',
                                     headers={'Authorization': token})

        # test someone can't update item in nonexistent bucketlist
        response2 = self.client.put(
            api.url_for(Bucketitemsactions, id=10, item_id=1),
            data=json.dumps({"name": "Travel to Iceland updated."}),
            content_type='application/json',
            headers={'Authorization': token})

        self.assertEqual(response2.status_code, 404)
        data = json.loads(response2.data)
        self.assertIn("Bucketlist item not found", data['Error'])

        # test someone can't delete nonexistent item
        response3 = self.client.delete(api.url_for(Bucketitemsactions,
                                                   id=1,
                                                   item_id=2),
                                       content_type='application/json',
                                       headers={'Authorization': token})

        self.assertEqual(response3.status_code, 404)
        data = json.loads(response3.data)
        self.assertIn("Bucketlist has no item with id 2", data['Error'])
    def logout(self, token):
        """
        Method to logout a test user.

        Returns:
            The response of the logout action
        """
        logout_response = self.client.get(
                        api.url_for(Logout),
                        content_type='application/json',
                        headers={'Authorization': token}
                        )

        return logout_response
예제 #7
0
    def test_authorized_user_can_create_bucketlists(self):
        """Test that a logged in user can create a bucketlist."""
        response = self.login()
        message = json.loads(response.data)
        token = message['token']

        response2 = self.client.post(
                                     api.url_for(Allbucketlists),
                                     data=json.dumps({"name": "Places I want to see"}),
                                     content_type='application/json',
                                     headers={'Authorization': token}
                                     )
        self.assertIn('Bucketlist created successfully.', response2.data)
        self.assertEqual(response2.status_code, 200)
예제 #8
0
    def test_authorized_user_can_delete_a_bucketlist(self):
        """Test that a user can delete a bucketlist."""
        # login and get the token
        response = self.login()
        message = json.loads(response.data)
        token = message['token']

        # create a test Bucketlist
        self.client.post(
                         api.url_for(Allbucketlists),
                         data=json.dumps({"name": "Life goals"}),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        # delete the bucketlist
        response = self.client.delete(
                         api.url_for(Onebucketlist, id=1),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        self.assertIn("Bucketlist 1 deleted successfully.", response.data)
예제 #9
0
    def test_authorized_user_can_access_all_bucketlists(self):
        """Test that a logged in user can see all his bucketlists."""
        response = self.login()
        message = json.loads(response.data)
        token = message['token']

        self.assertTrue(token)

        # create a test Bucketlist
        self.client.post(
                         api.url_for(Allbucketlists),
                         data=json.dumps({"name": "Life goals"}),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        # get all the bucketlists
        bucketlists = self.client.get(api.url_for(Allbucketlists),
                                                content_type='application/json',
                                                headers={'Authorization': token})

        self.assertEqual(response.status_code, 200)
        self.assertTrue(bucketlists)
        self.assertIn("Life goals", bucketlists.data)
예제 #10
0
    def test_authorized_user_can_edit_a_bucketlist(self):
        """Test that updating a bucketlist works as expected."""
        # login and get the token
        response = self.login()
        message = json.loads(response.data)
        token = message['token']

        # create a test Bucketlist
        self.client.post(
                         api.url_for(Allbucketlists),
                         data=json.dumps({"name": "Life goals"}),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        # check the bucketlist is there
        bucketlists = self.client.get(api.url_for(Onebucketlist, id=1),
                                                content_type='application/json',
                                                headers={'Authorization': token})

        self.assertEqual(response.status_code, 200)
        self.assertTrue(bucketlists)
        self.assertIn("Life goals", bucketlists.data)

        # update the bucketlist
        updated_bucketlist = self.client.put(
                         api.url_for(Onebucketlist, id=1),
                         data=json.dumps({"name": "Life goals forever"}),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        # check bucketlist is actually updated
        self.assertTrue(updated_bucketlist)
        self.assertEqual(updated_bucketlist.status_code, 200)
        self.assertIn("Life goals forever", updated_bucketlist.data)
예제 #11
0
    def test_authorized_user_can_access_bucketlist_by_id(self):
        """Test that a user can get one bucketlist by its id."""
        response = self.login()
        message = json.loads(response.data)
        token = message['token']

        self.assertTrue(token)

        # create a test Bucketlist
        self.client.post(
                         api.url_for(Allbucketlists),
                         data=json.dumps({"name": "Life goals"}),
                         content_type='application/json',
                         headers={'Authorization': token}
                         )

        # get the bucketlist by its id
        bucketlist = self.client.get(api.url_for(Onebucketlist, id=1),
                                                content_type='application/json',
                                                headers={'Authorization': token})

        self.assertEqual(response.status_code, 200)
        self.assertTrue(bucketlist)
        self.assertIn("Life goals", bucketlist.data)
예제 #12
0
    def login(self):
        """
        Method to log a test user in.

        Returns:
            The response of the login action
        """
        username = "******"
        password = "******"

        response = self.client.post(api.url_for(Login),
                                    data=json.dumps({
                                        'username': username,
                                        'password': password
                                    }),
                                    content_type='application/json')

        return response
    def login(self):
        """
        Method to log a test user in.

        Returns:
            The response of the login action
        """
        username = "******"
        password = "******"

        response = self.client.post(
                                    api.url_for(Login),
                                    data=json.dumps(
                                            {'username': username,
                                             'password': password
                                             }),
                                    content_type='application/json'
                                    )

        return response
예제 #14
0
    def test_unlogged_in_user_cant_access_bucketlists(self):
        """Test that an unlogged in user can't access bucketlists resource."""
        response = self.client.get(api.url_for(Allbucketlists))

        self.assertEqual(response.status_code, 401)
        self.assertIn('Unauthorized Access', response.data)
예제 #15
0
    def test_accessing_home_returns_welcome_message(self):
        """Test that accessing home page returns a welcome message."""
        response = self.client.get(api.url_for(Home))

        self.assertEqual(response.status_code, 200)
        self.assertIn('Welcome to the bucketlist API.', response.data)