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 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_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 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_create(): """capture agent create form.""" form = CaForm() form.vendor_id.choices = get_select_list_for_vendors() if form.validate_on_submit(): try: Ca.create(name=form.name.data, address=form.address.data, serial_number=form.serial_number.data, vendor_id=form.vendor_id.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='create')
def ca_create(): """capture agent create form.""" form = CaForm() form.vendor_id.choices = get_select_list_for_vendors() if form.validate_on_submit(): try: Ca.create( name=form.name.data, address=form.address.data, serial_number=form.serial_number.data, vendor_id=form.vendor_id.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='create')
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_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_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_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_'