<commit_before>import json
from tests.base import Base


class TestItemResource(Base):
    """ This class contains tests for login and registeration
        of user accounts
    """

    def test_gets_single_item(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "go bunjee jumping"
                         }),
                         headers=self.set_headers())

        response = self.client.get("/bucketlists/1/items/1",
                                   headers=self.set_headers())

        payload = json.loads(response.data.decode())
        self.assertEquals(payload["name"], "go bunjee jumping")

        self.assertFalse(payload["done"])
        self.assertEquals(response.status_code, 200)

    def test_updates_item(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "go bunjee jumping"
                         }),
                         headers=self.set_headers())

        response = self.client.put("/bucketlists/1/items/1",
                                   data=json.dumps({
                                       "name": "go climbing",
                                       "done": True

                                   }),
                                   headers=self.set_headers())

        payload = json.loads(response.data.decode())
        self.assertEquals(payload["message"], "Item updated successfully")
        self.assertEquals(response.status_code, 200)

    def test_deletes_item(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "go bunjee jumping"
                         }),
                         headers=self.set_headers())


        response = self.client.delete("/bucketlists/1/items/1",
                                     headers=self.set_headers())

        payload = json.loads(response.data.decode())
        self.assertEquals(payload["message"],
                          "Item deleted successfully")

        self.assertEquals(response.status_code, 200)

    def test_update_item_with_same_name(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "go bunjee jumping"
                         }),
                         headers=self.set_headers())

        response = self.client.put("/bucketlists/1/items/1",
                                   data=json.dumps({
                                       "name": "go bunjee jumping",
                                   }),
                                   headers=self.set_headers())

        payload = json.loads(response.data.decode())

        self.assertEquals(payload["message"],
                          "Item with similar name already exists")
        self.assertEquals(response.status_code, 409)

    def test_get_non_existing_item(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "<NAME>"
                         }),
                         headers=self.set_headers())

        response = self.client.get("/bucketlists/1/items/2",
                                   headers=self.set_headers())

        payload = json.loads(response.data.decode())
        self.assertEquals(payload["message"],
                          "Item not found")
        self.assertEquals(response.status_code, 404)


    def test_update_non_existing_bucket_items(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "<NAME>"
                         }),
                         headers=self.set_headers())

        response = self.client.put("/bucketlists/2/items/2",
                                   data=json.dumps({
                                       "name": "<NAME>"
                                   }),
                                   headers=self.set_headers())<commit_msg>[CHORE] Add test to get items for non existing bucketlist<commit_after>import json
from tests.base import Base


class TestItemResource(Base):
    """ This class contains tests for login and registeration
        of user accounts
    """

    def test_gets_single_item(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "go bunjee jumping"
                         }),
                         headers=self.set_headers())

        response = self.client.get("/bucketlists/1/items/1",
                                   headers=self.set_headers())

        payload = json.loads(response.data.decode())
        self.assertEquals(payload["name"], "go bunjee jumping")

        self.assertFalse(payload["done"])
        self.assertEquals(response.status_code, 200)

    def test_updates_item(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "go bunjee jumping"
                         }),
                         headers=self.set_headers())

        response = self.client.put("/bucketlists/1/items/1",
                                   data=json.dumps({
                                       "name": "go climbing",
                                       "done": True

                                   }),
                                   headers=self.set_headers())

        payload = json.loads(response.data.decode())
        self.assertEquals(payload["message"], "Item updated successfully")
        self.assertEquals(response.status_code, 200)

    def test_deletes_item(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "go bunjee jumping"
                         }),
                         headers=self.set_headers())


        response = self.client.delete("/bucketlists/1/items/1",
                                     headers=self.set_headers())

        payload = json.loads(response.data.decode())
        self.assertEquals(payload["message"],
                          "Item deleted successfully")

        self.assertEquals(response.status_code, 200)

    def test_update_item_with_same_name(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "go bunjee jumping"
                         }),
                         headers=self.set_headers())

        response = self.client.put("/bucketlists/1/items/1",
                                   data=json.dumps({
                                       "name": "go bunjee jumping",
                                   }),
                                   headers=self.set_headers())

        payload = json.loads(response.data.decode())

        self.assertEquals(payload["message"],
                          "Item with similar name already exists")
        self.assertEquals(response.status_code, 409)

    def test_get_non_existing_item(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "<NAME>"
                         }),
                         headers=self.set_headers())

        response = self.client.get("/bucketlists/1/items/2",
                                   headers=self.set_headers())

        payload = json.loads(response.data.decode())
        self.assertEquals(payload["message"],
                          "Item not found")
        self.assertEquals(response.status_code, 404)

    def test_get_non_existing__bucket_item(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "<NAME>"
                         }),
                         headers=self.set_headers())

        response = self.client.get("/bucketlists/2/items/1",
                                   headers=self.set_headers())

        payload = json.loads(response.data.decode())
        self.assertEquals(payload["message"],
                          "Bucketlist not found")
        self.assertEquals(response.status_code, 404)


    def test_update_non_existing_bucket_items(self):
        self.client.post("/bucketlists",
                         data=json.dumps({
                             "name": "<NAME>",
                             "description": "testing"
                         }),
                         headers=self.set_headers())

        self.client.post("/bucketlists/1/items",
                         data=json.dumps({
                             "name": "<NAME>"
                         }),
                         headers=self.set_headers())

        response = self.client.put("/bucketlists/2/items/2",
                                   data=json.dumps({
                                       "name": "<NAME>"
                                   }),
                                   headers=self.set_headers())
{'fraction_non_alphanumeric': 0.11286791534906349, 'fraction_numerical': 0.005837995621503284, 'mean_word_length': 1.060474440360842, 'pattern_counts': {'":': 47, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 33, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6584348', 'n_tokens_mistral': 2890, 'n_tokens_neox': 2690, 'n_words': 407}