コード例 #1
0
def query():
    error = None
    db = DbConnect(app.config)
    logger_type_choices = db.getLoggerTypes() 
    db.close()

    form = QueryForm(request.form)
    form.logger_type.choices = logger_type_choices


    if request.method == 'GET':
        form.process()
    else:   
        query = {}
        query["logger_type"] = form.logger_type.data,
        query["country_name"] = form.country_name.data,
        if form.state_name.data is not None:
            query["state_name"] = form.state_name.data, 
        if form.location_name.data is not None:
            query["location_name"] = form.location_name.data,
        if form.zone_name.data is not None:
            query["zone_name"] = form.zone_name.data,
        if form.sub_zone_name.data is not None:
            query["sub_zone_name"] = form.sub_zone_name.data,
        if form.wave_exp_name.data is not None:
            query["wave_exp"] = form.wave_exp_name.data,        
        query["start_date"] = form.date_pick_from.data.strftime('%m/%d/%Y'), 
        query["end_date"] = form.date_pick_to.data.strftime('%m/%d/%Y')
        # print("query: ", query)    
        # print("Query form submitted")

        db = DbConnect(app.config)
        query_results = db.getQueryResults(query) 
        db.close()
        # print("results: ", query_results)
        flash(query_results)
        # if form.validate_on_submit():
        
            # flash("Query details. logger_type: '%s', country_name: '%s', \
            #              state_name: '%s', location_name: '%s', \
            #              Date From: '%s', Date To: '%s' " % \

        # else:
        #     error = 'Invalid Submission. All fields marked with * are compulsory'
    return render_template('query.html', title='Query', form=form, error=error)
コード例 #2
0
class QueryFormTestCase(unittest.TestCase):
    """Query Form Feature specific Test Cases will go here"""
    
    def setUp(self):
        """Setup test app"""
        app.config['TESTING'] = True     
        self.db = DbConnect(app.config)

    def tearDown(self):
        """Close test database"""        
        self.db.close()

    def stringToBytes(self, stringValue):
        """Convert Strings to their Bytes representation"""
        return bytes(stringValue, 'UTF-8')

    def test_form_logger_type_automatic_fill(self):
        """Test the logger_type field is filled automatically on page load"""
        with app.test_client() as client:
            response = client.get('/query')
            logger_type_choices = self.db.getLoggerTypes() 
            for logger_type in logger_type_choices:
                self.assertIn(self.stringToBytes(logger_type[0]), response.data)        
    
    def check_ajax(self, selected_type, selected_value, dbFunction):
        """Helper Function to test the ajax call functionality when
           given selected type field is selected with given value"""
        with app.test_client() as client:
            response = client.get('/_parse_data', 
                                query_string=dict(
                                    select_type=selected_type,
                                    select_value=selected_value))
            self.assertEqual(selected_type, request.args.get('select_type'))
            self.assertEqual(selected_value, request.args.get('select_value'))
            choices = dbFunction(request.args.get('select_value'))
            for choice in choices:
                self.assertIn(self.stringToBytes(choice[0]), response.data)

    def test_form_logger_type_select(self):
        """Test the ajax call functionality if logger_type field is selected"""
        self.check_ajax("logger_type", "robomussel", self.db.getCountry)

    def test_form_country_name_select(self):
        """Test the ajax call functionality if country_name field is selected"""
        self.check_ajax("country_name", "USA", self.db.getState)

    def test_form_state_name_select(self):
        """Test the ajax call functionality if state_name field is selected"""
        self.check_ajax("state_name", "California", self.db.getLocation)

    def test_form_location_name_select(self):
        """Test the ajax call functionality if location_name field is selected"""
        self.check_ajax("lt_for_zone", "robomussel", self.db.getZone)

    def test_form_Zone_name_select(self):
        """Test the ajax call functionality if zone_name field is selected"""
        self.check_ajax("lt_for_subzone", "robomussel", self.db.getSubZone)    

    def test_form_SubZone_name_select(self):
        """Test the ajax call functionality if subZone_name field is selected"""
        self.check_ajax("lt_for_wave_exp", "robomussel", self.db.getWaveExp)    

    def test_query_results(self):
        """Test the query results functionality"""
        with app.test_client() as client:
            response = client.get('/_submit_query', 
                query_string={
                'sub_zone_name': ['High'], 
                'end_date': ['04/12/2016'], 
                'state_name': ['British Columbia'], 
                'wave_exp': ['exposed'], 
                'location_name': ['Seppings Island'], 
                'zone_name': ['High'], 
                'logger_type': ['robomussel'], 
                'start_date': ['03/01/2016'], 
                'country_name': ['Canada']},
                    follow_redirects=True)
            self.assertIn(b"13.98", response.data)
            self.assertIn(b"12.87", response.data)
