def validate_new_item_info(values): if values['item_name_text_box'] == '' or not values[ 'item_quantity_text_box'].isdigit( ) or not string_tools.extract_size_and_uom( values['item_size_text_box'])['successful']: spin_up_confirm_message( [failed_validation_yes, failed_validation_no], 'Item information invalid!\rWould you like to\rre-enter values?') else: save_new_item()
class Test_when_extracting_size_and_uom_successfully: result = string_tools.extract_size_and_uom('8oz') def test_it_should_return_successful(self): assert self.result['successful'] is True def test_it_should_return_the_size(self): assert self.result['size'] == 8 def test_it_should_return_the_uom(self): assert self.result['uom'] == 'oz'
class Test_when_extracting_size_and_uom_and_size_are_multi_digit: result = string_tools.extract_size_and_uom('854g') def test_it_should_return_successful(self): assert self.result['successful'] is True def test_it_should_return_the_size(self): assert self.result['size'] == 854 def test_it_should_return_the_uom(self): assert self.result['uom'] == 'g'
def save_new_item(): values = editable_text_widget.get_values() new_item = {} new_item['_id'] = barcode_widget.get_value() new_item['name'] = values['item_name_text_box'] new_item['quantity'] = int(values['item_quantity_text_box']) new_item['image'] = found_item_image extract_response = string_tools.extract_size_and_uom( values['item_size_text_box']) if extract_response['successful'] is True: new_item['size'] = extract_response['size'] new_item['uom'] = extract_response['uom'] repo.save(new_item) reset_display()
class Test_when_extracting_size_and_uom_and_there_are_no_chars_after_digits(): result = string_tools.extract_size_and_uom('8') def test_it_should_not_return_successful(self): assert self.result['successful'] is False
class Test_when_extracting_size_and_uom_and_there_are_multiple_separated_digits( ): result = string_tools.extract_size_and_uom('8 6oz') def test_it_should_not_return_successful(self): assert self.result['successful'] is False