def test_update(self, testapp_login_disabled, simple_db):
        """update happy path."""
        loc = Location.get_by_id(simple_db['room'][2].id)
        assert loc.name == simple_db['room'][2].name

        l = dict(name='special_new_name')
        url = '/api/inventory/locations/%i' % simple_db['room'][2].id
        res = testapp_login_disabled.put_json(url, params=l)

        loc = Location.get_by_id(simple_db['room'][2].id)
        assert loc.name == 'special_new_name'
示例#2
0
    def test_update(self, testapp_login_disabled, simple_db):
        """update happy path."""
        loc = Location.get_by_id(simple_db['room'][2].id)
        assert loc.name == simple_db['room'][2].name

        l = dict(name='special_new_name')
        url = '/api/inventory/locations/%i' % simple_db['room'][2].id
        res = testapp_login_disabled.put_json(url, params=l)

        loc = Location.get_by_id(simple_db['room'][2].id)
        assert loc.name == 'special_new_name'
示例#3
0
def role_create():
    form = RoleForm()
    form.ca_id.choices = get_select_list_for_cas()
    form.location_id.choices = get_select_list_for_locations()
    form.cluster_id.choices = get_select_list_for_clusters()
    if form.validate_on_submit():
        ca = Ca.get_by_id(form.ca_id.data)
        loc = Location.get_by_id(form.location_id.data)
        cluster = MhCluster.get_by_id(form.cluster_id.data)
        try:
            Role.create(name=form.role_name.data,
                        ca=ca,
                        location=loc,
                        cluster=cluster)
        except (InvalidCaRoleError, AssociationError) as e:
            flash('Error: %s' % e.message, 'danger')
        else:
            flash('role created.', 'success')
    else:
        flash_errors(form)

    return render_template('inventory/role_form.html',
                           version=app_version,
                           form=form,
                           mode='create')
示例#4
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')
示例#5
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')
示例#6
0
 def test_delete_room(self, simple_db):
     """delete room and undo associations."""
     assert len(simple_db['room'][0].get_ca_by_role('experimental')) == 2
     assert len(simple_db['room'][0].get_ca()) == 3
     room_id = simple_db['room'][0].id
     simple_db['room'][0].delete()
     assert not bool(Location.get_by_id(room_id))
     assert simple_db['ca'][0].role_name == None
     assert simple_db['ca'][1].role_name == None
     assert simple_db['ca'][2].role_name == None
     assert len(simple_db['cluster'][0].get_ca()) == 0
 def test_delete_room(self, simple_db):
     """delete room and undo associations."""
     assert len(simple_db['room'][0].get_ca_by_role('experimental')) == 2
     assert len(simple_db['room'][0].get_ca()) == 3
     room_id = simple_db['room'][0].id
     simple_db['room'][0].delete()
     assert not bool(Location.get_by_id(room_id))
     assert simple_db['ca'][0].role_name == None
     assert simple_db['ca'][1].role_name == None
     assert simple_db['ca'][2].role_name == None
     assert len(simple_db['cluster'][0].get_ca()) == 0
示例#8
0
    def test_create_location(self, testapp_login_disabled, simple_db):
        """create new location - happy path."""
        l = dict(name='fake-ROOM')
        res = testapp_login_disabled.post_json('/api/inventory/locations', l)
        assert res.status_int == 201

        l_list = Location.query.all()
        assert len(l_list) == 6

        json_data = json.loads(res.body)
        assert bool(json_data['id'])

        loc = Location.get_by_id(json_data['id'])
        assert loc.name == l['name']
    def test_create_location(self, testapp_login_disabled, simple_db):
        """create new location - happy path."""
        l = dict(name='fake-ROOM')
        res = testapp_login_disabled.post_json('/api/inventory/locations', l)
        assert res.status_int == 201

        l_list = Location.query.all()
        assert len(l_list) == 6

        json_data = json.loads(res.body)
        assert bool(json_data['id'])

        loc = Location.get_by_id(json_data['id'])
        assert loc.name == l['name']
