def depts(): ''' Calculates the "mean" of all depts inside the database''' listName = getDictFromPost(request).get('listName') if listName != None and listName != 'undefined': persons = storage.getExpensesPerPerson(listName, current_identity) dispenses = storage.getDispenses(listName, current_identity) if len(persons) > 0: meanDepts = deptCalculator.calcDepts(persons, dispenses) return json.dumps(meanDepts) return json.dumps([]) return Response('Need a list id', 400)
def test_calculator_sanity(): foo, bar, baz, ping, pong = getExpensePersons() # mean of foo and bar is 7.5 expensePersons = [foo, bar] returnList = deptCalculator.calcDepts(expensePersons, Decimal('0')) paybackInstruction = returnList[0] expectedFoo = {'name': 'foo', 'some': 'attr', 'another': 'attr'} expectedBar = {'name': 'bar', 'some': 'attr', 'another': 'attr', 'yet': 'anotherattr'} assert paybackInstruction assert paybackInstruction['borrower'] == expectedBar assert paybackInstruction['sponsor'] == expectedFoo assert paybackInstruction['amount'] == 2.5
def test_calculator_sanity_with_dispenses(): foo, bar, baz, ping, pong = getExpensePersons() # mean of foo(10) and bar(5) with 10€ dispense is (15-10)/2 = 2.5 expensePersons = [foo, bar] returnList = deptCalculator.calcDepts(expensePersons, Decimal('1000')) paybackInstructions = returnList expectedDispense = {'name': 'Spende'} expectedFoo = {'name': 'foo', 'some': 'attr', 'another': 'attr'} expectedBar = {'name': 'bar', 'some': 'attr', 'another': 'attr', 'yet': 'anotherattr'} assert paybackInstructions assert paybackInstructions[0]['borrower'] == expectedDispense assert paybackInstructions[0]['sponsor'] == expectedFoo assert paybackInstructions[0]['amount'] == 7.5 assert paybackInstructions[1]['borrower'] == expectedDispense assert paybackInstructions[1]['sponsor'] == expectedBar assert paybackInstructions[1]['amount'] == 2.5