<commit_before>from . base_test_case import BaseTestCase
import json


class BucketListApiTestCase(BaseTestCase):

    def setUp(self):
        self.bucketlist = json.dumps({"name": "some bucketlist",
                                      "created_by": "me",
                                      })

    def post(self):

        response = self.client.post('/bucketlists',
                                    data=self.bucketlist,
                                    content_type='application/json',
                                    headers={}
                                    )
        return response

    # Tests for entire bucketlist
    def test_cannot_create_empty_bucketlist(self):

        response = self.client.post('/bucketlists',
                                    data=json.dumps({}),
                                    content_type='application/json',
                                    headers={}
                                    )
        self.assertEqual(response.json, "Error! Bucketlist has no data")

    def test_return_message_if_no_bucketlists_exist(self):

        response = self.client.get('/bucketlists',
                                   content_type='application/json',
                                   headers={}
                                   )
        self.assertEqual(response.json, "No bucketlists to display")

    def test_cannot_create_duplicate_bucketlist(self):

        self.post()
        self.assertEqual(self.post().json, "Bucketlist already exists")

    def test_it_gets_all_bucket_lists(self):

        self.post()
        response = self.client.get('/bucketlists',
                                   content_type='application/json',
                                   headers={}
                                   )
        self.assertEqual(response.json, 200)
        self.assertIn("name", response.json)

    def test_it_creates_new_bucket_list(self):

        response = self.post()
        self.assertEqual(response.status_code, 201)
        # Assert that an item was added to db

    # Tests for single bucketlist entry
    def test_cannot_get_non_existent_bucketlist(self):

        self.post()
        response = self.client.get('/bucketlists/11',
                                   content_type='application/json',
                                   headers={}
                                   )
        self.assertEqual(response.json, "Bucketlist does not exist")

    def test_it_gets_bucketlist(self):

        self.post()
        response = self.client.get('/bucketlists/1',
                                   content_type='application/json',
                                   headers={}
                                   )
        self.assertIn("name", response.json)

    def test_cannot_update_non_existent_bucketlist(self):

        data = json.dumps({"new name": "something else"})
        self.post()
        response = self.client.put('/bucketlists/11',
                                   data=data,
                                   content_type='application/json',
                                   headers={}
                                   )
        self.assertEqual(response.json, "Item does not exist")

    def test_it_updates_bucketlist(self):

        data = json.dumps({"new name": "something else"})
        self.post()
        response = self.client.put('/bucketlists/1',
                                   data=data,
                                   content_type='application/json',
                                   headers={}
                                   )
        self.assertEqual(response.status_code, 200)

    def test_cannot_delete_non_existent_bucketlist(self):

        self.post()
        response = self.client.delete('/bucketlists/11',
                                      content_type='application/json',
                                      headers={}
                                      )
        self.assertEqual(response.json, "Item does not exist")

    def test_it_deletes_bucketlist(self):

        self.post()
        response = self.client.delete('/bucketlists/1',
                                      content_type='application/json',
                                      headers={}
                                      )
        self.assertEqual(response.status_code, 200)
        # Assert that an item was delted from db<commit_msg>Refactored tests for put and delete methods<commit_after>from . base_test_case import BaseTestCase
import json


class BucketListApiTestCase(BaseTestCase):

    def post(self, payload):
        response = self.client.post('/bucketlists',
                                    data=json.dumps(payload),
                                    content_type='application/json',
                                    headers={"Authorization": self.token}
                                    )
        return response

    # Tests for entire bucketlist
    def test_create_empty_bucketlist(self):

        response = self.post({})
        self.assertEqual(response.json,
                         {"error": "Bucketlist has no data"})

    def test_create_new_bucket_list(self):
        response = self.post({"name": "New bucketlist"})
        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.json,
                         {
                             "message": "created new bucketlist",
                             "name": "New bucketlist"
                         })

    def test_create_duplicate_bucketlist(self):
        self.post({"name": "Test bucketlist"})
        response = self.post({"name": "Test bucketlist"})
        self.assertEqual(
            response.json, {"message": "Bucketlist already exists"})

    def test_get_all_bucket_lists(self):
        self.post({"name": "Bucketlist one"})
        self.post({"name": "Bucketlist two"})
        self.post({"name": "Bucketlist three"})
        response = self.client.get('/bucketlists',
                                   content_type='application/json',
                                   headers={"Authorization": self.token}
                                   )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.json), 4)

    # Tests for single bucketlist entry
    def test_get_non_existent_bucketlist(self):
        # self.post({"name": "Test bucketlist"})
        response = self.client.get('/bucketlists/11',
                                   content_type='application/json',
                                   headers={"Authorization": self.token}
                                   )
        self.assertEqual(response.status_code, 404)
        self.assertEqual(response.json,
                         {"error": "Bucketlist not found"})

    def test_get_bucketlist(self):
        response = self.client.get('/bucketlists/1',
                                   content_type='application/json',
                                   headers={"Authorization": self.token}
                                   )
        self.assertEqual(response.json["name"],
                         "Test bucketlist")

    def test_update_non_existent_bucketlist(self):
        payload = {"new name": "something else"}
        response = self.client.put('/bucketlists/11',
                                   data=payload,
                                   content_type='application/json',
                                   headers={"Authorization": self.token}
                                   )
        self.assertEqual(response.status_code, 404)
        self.assertEqual(response.json,
                         {"error": "Bucketlist not found"})

    def test_update_bucketlist(self):
        payload = json.dumps({"name": "Renamed bucketlist"})
        self.post({"name": "Test bucketlist"})
        response = self.client.put('/bucketlists/1',
                                   data=payload,
                                   content_type='application/json',
                                   headers={"Authorization": self.token}
                                   )
        self.assertEqual(response.status_code, 200)

    def test_delete_non_existent_bucketlist(self):
        response = self.client.delete('/bucketlists/11',
                                      content_type='application/json',
                                      headers={"Authorization": self.token}
                                      )
        self.assertEqual(response.status_code, 404)

    def test_delete_bucketlist(self):
        self.post({"name": "Test bucketlist"})
        response = self.client.delete('/bucketlists/1',
                                      content_type='application/json',
                                      headers={"Authorization": self.token}
                                      )
        self.assertEqual(response.status_code, 204)
{'fraction_non_alphanumeric': 0.09627118644067796, 'fraction_numerical': 0.005875706214689265, 'mean_word_length': 1.3347401740965446, 'pattern_counts': {'":': 29, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 63, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7198537', 'n_tokens_mistral': 2149, 'n_tokens_neox': 1979, 'n_words': 352}