def stats(request): if request.method == "POST": form = SearchForm(request.POST) if form.is_valid(): url = form.cleaned_data["url"] input = getWords(getDocument(url)) output = wordstats.stats(input) jsonstats = json.dumps(output.wordcount, indent=4) return render_to_response( "graph.html", {"shortest": output.shortest, "longest": output.longest, "wordcount": jsonstats} ) else: form = SearchForm() return render_to_response("index.html", {"form": form})
import wordstats input = "this is a test to see how well this search thing works. a word like test which is used multiple times in a test should test if the number of times test shows worked." output = wordstats.stats(input) #print output.wordcount assert len(output.wordcount) == 10 #print output.shortest assert output.shortest == "is" #print output.longest assert output.longest == "multiple"