コード例 #3
0
ファイル: tests_query.py プロジェクト: sharma-abhi/SavingNemo
class QueryFormTestCase(unittest.TestCase):
    """Query Form Feature specific Test Cases will go here"""
    
    def setUp(self):
        """Setup test app"""
        app.config['TESTING'] = True     
        self.db = DbConnect(app.config)

    def tearDown(self):
        """Close test database"""        
        self.db.close()

    def stringToBytes(self, stringValue):
        """Convert Strings to their Bytes representation"""
        return bytes(stringValue, 'UTF-8')

    def test_form_logger_type_automatic_fill(self):
        """Test the logger_type field is filled automatically on page load"""
        with app.test_client() as client:
            response = client.get('/query')
            logger_type_choices = self.db.getLoggerTypes() 
            for logger_type in logger_type_choices:
                self.assertIn(self.stringToBytes(logger_type[0]), response.data)        
    
    def check_ajax(self, selected_type, selected_value, dbFunction):
        """Helper Function to test the ajax call functionality when
           given selected type field is selected with given value"""
        with app.test_client() as client:
            response = client.get('/_parse_data', 
                                query_string=dict(
                                    select_type=selected_type,
                                    select_value=selected_value))
            self.assertEqual(selected_type, request.args.get('select_type'))
            self.assertEqual(selected_value, request.args.get('select_value'))
            choices = dbFunction(request.args.get('select_value'))
            for choice in choices:
                self.assertIn(self.stringToBytes(choice[0]), response.data)

    def test_form_logger_type_select(self):
        """Test the ajax call functionality if logger_type field is selected"""
        self.check_ajax("logger_type", "robomussel", self.db.getCountry)

    def test_form_country_name_select(self):
        """Test the ajax call functionality if country_name field is selected"""
        self.check_ajax("country_name", "USA", self.db.getState)

    def test_form_state_name_select(self):
        """Test the ajax call functionality if state_name field is selected"""
        self.check_ajax("state_name", "California", self.db.getLocation)

    def test_form_location_name_select(self):
        """Test the ajax call functionality if location_name field is selected"""
        self.check_ajax("lt_for_zone", "robomussel", self.db.getZone)

    def test_form_Zone_name_select(self):
        """Test the ajax call functionality if zone_name field is selected"""
        self.check_ajax("lt_for_subzone", "robomussel", self.db.getSubZone)    

    def test_form_SubZone_name_select(self):
        """Test the ajax call functionality if subZone_name field is selected"""
        self.check_ajax("lt_for_wave_exp", "robomussel", self.db.getWaveExp)    

    def test_query_results(self):
        """Test the query results functionality"""
        with app.test_client() as client:
            response = client.post('/query', 
                data=dict(
                    logger_type="robomussel",
                    country_name="Canada",
                    state_name="British Columbia",
                    location_name="Seppings Island",
                    zone_name="High",
                    sub_zone_name="High",
                    wave_exp_name="exposed",
                    date_pick_from=datetime.date(1995, 4, 15).strftime('%m/%d/%Y'),
                    date_pick_to=datetime.date(2016, 4, 30).strftime('%m/%d/%Y')),
                    follow_redirects=True)
            self.assertIn(b"[('robomussel', 13.98), ('robomussel', 12.87)]", response.data)
コード例 #4
0
class QueryFormTestCase(unittest.TestCase):
    """Query Form Feature specific Test Cases will go here"""
    def setUp(self):
        """Setup test app"""
        app.config['TESTING'] = True
        self.db = DbConnect(app.config)

    def tearDown(self):
        """Close test database"""
        self.db.close()

    def stringToBytes(self, stringValue):
        """Convert Strings to their Bytes representation"""
        return bytes(stringValue, 'UTF-8')

    def test_form_logger_type_automatic_fill(self):
        """Test the logger_type field is filled automatically on page load"""
        with app.test_client() as client:
            response = client.get('/query')
            logger_type_choices = self.db.getLoggerTypes()
            for logger_type in logger_type_choices:
                self.assertIn(self.stringToBytes(logger_type[0]),
                              response.data)

    def check_ajax(self, selected_type, selected_value, dbFunction):
        """Helper Function to test the ajax call functionality when
           given selected type field is selected with given value"""
        with app.test_client() as client:
            response = client.get('/_parse_data',
                                  query_string=dict(
                                      select_type=selected_type,
                                      select_value=selected_value))
            self.assertEqual(selected_type, request.args.get('select_type'))
            self.assertEqual(selected_value, request.args.get('select_value'))
            choices = dbFunction(request.args.get('select_value'))
            for choice in choices:
                self.assertIn(self.stringToBytes(choice[0]), response.data)

    def test_form_logger_type_select(self):
        """Test the ajax call functionality if logger_type field is selected"""
        self.check_ajax("logger_type", "robomussel", self.db.getCountry)

    def test_form_country_name_select(self):
        """Test the ajax call functionality if country_name field is selected"""
        self.check_ajax("country_name", "USA", self.db.getState)

    def test_form_state_name_select(self):
        """Test the ajax call functionality if state_name field is selected"""
        self.check_ajax("state_name", "California", self.db.getLocation)

    def test_form_location_name_select(self):
        """Test the ajax call functionality if location_name field is selected"""
        self.check_ajax("lt_for_zone", "robomussel", self.db.getZone)

    def test_form_Zone_name_select(self):
        """Test the ajax call functionality if zone_name field is selected"""
        self.check_ajax("lt_for_subzone", "robomussel", self.db.getSubZone)

    def test_form_SubZone_name_select(self):
        """Test the ajax call functionality if subZone_name field is selected"""
        self.check_ajax("lt_for_wave_exp", "robomussel", self.db.getWaveExp)

    def test_query_results(self):
        """Test the query results functionality"""
        with app.test_client() as client:
            response = client.post('/query',
                                   data=dict(logger_type="robomussel",
                                             country_name="Canada",
                                             state_name="British Columbia",
                                             location_name="Seppings Island",
                                             zone_name="High",
                                             sub_zone_name="High",
                                             wave_exp_name="exposed",
                                             date_pick_from=datetime.date(
                                                 1995, 4,
                                                 15).strftime('%m/%d/%Y'),
                                             date_pick_to=datetime.date(
                                                 2016, 4,
                                                 30).strftime('%m/%d/%Y')),
                                   follow_redirects=True)
            self.assertIn(
                b"[('robomussel', 13.98), ('robomussel', 12.87)]",
                response.data)