<commit_before>import json # enables inspecting JSON data for certain fields
from django.test import TestCase, Client
# NOTE: disabled these for now but expect they'll be used in the near future
# from django.urls import reverse
# from budget_app.models import OCRB
# from mixer.backend.django import mixer
# from rest_framework import status
# from rest_framework.test import APITestCase

# Other Ideas:
# - http://stackoverflow.com/questions/24904362/how-to-write-unit-tests-for-django-rest-framework-apis
# - https://github.com/hackoregon/hacku-devops-2017/wiki/Assignment-5
# - http://www.django-rest-framework.org/api-guide/testing/

class TestCodeEndpoint(TestCase):
    def setup(self):
        self.client = Client()

    def test(self):
        response = self.client.get('/budget/code/')

        self.assertEqual(response.status_code, 200)

    def test_code_get_request_works_with_query_param(self):
        response = self.client.get("/budget/code/?code=AT")
        self.assertEqual(response.status_code, 200)
        json_content = json.loads(response.content.decode('utf-8'))
        codes = [item["code"] for item in json_content]

        for code in codes:
            self.assertEqual(code, AT)

class TestHistoryEndpoint(TestCase):
    def setup(self):
        self.client = Client()

    def test(self):
        response = self.client.get('/budget/history/')

        self.assertEqual(response.status_code, 200)

    def test_history_get_request_works_with_query_param(self):
        response = self.client.get("/budget/history/?fiscal_year=2015-16&bureau_code=PS")
        self.assertEqual(response.status_code, 200)
        json_content = json.loads(response.content.decode('utf-8'))
        fiscal_years = [item["fiscal_year"] for item in json_content]

        for fiscal_year in fiscal_years:
            self.assertEqual(fiscal_year, 2015-16)

class TestKpmEndpoint(TestCase):
    def setup(self):
        self.client = Client()

    def test(self):
        response = self.client.get('/budget/kpm/')

        self.assertEqual(response.status_code, 200)

    def test_kpm_get_request_works_with_query_param(self):
        response = self.client.get("/budget/kpm/?fy=2015-16")
        self.assertEqual(response.status_code, 200)
        json_content = json.loads(response.content.decode('utf-8'))
        fiscal_years = [item["fy"] for item in json_content]

        for fiscal_year in fiscal_years:
            self.assertEqual(fiscal_year, 2015-16)

class TestOcrbEndpoint(TestCase):
    def setup(self):
        self.client = Client()

    def test(self):
        response = self.client.get('/budget/ocrb/')

        self.assertEqual(response.status_code, 200)

    def test_ocrb_get_request_works_with_query_param(self):
        response = self.client.get("/budget/ocrb/?fy=2015-16")
        self.assertEqual(response.status_code, 200)
        json_content = json.loads(response.content.decode('utf-8'))
        fiscal_years = [item["fy"] for item in json_content]

        for fiscal_year in fiscal_years:
            self.assertEqual(fiscal_year, 2015-16)<commit_msg>fix string typos in test<commit_after>import json # enables inspecting JSON data for certain fields
from django.test import TestCase, Client
# NOTE: disabled these for now but expect they'll be used in the near future
# from django.urls import reverse
# from budget_app.models import OCRB
# from mixer.backend.django import mixer
# from rest_framework import status
# from rest_framework.test import APITestCase

# Other Ideas:
# - http://stackoverflow.com/questions/24904362/how-to-write-unit-tests-for-django-rest-framework-apis
# - https://github.com/hackoregon/hacku-devops-2017/wiki/Assignment-5
# - http://www.django-rest-framework.org/api-guide/testing/

class TestCodeEndpoint(TestCase):
    def setup(self):
        self.client = Client()

    def test(self):
        response = self.client.get('/budget/code/')

        self.assertEqual(response.status_code, 200)

    def test_code_get_request_works_with_query_param(self):
        response = self.client.get("/budget/code/?code=AT")
        self.assertEqual(response.status_code, 200)
        json_content = json.loads(response.content.decode('utf-8'))
        codes = [item["code"] for item in json_content]

        for code in codes:
            self.assertEqual(code, 'AT')

class TestHistoryEndpoint(TestCase):
    def setup(self):
        self.client = Client()

    def test(self):
        response = self.client.get('/budget/history/')

        self.assertEqual(response.status_code, 200)

    def test_history_get_request_works_with_query_param(self):
        response = self.client.get("/budget/history/?fiscal_year=2015-16&bureau_code=PS")
        self.assertEqual(response.status_code, 200)
        json_content = json.loads(response.content.decode('utf-8'))
        fiscal_years = [item["fiscal_year"] for item in json_content]

        for fiscal_year in fiscal_years:
            self.assertEqual(fiscal_year, '2015-16')

class TestKpmEndpoint(TestCase):
    def setup(self):
        self.client = Client()

    def test(self):
        response = self.client.get('/budget/kpm/')

        self.assertEqual(response.status_code, 200)

    def test_kpm_get_request_works_with_query_param(self):
        response = self.client.get("/budget/kpm/?fy=2015-16")
        self.assertEqual(response.status_code, 200)
        json_content = json.loads(response.content.decode('utf-8'))
        fiscal_years = [item["fy"] for item in json_content]

        for fiscal_year in fiscal_years:
            self.assertEqual(fiscal_year, '2015-16')

class TestOcrbEndpoint(TestCase):
    def setup(self):
        self.client = Client()

    def test(self):
        response = self.client.get('/budget/ocrb/')

        self.assertEqual(response.status_code, 200)

    def test_ocrb_get_request_works_with_query_param(self):
        response = self.client.get("/budget/ocrb/?fy=2015-16")
        self.assertEqual(response.status_code, 200)
        json_content = json.loads(response.content.decode('utf-8'))
        fiscal_years = [item["fy"] for item in json_content]

        for fiscal_year in fiscal_years:
            self.assertEqual(fiscal_year, '2015-16')
{'fraction_non_alphanumeric': 0.11609583534330278, 'fraction_numerical': 0.024762823605081204, 'mean_word_length': 3.3224461431549686, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '2738956', 'n_tokens_mistral': 2041, 'n_tokens_neox': 1884, 'n_words': 365}