<commit_before>from django.test import TestCase
from database.models import *
from database.tests.factory import *
from database.views.api import *

class TableTest(TestCase):
    def test_showAllTables(self):
        # =================================================================
        # test serializer TableSerializer serializeAll()
        # {
        #     "tables": [
        #         {"name": "example", "columns": ["columname","anothercolum"]},
        #         {"name": "2nd", "columns": ["columname","anothercolum"]}
        #     ]
        # }
        # =================================================================

        schmog = DBUser.objects.create_user(username="test")
        schmog.save()

        table1 = create_table()
        table2 = create_table()

        connect_User_With_Rights(schmog,table1)
        connect_User_With_Rights(schmog,table2)

        result =  TableSerializer.serializeAll(schmog)

        length = 0
        table1Cols = list()
        for col in table1.getColumns():
            table1Cols.append(col.name)

        table2Cols = list()
        for col in table2.getColumns():
            table2Cols.append(col.name)
        # =================================================================
        # tests the columns of the tables have the same name as the columns of the result
        # =================================================================
        for table in result["tables"]:
            if table["name"] == table1.name:
                obj =  table
                self.assertEquals(table1Cols, obj["columns"])
            elif table["name"] == table2.name:
                obj = table
                self.assertEquals(table2Cols, obj["columns"])

        # =================================================================
        # tests the name of the table
        # =================================================================
        self.assertTrue(table1.name in [table["name"] for table in result["tables"]])
        self.assertTrue(table2.name in [table["name"] for table in result["tables"]])

        # =================================================================
        # tests the number of columns in the table
        # =================================================================
        for array in [table["columns"] for table in result["tables"]]:
            length += len(array)

        self.assertEquals(length, 10)

        print result

    # AM ARSCH !!!!!!!!!
    def test_showTable(self):
        # =================================================================
        #return the table with specified name, along with its columns and datasets.
        # {
        #     "name": "example",
        #     "datasets": [
        #         {"id": 38, "data": [ {"column": "id", "type": 1, "value": 0}, "column": "columnname", "type": 0, "value": "aString"}, {"column": "anothercolumn", "type": 5, "value": [1, 2], "table": "aTableName"} ]},  //row 1
        #         {"id": 18, "data": [ {"column": "id", "type": 1, "value": 17}, "column": "columnname", "type": 0, "value": "aString"}, {"column": "anothercolumn", "type": 5, "value": [13, 14], "table": "aTableName"} ]}   //row 2
        #     ]
        # }
        # =================================================================
        table1 = create_table()

        schmog = DBUser.objects.create_user(username="test")
        schmog.save()

        connect_User_With_Rights(schmog, table1)
        result = TableSerializer.serializeOne(table1.name,schmog)

        table1Cols = list()
        for col in table1.getColumns():
            table1Cols.append(col.name)

        print result

        self.assertTrue(table1.name in [table["name"] in result["name"]])

    # SOLLTE SO EIGENTLICH KLAPPEN
    def test_deleteTable(self):
        table1 = create_table()<commit_msg>factory is complete now and ready for api-testing<commit_after>from django.test import TestCase
from database.models import *
from database.tests.factory import *
from database.views.api import *

class TableTest(TestCase):
    def test_showAllTables(self):
        # =================================================================
        # test serializer TableSerializer serializeAll()
        # {
        #     "tables": [
        #         {"name": "example", "columns": ["columname","anothercolum"]},
        #         {"name": "2nd", "columns": ["columname","anothercolum"]}
        #     ]
        # }
        # =================================================================

        schmog = DBUser.objects.create_user(username="test")
        schmog.save()

        table1 = create_table()
        table2 = create_table()

        connect_User_With_Rights(schmog,table1)
        connect_User_With_Rights(schmog,table2)

        result =  TableSerializer.serializeAll(schmog)

        length = 0
        table1Cols = list()
        for col in table1.getColumns():
            table1Cols.append(col.name)

        table2Cols = list()
        for col in table2.getColumns():
            table2Cols.append(col.name)
        # =================================================================
        # tests the columns of the tables have the same name as the columns of the result
        # =================================================================
        for table in result["tables"]:
            if table["name"] == table1.name:
                obj =  table
                self.assertEquals(table1Cols, obj["columns"])
            elif table["name"] == table2.name:
                obj = table
                self.assertEquals(table2Cols, obj["columns"])

        # =================================================================
        # tests the name of the table
        # =================================================================
        self.assertTrue(table1.name in [table["name"] for table in result["tables"]])
        self.assertTrue(table2.name in [table["name"] for table in result["tables"]])

        # =================================================================
        # tests the number of columns in the table
        # =================================================================
        for array in [table["columns"] for table in result["tables"]]:
            length += len(array)

        self.assertEquals(length, 10)

    # AM ARSCH !!!!!!!!!
    def test_showTable(self):
        # =================================================================
        #return the table with specified name, along with its columns and datasets.
        # {
        #     "name": "example",
        #     "datasets": [
        #         {"id": 38, "data": [ {"column": "id", "type": 1, "value": 0}, "column": "columnname", "type": 0, "value": "aString"}, {"column": "anothercolumn", "type": 5, "value": [1, 2], "table": "aTableName"} ]},  //row 1
        #         {"id": 18, "data": [ {"column": "id", "type": 1, "value": 17}, "column": "columnname", "type": 0, "value": "aString"}, {"column": "anothercolumn", "type": 5, "value": [13, 14], "table": "aTableName"} ]}   //row 2
        #     ]
        # }
        # =================================================================
        table1 = create_table()

        schmog = DBUser.objects.create_user(username="test")
        schmog.save()

        connect_User_With_Rights(schmog, table1)
        result = TableSerializer.serializeOne(table1.name,schmog)

        table1Cols = list()
        for col in table1.getColumns():
            table1Cols.append(col.name)

        print result

        self.assertTrue(table1.name in [table["name"] in result["name"]])

    # SOLLTE SO EIGENTLICH KLAPPEN
    def test_deleteTable(self):
        table1 = create_table()
{'fraction_non_alphanumeric': 0.2846630518977537, 'fraction_numerical': 0.012651691195455719, 'mean_word_length': 2.78271484375, 'pattern_counts': {'":': 62, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '809610', 'n_tokens_mistral': 2081, 'n_tokens_neox': 1909, 'n_words': 474}