<commit_before>import unittest
import os
import string
import random
import datetime
import json
import logging

from nose.tools import eq_, ok_

log = logging.getLogger(__name__)
from flask_appbuilder import SQLA
from .sqla.models import Model1, insert_data

MODEL1_DATA_SIZE = 10

class FlaskTestCase(unittest.TestCase):
    def setUp(self):
        from flask import Flask
        from flask_appbuilder import AppBuilder
        from flask_appbuilder.models.sqla.interface import SQLAInterface
        from flask_appbuilder.api import ModelApi

        self.app = Flask(__name__)
        self.basedir = os.path.abspath(os.path.dirname(__file__))
        self.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'
        self.app.config['CSRF_ENABLED'] = False
        self.app.config['SECRET_KEY'] = 'thisismyscretkey'
        self.app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

        self.db = SQLA(self.app)
        self.appbuilder = AppBuilder(self.app, self.db.session)

        # Create models and insert data
        insert_data(self.db.session, Model1, MODEL1_DATA_SIZE)

        class Model1Api(ModelApi):
            datamodel = SQLAInterface(Model1)
            list_columns = ['field_integer', 'field_float', 'field_string', 'field_date']
            description_columns = {
                'field_integer': 'Field Integer',
                'field_float': 'Field Float',
                'field_string': 'Field String'
            }

        self.model1api = Model1Api
        self.appbuilder.add_view_no_menu(Model1Api)


    def tearDown(self):
        self.appbuilder = None
        self.app = None
        self.db = None

    def test_get_item(self):
        """
            REST Api: Test get item
        """
        #insert_data(self.db.session, Model1)
        client = self.app.test_client()

        # Check for Welcome Message
        for i in range(1, MODEL1_DATA_SIZE):
            rv = client.get('api/v1/model1api/{}/'.format(i))
            data = json.loads(rv.data.decode('utf-8'))
            return self.assert_get_item(rv, data, i-1)

    def assert_get_item(self, rv, data, value):
        # test result
        log.info("get_item:{} {}".format(data, value))
        eq_(data['result'], {'field_date':None,
                             'field_float':float(value),
                             'field_integer':value,
                             'field_string':"test{}".format(value)})
        # test descriptions
        eq_(data['description_columns'], self.model1api.description_columns)
        eq_(data['label_columns'], {'field_date':'Field Date',
                                    'field_float':'Field Float',
                                    'field_integer':'Field Integer',
                                    'field_string':'Field String',
                                    'id':'Id'})
        eq_(rv.status_code, 200)

    def test_get_list(self):
        """
            REST Api: Test get list
        """
        #insert_data(self.db.session, Model1)
        client = self.app.test_client()

        # Check for Welcome Message
        rv = client.get('api/v1/model1api/')
        data = json.loads(rv.data.decode('utf-8'))
        for i in range(1, MODEL1_DATA_SIZE):
            return self.assert_get_list(rv, data['result'][i-1], i-1)

    def assert_get_list(self, rv, data, value):
        # test result

        log.error("get list:{} {}".format(data, value))
        eq_(data, {'field_date':None,
                             'field_float':float(value),
                             'field_integer':value,
                             'field_string':"test{}".format(value)})
        eq_(rv.status_code, 200)<commit_msg>[tests] Fix, item loop tests are not being called<commit_after>import unittest
import os
import string
import random
import datetime
import json
import logging

from nose.tools import eq_, ok_

log = logging.getLogger(__name__)
from flask_appbuilder import SQLA
from .sqla.models import Model1, insert_data

MODEL1_DATA_SIZE = 10

class FlaskTestCase(unittest.TestCase):

    def setUp(self):
        from flask import Flask
        from flask_appbuilder import AppBuilder
        from flask_appbuilder.models.sqla.interface import SQLAInterface
        from flask_appbuilder.api import ModelApi

        self.app = Flask(__name__)
        self.basedir = os.path.abspath(os.path.dirname(__file__))
        self.app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'
        self.app.config['CSRF_ENABLED'] = False
        self.app.config['SECRET_KEY'] = 'thisismyscretkey'
        self.app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

        self.db = SQLA(self.app)
        self.appbuilder = AppBuilder(self.app, self.db.session)

        # Create models and insert data
        insert_data(self.db.session, Model1, MODEL1_DATA_SIZE)

        class Model1Api(ModelApi):
            datamodel = SQLAInterface(Model1)
            list_columns = ['field_integer', 'field_float', 'field_string', 'field_date']
            description_columns = {
                'field_integer': 'Field Integer',
                'field_float': 'Field Float',
                'field_string': 'Field String'
            }

        self.model1api = Model1Api
        self.appbuilder.add_view_no_menu(Model1Api)


    def tearDown(self):
        self.appbuilder = None
        self.app = None
        self.db = None

    def test_get_item(self):
        """
            REST Api: Test get item
        """
        client = self.app.test_client()

        for i in range(1, MODEL1_DATA_SIZE):
            rv = client.get('api/v1/model1api/{}/'.format(i))
            data = json.loads(rv.data.decode('utf-8'))
            self.assert_get_item(rv, data, i-1)

    def assert_get_item(self, rv, data, value):
        log.info("assert_get_item: {} {}".format(data, value))
        # test result
        eq_(data['result'], {'field_date':None,
                             'field_float':float(value),
                             'field_integer':value,
                             'field_string':"test{}".format(value)})
        # test descriptions
        eq_(data['description_columns'], self.model1api.description_columns)
        # test labels
        eq_(data['label_columns'], {'field_date':'Field Date',
                                    'field_float':'Field Float',
                                    'field_integer':'Field Integer',
                                    'field_string':'Field String',
                                    'id':'Id'})
        eq_(rv.status_code, 200)

    def test_get_list(self):
        """
            REST Api: Test get list
        """
        client = self.app.test_client()

        rv = client.get('api/v1/model1api/')
        data = json.loads(rv.data.decode('utf-8'))
        for i in range(1, MODEL1_DATA_SIZE):
            self.assert_get_list(rv, data['result'][i-1], i-1)

    def assert_get_list(self, rv, data, value):
        log.info("assert_get_list: {} {}".format(data, value))
        # test result
        eq_(data, {'field_date':None,
                             'field_float':float(value),
                             'field_integer':value,
                             'field_string':"test{}".format(value)})
        eq_(rv.status_code, 200)


{'fraction_non_alphanumeric': 0.11567523011402665, 'fraction_numerical': 0.008792416540733617, 'mean_word_length': 2.0320699708454812, 'pattern_counts': {'":': 0, '<': 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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6325216', 'n_tokens_mistral': 2190, 'n_tokens_neox': 2108, 'n_words': 418}