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)
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')
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?')
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?')
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)
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)