def test_json_input(self): payload = [123, 34, 56, 78] json_payload = json.dumps(payload) self.assertEqual( payload, utils.parse_sizes_str(json_payload) )
def ipcalc(): network = request.args.get('network') sizes_str = request.args.get('size') latest = collections.deque(session.get('latest', []), maxlen=5) sizes = utils.parse_sizes_str(sizes_str) if sizes_str else [] if not network or not sizes: flash('Enter your network and list of networks', 'info') return render_template("index.html", latest=latest) if not latest: latest = collections.deque(maxlen=5) latest.append({ 'time': datetime.now(), 'path': request.full_path, 'network': network, 'sizes': sizes }) session['latest'] = list(latest) try: if len(sizes) >= 20: sizes = sizes[:20] raise Exception("Your browser probably cannot handle this") context = get_context(network, sizes) return render_template('index.html', context=context, latest=latest, calculated=True) except Exception as e: flash(str(e), 'error') return render_template("index.html", context={ 'network': network, 'sizes': sizes }, latest=latest)
def test_single_json_input(self): payload = [123] payload_as_str = '[123]' self.assertEqual(payload, utils.parse_sizes_str(payload_as_str))
def test_single_with_space_input(self): payload = [123] payload_as_str = '123 ' self.assertEqual(payload, utils.parse_sizes_str(payload_as_str))
def test_really_idiotic_way_to_separate_input(self): payload = [123, 34, 56, 78] idiot_payload = '123, 34 56;78' self.assertEqual(payload, utils.parse_sizes_str(idiot_payload))
def test_comma_separated_input(self): payload = [123, 34, 56, 78] space_payload = ','.join(map(str, payload)) self.assertEqual(payload, utils.parse_sizes_str(space_payload))
def test_multiple_consequence_separators(self): payload = [123, 34, 45] payload_as_str = '123,,,;34; 45; ' self.assertEqual(payload, utils.parse_sizes_str(payload_as_str))
def test_null_separator_input(self): self.assertEqual([], utils.parse_sizes_str(',;;;,, ;, ;, ;,; ;'))
def test_null_json_input(self): self.assertEqual([], utils.parse_sizes_str('[]'))