示例#1
0
def location_create():
    form = LocationForm()
    if form.validate_on_submit():
        try:
            Location.create(name=form.name.data)
        except (InvalidOperationError, InvalidEmptyValueError,
                DuplicateLocationNameError) as e:
            flash('Error: %s' % e.message, 'danger')
        else:
            flash('location created.', 'success')
    else:
        flash_errors(form)

    return render_template('inventory/location_form.html',
                           version=app_version,
                           form=form,
                           mode='create')
示例#2
0
def location_create():
    form = LocationForm()
    if form.validate_on_submit():
        try:
            Location.create(name=form.name.data)
        except (InvalidOperationError,
                InvalidEmptyValueError,
                DuplicateLocationNameError) as e:
            flash('Error: %s' % e.message, 'danger')
        else:
            flash('location created.', 'success')
    else:
        flash_errors(form)

    return render_template(
            'inventory/location_form.html',
            version=app_version, form=form, mode='create')
示例#3
0
 def test_should_fail_when_create_location_duplicate_name(self, simple_db):
     """location name is unique."""
     with pytest.raises(DuplicateLocationNameError):
         loc = Location.create(name=simple_db['room'][0].name)
示例#4
0
 def test_name_id(self):
     """test name_id is populated."""
     loc = Location.create(name='room A')
     assert loc.name_id == 'room_a'
示例#5
0
 def test_created_at_defaults_to_datetime(self):
     """test creation date."""
     loc = Location.create(name='room A')
     assert bool(loc.created_at)
     assert isinstance(loc.created_at, dt.datetime)
示例#6
0
 def test_get_by_id(self):
     """get location by id."""
     loc = Location.create(name='room A')
     retrieved = Location.get_by_id(loc.id)
     assert retrieved == loc
 def test_should_fail_when_create_location_duplicate_name(self, simple_db):
     """location name is unique."""
     with pytest.raises(DuplicateLocationNameError):
         loc = Location.create(name=simple_db['room'][0].name)
 def test_name_id(self):
     """test name_id is populated."""
     loc = Location.create(name='room A')
     assert loc.name_id == 'room_a'
 def test_created_at_defaults_to_datetime(self):
     """test creation date."""
     loc = Location.create(name='room A')
     assert bool(loc.created_at)
     assert isinstance(loc.created_at, dt.datetime)
示例#10
0
 def test_get_by_id(self):
     """get location by id."""
     loc = Location.create(name='room A')
     retrieved = Location.get_by_id(loc.id)
     assert retrieved == loc