<commit_before>#
# Copyright (C) 2007-2013 by frePPLe bvba
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from django.http import StreamingHttpResponse
from django.test import TestCase


class OutputTest(TestCase):

    fixtures = ["demo"]

    def checkResponse(self, response):
        if isinstance(response, StreamingHttpResponse):
            for rec in response.streaming_content:
                rec
        self.assertEqual(response.status_code, 200)

    def setUp(self):
        # Login
        self.client.login(username="admin", password="<PASSWORD>")

    # Buffer
    def test_output_buffer(self):
        response = self.client.get("/buffer/?format=json")
        self.assertContains(response, '"records":0,')
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/buffer/?format=csvtable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/buffer/?format=csvlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/buffer/?format=spreadsheettable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )
        response = self.client.get("/flowplan/?format=json")
        self.checkResponse(response)

    # Resource
    def test_output_resource(self):
        response = self.client.get("/resource/?format=json")
        self.assertContains(response, '"records":3,')
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/resource/?format=csvtable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/resource/?format=spreadsheetlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )
        response = self.client.get("/loadplan/?format=json")
        self.checkResponse(response)

    # Demand
    def test_output_demand(self):
        response = self.client.get("/demand/")
        self.assertContains(response, "Demand report")
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/demand/?format=csvlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/demand/?format=spreadsheettable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )

    # Manufacturing orders
    def test_output_manufacturing_orders(self):
        response = self.client.get("/operation/?format=json")
        self.assertContains(response, '"records":0,')
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/operation/?format=csvtable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/operation/?format=spreadsheetlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )

    # Purchase orders
    def test_output_purchase_orders(self):
        response = self.client.get("/purchase/?format=json")
        self.assertContains(response, '"records":4,')
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/purchase/?format=csvtable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/purchase/?format=spreadsheetlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )

    # Distribution orders
    def test_output_distribution_orders(self):
        response = self.client.get("/distribution/?format=json")
        self.assertContains(response, '"records":0,')
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/distribution/?format=csvtable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/distribution/?format=spreadsheetlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )

    # Problem
    def test_output_problem(self):
        response = self.client.get("/problem/?format=json")
        self.assertContains(response, '"records":0,')  # specific for community
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/problem/?format=csvlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/problem/?format=spreadsheetlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )

    # Pegging
    def test_output_pegging(self):
        response = self.client.get("/demandpegging/Demand%2001/?format=json")<commit_msg>test result not specific to community edition any longer<commit_after>#
# Copyright (C) 2007-2013 by frePPLe bvba
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public
# License along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

from django.http import StreamingHttpResponse
from django.test import TestCase


class OutputTest(TestCase):

    fixtures = ["demo"]

    def checkResponse(self, response):
        if isinstance(response, StreamingHttpResponse):
            for rec in response.streaming_content:
                rec
        self.assertEqual(response.status_code, 200)

    def setUp(self):
        # Login
        self.client.login(username="admin", password="<PASSWORD>")

    # Buffer
    def test_output_buffer(self):
        response = self.client.get("/buffer/?format=json")
        self.assertContains(response, '"records":0,')
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/buffer/?format=csvtable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/buffer/?format=csvlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/buffer/?format=spreadsheettable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )
        response = self.client.get("/flowplan/?format=json")
        self.checkResponse(response)

    # Resource
    def test_output_resource(self):
        response = self.client.get("/resource/?format=json")
        self.assertContains(response, '"records":3,')
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/resource/?format=csvtable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/resource/?format=spreadsheetlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )
        response = self.client.get("/loadplan/?format=json")
        self.checkResponse(response)

    # Demand
    def test_output_demand(self):
        response = self.client.get("/demand/")
        self.assertContains(response, "Demand report")
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/demand/?format=csvlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/demand/?format=spreadsheettable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )

    # Manufacturing orders
    def test_output_manufacturing_orders(self):
        response = self.client.get("/operation/?format=json")
        self.assertContains(response, '"records":0,')
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/operation/?format=csvtable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/operation/?format=spreadsheetlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )

    # Purchase orders
    def test_output_purchase_orders(self):
        response = self.client.get("/purchase/?format=json")
        self.assertContains(response, '"records":4,')
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/purchase/?format=csvtable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/purchase/?format=spreadsheetlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )

    # Distribution orders
    def test_output_distribution_orders(self):
        response = self.client.get("/distribution/?format=json")
        self.assertContains(response, '"records":0,')
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/distribution/?format=csvtable")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/distribution/?format=spreadsheetlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )

    # Problem
    def test_output_problem(self):
        response = self.client.get("/problem/?format=json")
        self.assertContains(response, '"records":0,')
        self.assertEqual(response.status_code, 200)
        response = self.client.get("/problem/?format=csvlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith("text/csv; charset=")
        )
        response = self.client.get("/problem/?format=spreadsheetlist")
        self.checkResponse(response)
        self.assertTrue(
            response.__getitem__("Content-Type").startswith(
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            )
        )

    # Pegging
    def test_output_pegging(self):
        response = self.client.get("/demandpegging/Demand%2001/?format=json")
{'fraction_non_alphanumeric': 0.11670840787119857, 'fraction_numerical': 0.006153846153846154, 'mean_word_length': 2.752953813104189, 'pattern_counts': {'":': 12, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 14}, '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': '7025911', 'n_tokens_mistral': 3918, 'n_tokens_neox': 3701, 'n_words': 624}