示例#10
0
def location_edit(r_id):
    loc = Location.get_by_id(r_id)
    if not loc:
        return render_template('404.html')

    form = LocationForm(obj=loc)
    if form.validate_on_submit():
        try:
            loc.update(name=form.name.data)
        except (InvalidOperationError,
                InvalidEmptyValueError,
                DuplicateLocationNameError) as e:
            flash('Error: %s' % e.message, 'danger')
        else:
            flash('location updated.', 'success')
    else:
        flash_errors(form)

    return render_template(
            'inventory/location_form.html',
            version=app_version, form=form, mode='edit', r_id=loc.id)
示例#11
0
def location_edit(r_id):
    loc = Location.get_by_id(r_id)
    if not loc:
        return render_template('404.html')

    form = LocationForm(obj=loc)
    if form.validate_on_submit():
        try:
            loc.update(name=form.name.data)
        except (InvalidOperationError, InvalidEmptyValueError,
                DuplicateLocationNameError) as e:
            flash('Error: %s' % e.message, 'danger')
        else:
            flash('location updated.', 'success')
    else:
        flash_errors(form)

    return render_template('inventory/location_form.html',
                           version=app_version,
                           form=form,
                           mode='edit',
                           r_id=loc.id)
示例#12
0
def role_create():
    form = RoleForm()
    form.ca_id.choices = get_select_list_for_cas()
    form.location_id.choices = get_select_list_for_locations()
    form.cluster_id.choices = get_select_list_for_clusters()
    if form.validate_on_submit():
        ca = Ca.get_by_id(form.ca_id.data)
        loc = Location.get_by_id(form.location_id.data)
        cluster = MhCluster.get_by_id(form.cluster_id.data)
        try:
            Role.create(
                    name=form.role_name.data,
                    ca=ca, location=loc, cluster=cluster)
        except (InvalidCaRoleError,
                AssociationError) as e:
            flash('Error: %s' % e.message, 'danger')
        else:
            flash('role created.', 'success')
    else:
        flash_errors(form)

    return render_template(
            'inventory/role_form.html',
            version=app_version, form=form, mode='create')
示例#13
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)
示例#14
0
 def test_name_id(self):
     """test name_id is populated."""
     loc = Location.create(name='room A')
     assert loc.name_id == 'room_a'
示例#15
0
 def test_should_fail_when_update_not_updateable_field(self, simple_db):
     """capture_agents is not updateable."""
     l = Location.get_by_id(simple_db['room'][0].id)
     with pytest.raises(InvalidOperationError):
         l.update(capture_agents=[simple_db['ca'][3]])
示例#16
0
 def test_should_fail_when_update_location_duplicate_name(self, simple_db):
     """name is unique."""
     l = Location.get_by_id(simple_db['room'][0].id)
     with pytest.raises(DuplicateLocationNameError):
         l.update(name=simple_db['room'][1].name)
示例#17
0
 def test_update(self, simple_db):
     """update happy path."""
     l = Location.get_by_id(simple_db['room'][0].id)
     l.update(name='new_name_for_room')
     l2 = Location.get_by_id(simple_db['room'][0].id)
     assert l2.name == 'new_name_for_room'
示例#18
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)
示例#19
0
 def test_should_fail_when_update_location_duplicate_name(self, simple_db):
     """name is unique."""
     l = Location.get_by_id(simple_db['room'][0].id)
     with pytest.raises(DuplicateLocationNameError):
         l.update(name=simple_db['room'][1].name)
示例#20
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)
示例#21
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
示例#22
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)
示例#23
0
 def test_should_fail_when_update_not_updateable_field(self, simple_db):
     """capture_agents is not updateable."""
     l = Location.get_by_id(simple_db['room'][0].id)
     with pytest.raises(InvalidOperationError):
         l.update(capture_agents=[simple_db['ca'][3]])
示例#24
0
 def test_name_id(self):
     """test name_id is populated."""
     loc = Location.create(name='room A')
     assert loc.name_id == 'room_a'
示例#25
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
示例#26
0
 def test_update(self, simple_db):
     """update happy path."""
     l = Location.get_by_id(simple_db['room'][0].id)
     l.update(name='new_name_for_room')
     l2 = Location.get_by_id(simple_db['room'][0].id)
     assert l2.name == 'new_name_for_room'