コード例 #1
0
ファイル: routes.py プロジェクト: patrickshobe/AddressBook
def lookup():
    """ Lookup Route """
    form = ZipForm()
    if form.validate_on_submit():
        zip_service = ZipService()
        response = zip_service.perform_lookup(form.zip.data)
        return render_template('lookup.html', form=form, result=response)
    return render_template('lookup.html', result=None, form=form)
コード例 #2
0
    def test_validator_can_lookup(self):
        zip = '80205'
        lookup = ZipService()
        result = lookup.perform_lookup(zip)

        self.assertEqual(result['Zip5'], zip)
        self.assertEqual(result['City'], 'Denver')
        self.assertEqual(result['State'], 'CO')
コード例 #3
0
    def test_address_validator_fails_state(self):
        """ Test that the validator will fail a wrong state"""
        data = {
            'name': 'Casa Bonita',
            'address': '6715 West Colfax Ave',
            'zip': '80214',
            'city': 'Denver',
            'state': 'Utah'
        }
        validator = ZipService()
        validator.validate_address(data)

        result = Address.query.get(1)

        self.assertEqual(result.error, 'Incorrect State: Did you mean CO?')
コード例 #4
0
    def test_address_validator_fails_city(self):
        """ Test that the validator will fail a wrong city"""
        data = {
            'name': 'Casa Bonita',
            'address': '6715 West Colfax Ave',
            'zip': '80214',
            'city': 'Salt Lake City',
            'state': 'CO'
        }
        validator = ZipService()
        validator.validate_address(data)

        result = Address.query.get(1)

        self.assertEqual(result.error, 'Incorrect City: Did you mean Denver?')
コード例 #5
0
    def test_address_validator_passes(self):
        """ Test that a correct address passes the validator"""
        data = {
            'name': 'Casa Bonita',
            'address': '6715 West Colfax Ave',
            'zip': '80214',
            'city': 'Denver',
            'state': 'CO'
        }
        validator = ZipService()
        validator.validate_address(data)

        result = Address.query.get(1)

        self.assertEqual(result.error, None)
コード例 #6
0
ファイル: routes.py プロジェクト: patrickshobe/AddressBook
def create():
    """ Address New """
    form = AddressForm()
    if form.validate_on_submit():
        form_data = {
            'name': form.name.data,
            'address': form.address.data,
            'zip': form.zip.data,
            'city': form.city.data,
            'state': form.state.data
        }
        validator = ZipService()
        validator.validate_address(form_data)
        flash('{} Created Successfully'.format(form.name.data))
        return redirect('/')
    return render_template('create.html', form=form)