Example #1
0
 def testTest0002(self):
     """It turned out that binary comission was not paid for user when a binary matrix got full.
        in testHandleFullMatrixOfUser. In this test, we go to the failure point and execute the test
        function line-by-line."""
     parentUserId = User.objects.create(username="******", sponsor=MasterUser.Get()).id
     Controller().createNewBinaryPosition(parentUserId)
     numberOfUsers = BinaryTree()._getNumberOfNodesToReturn() - 2
     self._createBinaryPositions(numberOfUsers, parentUserId)
     lastUserId = User.objects.create(username="******", sponsor=User.Get(parentUserId)).id
     # This was the failed line:
     # Controller().createNewBinaryPosition(lastUserId)
     self.assertTrue(User.Get(lastUserId).addNewActiveBinaryPosition())
     # Check situation before payment
     self.assertEqual(- Controller().price, User.Get(parentUserId).binary_money)
     Controller().payBinaryPrice(lastUserId)
     self.assertEqual(- Controller().price, User.Get(parentUserId).binary_money)
     # This line did noy pay commision for parent user. Extend it, check line-by-line
     # Controller()._handleFullMatrix(User.Get(lastUserId).active_binary_position)
     position = User.Get(lastUserId).active_binary_position
     top = BinaryTree().getMatrixTop(position)
     self.assertTrue(not top.owner.isMaster())
     if not top.owner.isMaster():
         Controller().payBinaryCommission(top.owner.id)
     # OK, this was the error. payBinaryCommission was called, saved the new money state,
     # but this line re-saved the old state.
     # top.owner.save()
     self.assertEqual(- Controller().price + Controller().commission, User.Get(parentUserId).binary_money)
Example #2
0
 def testHandleFullMatrixOfUser(self):
     activeId = MasterUser.Get().active_binary_position.id
     self.assertTrue(MasterUser.Get().active_binary_position)
     self.assertEqual(MasterUser.Get().id, 1)
     parentUserId = User.objects.create(username="******", sponsor=MasterUser.Get()).id
     Controller().createNewBinaryPosition(parentUserId)
     self.assertTrue(User.Get(parentUserId).active_binary_position)
     numberOfUsers = BinaryTree()._getNumberOfNodesToReturn() - 2
     self._createBinaryPositions(numberOfUsers, parentUserId)
     self.assertEqual(- Controller().price, User.Get(parentUserId).binary_money)
     lastUserId = User.objects.create(username="******", sponsor=User.Get(parentUserId)).id
     self.assertEqual(activeId, MasterUser.Get().active_binary_position.id)
     self.assertEqual(User.Get(lastUserId).sponsor.id, parentUserId)
     Controller().createNewBinaryPosition(lastUserId)
     self.assertEqual(User.Get(lastUserId).sponsor.id, parentUserId)
     self.assertEqual(activeId, MasterUser.Get().active_binary_position.id)
     self.assertEqual((numberOfUsers + 2) * Controller().price - Controller().commission, MasterUser.Get().binary_money)
     # With this move, the parent's matrix got full. Sponsor should get commission, no new fee
     # should be paid after the repositioning.
     # This line has been failed. Test0002 was used for debugging.
     self.assertEqual(- Controller().price + Controller().commission, User.Get(parentUserId).binary_money)
     # Check if the new position for the master has been created.
     # It must be the rightmost node at one level below the full matrix.
     self.assertEqual(User.Get(parentUserId).active_binary_position.parent.owner.id, MasterUser.Get().id)
     self.assertTrue(MasterUser.Get().active_binary_position.right)
     self.assertEqual(MasterUser.Get().active_binary_position.right.id, User.Get(parentUserId).active_binary_position.id)
Example #3
0
 def testHandleFullMatrixOfMaster(self):
     numberOfUsers = BinaryTree()._getNumberOfNodesToReturn() - 2
     self._createBinaryPositions(numberOfUsers, MasterUser.Get().id)
     self.assertEqual(numberOfUsers * Controller().price, MasterUser.Get().binary_money)
     user = User.objects.create(username="******", sponsor=MasterUser.Get())
     Controller().createNewBinaryPosition(user.id)
     # With this move, the master's matrix got full. Master should not get commission,
     # only the fees.
     self.assertEqual((numberOfUsers + 1) * Controller().price, MasterUser.Get().binary_money)
     # Check if the new position for the master has been created.
     # It must be a completely new matrix.
     self.assertEqual(MasterUser.Get().active_binary_position.parent, None)