def test_get_by_id(self, simple_db): """get ca by id.""" ca = Ca.create(name='fake-epiphan', vendor_id=simple_db['vendor'].id, address='fake-epiphan.blah.bloh.net') retrieved = Ca.get_by_id(ca.id) assert retrieved == ca
def ca_edit(r_id): """capture agent edit form.""" ca = Ca.get_by_id(r_id) if not ca: return render_template('404.html') form = CaForm(obj=ca) form.vendor_id.choices = get_select_list_for_vendors() if form.validate_on_submit(): try: ca.update( name=form.name.data, address=form.address.data, serial_number=form.serial_number.data) except (InvalidEmptyValueError, MissingVendorError, DuplicateCaptureAgentNameError, DuplicateCaptureAgentAddressError, DuplicateCaptureAgentSerialNumberError) as e: flash('Error: %s' % e.message, 'danger') else: flash('capture agent created.', 'success') else: flash_errors(form) return render_template( 'inventory/capture_agent_form.html', version=app_version, form=form, mode='edit', r_id=ca.id)
def test_created_at_defaults_to_datetime(self, simple_db): """test creation date.""" ca = Ca.create(name='fake-epiphan', vendor_id=simple_db['vendor'].id, address='fake-epiphan.blah.bloh.net') assert bool(ca.created_at) assert isinstance(ca.created_at, dt.datetime)
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')
def test_should_fail_when_create_ca_duplicate_serial_number(self, simple_db): """ca serial_number is unique.""" with pytest.raises(DuplicateCaptureAgentSerialNumberError): ca = Ca.create(name='fake-epiphan', vendor_id=simple_db['vendor'].id, address='fake-epiphan.blah.bloh.net', serial_number=simple_db['ca'][0].serial_number)
def ca_edit(r_id): """capture agent edit form.""" ca = Ca.get_by_id(r_id) if not ca: return render_template('404.html') form = CaForm(obj=ca) form.vendor_id.choices = get_select_list_for_vendors() if form.validate_on_submit(): try: ca.update(name=form.name.data, address=form.address.data, serial_number=form.serial_number.data) except (InvalidEmptyValueError, MissingVendorError, DuplicateCaptureAgentNameError, DuplicateCaptureAgentAddressError, DuplicateCaptureAgentSerialNumberError) as e: flash('Error: %s' % e.message, 'danger') else: flash('capture agent created.', 'success') else: flash_errors(form) return render_template('inventory/capture_agent_form.html', version=app_version, form=form, mode='edit', r_id=ca.id)
def test_update_name_ca( self, testapp_login_disabled, simple_db): ca = dict(name='fake-name') res = testapp_login_disabled.put_json( '/api/inventory/cas/%i' % simple_db['ca'][1].id, params=ca) assert res.status_int == 200 ca_updated = Ca.get_by_id(simple_db['ca'][1].id) assert ca_updated.name == ca['name']
def test_update_name_ca(self, testapp_login_disabled, simple_db): ca = dict(name='fake-name') res = testapp_login_disabled.put_json('/api/inventory/cas/%i' % simple_db['ca'][1].id, params=ca) assert res.status_int == 200 ca_updated = Ca.get_by_id(simple_db['ca'][1].id) assert ca_updated.name == ca['name']
def test_should_fail_when_create_ca_duplicate_serial_number( self, simple_db): """ca serial_number is unique.""" with pytest.raises(DuplicateCaptureAgentSerialNumberError): ca = Ca.create(name='fake-epiphan', vendor_id=simple_db['vendor'].id, address='fake-epiphan.blah.bloh.net', serial_number=simple_db['ca'][0].serial_number)
def test_should_fail_when_update_empty_ca_address(self, simple_db): """ca address is mandatory.""" ca = Ca.get_by_id(simple_db['ca'][2].id) ca.update(serial_number='') assert ca.serial_number == '' with pytest.raises(InvalidEmptyValueError) as e: ca.update(address='') assert 'not allowed empty value for `address`' in str(e.value)
def test_update_ca_name(self, simple_db): """test update ca - happy path.""" ca = Ca.get_by_id(simple_db['ca'][0].id) ca.update(name='new-name') assert ca.name == 'new-name' ca.update(name='blah', address='blah.some.domain', serial_number='xxx') assert ca.name == 'blah' assert ca.address == 'blah.some.domain' assert ca.serial_number == 'xxx'
def test_create_ca(self, testapp_login_disabled, simple_db): """create new capture agent - happy path.""" new_ca = dict(name='fake-ca', address='fake-ca.some.url', vendor_id=simple_db['vendor'].id, serial_number='ABC123') res = testapp_login_disabled.post_json('/api/inventory/cas', new_ca) assert res.status_int == 201 ca_list = Ca.query.all() assert len(ca_list) == 6 json_ca = json.loads(res.body) assert bool(json_ca['id']) ca = Ca.get_by_id(json_ca['id']) assert ca.name == new_ca['name'] assert ca.serial_number == new_ca['serial_number'] assert ca.vendor_id == new_ca['vendor_id']
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')
def test_delete_ca(self, simple_db): ca_id = simple_db['ca'][0].id simple_db['ca'][0].delete() assert Ca.get_by_id(ca_id) is None
def test_should_fail_when_create_ca_duplicate_address(self, simple_db): """ca address is unique.""" with pytest.raises(DuplicateCaptureAgentAddressError): ca = Ca.create(name='fake-epiphan', vendor_id=simple_db['vendor'].id, address=simple_db['ca'][0].address)
def test_should_fail_when_create_ca_missing_vendor(self, simple_db): """vendor is mandatory for every capture agent.""" with pytest.raises(MissingVendorError): ca = Ca.create(name='fake-epiphan', vendor_id=999999, address='fake-epiphan.blah.bloh.net')
def test_should_fail_when_create_ca_duplicate_name(self, simple_db): """ca name is unique.""" with pytest.raises(DuplicateCaptureAgentNameError): ca = Ca.create(name=simple_db['ca'][0].name, vendor_id=simple_db['vendor'].id, address='fake-epiphan.blah.bloh.net')
def test_name_id(self, simple_db): """test name_id is populated.""" ca = Ca.create(name='fake-epiphan[A]', vendor_id=simple_db['vendor'].id, address='fake-epiphan.blah.bloh.net') assert ca.name_id == 'fake_epiphan_a_'
def test_should_fail_when_update_not_updateable_ca_field(self, simple_db): """vendor_id is not allowed to be updated.""" ca = Ca.get_by_id(simple_db['ca'][1].id) with pytest.raises(InvalidOperationError) as e: ca.update(vendor_id=simple_db['vendor'].id) assert 'not allowed to update ca fields: vendor_id' in str(e.value)