<commit_before>from django.test import Client, TransactionTestCase
import json
from jsonpath_rw import jsonpath, parse


class ArticleEndpointTest(TransactionTestCase):

    fixtures = ['articles_and_authors.json']
    endpoint = '/api/rest/v1/articles'

    def test_list(self):
        client = Client()
        response = client.get(ArticleEndpointTest.endpoint)
        self.assertEqual(response.status_code, 200)
        content = str(response.content, encoding='utf8')
        content_json = json.loads(content)

        # see more about jsonpath at http://goessner.net/articles/JsonPath/
        # and its python port at https://github.com/kennknowles/python-jsonpath-rw
        actual_ids = [match.value for match in parse('$.[*].id').find(content_json)]
        self.assertEquals([1], actual_ids)

    def test_404_when_id_doesnt_exist(self):
        client = Client()
        response = client.get(ArticleEndpointTest.endpoint + '/123')
        self.assertEqual(response.status_code, 404)

    def test_post(self):
        client = Client()
        json_str = json.dumps({
            "title": "a nice title",
            "url": "http://johndoo.org",
            "content": "dummy content",
        })
        response = client.post(ArticleEndpointTest.endpoint, data=json_str, content_type="application/json")
        self.assertEqual(response.status_code, 201)

    def test_delete(self):
        client = Client()
        response = client.delete(ArticleEndpointTest.endpoint + '/1')
        self.assertEqual(response.status_code, 204)

    def test_delete_not_found(self):
        client = Client()
        response = client.delete(ArticleEndpointTest.endpoint + '/123')
        self.assertEqual(response.status_code, 404)


class AuthorEndpointTest(TransactionTestCase):

    fixtures = ['articles_and_authors.json']
    endpoint = '/api/rest/v1/authors'

    def test_list(self):
        client = Client()
        response = client.get(AuthorEndpointTest.endpoint)
        self.assertEqual(response.status_code, 200)
        content = str(response.content, encoding='utf8')
        content_json = json.loads(content)

        # see more about jsonpath at http://goessner.net/articles/JsonPath/
        # and its python port at https://github.com/kennknowles/python-jsonpath-rw
        actual_ids = [match.value for match in parse('$.[*].id').find(content_json)]
        self.assertEquals([1, 2], actual_ids)

    def test_404_when_id_doesnt_exist(self):
        client = Client()
        response = client.get(AuthorEndpointTest.endpoint + '/123')
        self.assertEqual(response.status_code, 404)

    def test_post(self):
        client = Client()
        json_str = json.dumps({
            "id": 1,
            "name": "<NAME>",
            "profile_url": "http://johndoo.org",
        })
        response = client.post(AuthorEndpointTest.endpoint, data=json_str, content_type="application/json")
        self.assertEqual(response.status_code, 201)<commit_msg>Fix test that failed due to ordering change performed on last commit 6fd475ef3fde4cef0786c6429f71b842da779a7c<commit_after>from django.test import Client, TransactionTestCase
import json
from jsonpath_rw import jsonpath, parse


class ArticleEndpointTest(TransactionTestCase):

    fixtures = ['articles_and_authors.json']
    endpoint = '/api/rest/v1/articles'

    def test_list(self):
        client = Client()
        response = client.get(ArticleEndpointTest.endpoint)
        self.assertEqual(response.status_code, 200)
        content = str(response.content, encoding='utf8')
        content_json = json.loads(content)

        # see more about jsonpath at http://goessner.net/articles/JsonPath/
        # and its python port at https://github.com/kennknowles/python-jsonpath-rw
        actual_ids = [match.value for match in parse('$.[*].id').find(content_json)]
        self.assertEquals([1], actual_ids)

    def test_404_when_id_doesnt_exist(self):
        client = Client()
        response = client.get(ArticleEndpointTest.endpoint + '/123')
        self.assertEqual(response.status_code, 404)

    def test_post(self):
        client = Client()
        json_str = json.dumps({
            "title": "a nice title",
            "url": "http://johndoo.org",
            "content": "dummy content",
        })
        response = client.post(ArticleEndpointTest.endpoint, data=json_str, content_type="application/json")
        self.assertEqual(response.status_code, 201)

    def test_delete(self):
        client = Client()
        response = client.delete(ArticleEndpointTest.endpoint + '/1')
        self.assertEqual(response.status_code, 204)

    def test_delete_not_found(self):
        client = Client()
        response = client.delete(ArticleEndpointTest.endpoint + '/123')
        self.assertEqual(response.status_code, 404)


class AuthorEndpointTest(TransactionTestCase):

    fixtures = ['articles_and_authors.json']
    endpoint = '/api/rest/v1/authors'

    def test_list(self):
        client = Client()
        response = client.get(AuthorEndpointTest.endpoint)
        self.assertEqual(response.status_code, 200)
        content = str(response.content, encoding='utf8')
        content_json = json.loads(content)

        # see more about jsonpath at http://goessner.net/articles/JsonPath/
        # and its python port at https://github.com/kennknowles/python-jsonpath-rw
        actual_ids = [match.value for match in parse('$.[*].id').find(content_json)]
        self.assertEquals([2, 1], actual_ids)

    def test_404_when_id_doesnt_exist(self):
        client = Client()
        response = client.get(AuthorEndpointTest.endpoint + '/123')
        self.assertEqual(response.status_code, 404)

    def test_post(self):
        client = Client()
        json_str = json.dumps({
            "id": 1,
            "name": "<NAME>",
            "profile_url": "http://johndoo.org",
        })
        response = client.post(AuthorEndpointTest.endpoint, data=json_str, content_type="application/json")
        self.assertEqual(response.status_code, 201)
{'fraction_non_alphanumeric': 0.11782178217821782, 'fraction_numerical': 0.019636963696369636, 'mean_word_length': 2.9744262295081967, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1851644', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1704, 'n_words': 343}