Пример #1
0
 def testPayBinaryPrice(self):
     userId = User.objects.create(username="******", sponsor=MasterUser.Get()).id
     self.assertEqual(0, User.Get(userId).binary_money)
     self.assertEqual(0, MasterUser.Get().binary_money)
     Controller().payBinaryPrice(userId)
     self.assertEqual(-Controller().price, User.Get(userId).binary_money)
     self.assertEqual(Controller().price, MasterUser.Get().binary_money)
Пример #2
0
 def testCreateNewBinaryPositionForUser(self):
     userId = User.objects.create(username="******", sponsor=MasterUser.Get()).id
     self.assertEqual(1, len(BinaryPosition.objects.all()))
     self.assertFalse(User.Get(userId).active_binary_position)
     newPosition = Controller().createNewBinaryPosition(userId)
     self.assertTrue(newPosition)
     self.assertEqual(newPosition, User.Get(userId).active_binary_position)
     self.assertEqual(2, len(BinaryPosition.objects.all()))
     self.assertEqual(MasterUser.Get().active_binary_position.left, newPosition)
     self.assertEqual(newPosition.parent, MasterUser.Get().active_binary_position)
Пример #3
0
 def testCreateNewUser(self):
     c = Controller()
     c._getState().tree_view = State.UNILEVEL_TREE
     master = MasterUser.Get()
     user1Id = c.createNewUser(master)
     tree = UnilevelTree()
     tree.treeToJson(User.Get(user1Id).active_unilevel_position)
     user2Id = c.createNewUser(User.Get(user1Id))
     tree.treeToJson(User.Get(user1Id).active_unilevel_position)
     tree.treeToJson(User.Get(user2Id).active_unilevel_position)
Пример #4
0
 def testUserLeaves_MasterCannotLeave(self):
     c = Controller()
     with self.assertRaises(MasterUser.MasterCannotLeave):
         c.userLeaves(MasterUser.Get().id)
     user1Id = User.objects.create(username="******", sponsor=MasterUser.Get()).id
     user2Id = User.objects.create(username="******", sponsor=User.Get(user1Id)).id
     self.assertEqual(User.Get(user2Id).sponsor.id, user1Id)
     self.assertTrue(User.Get(user1Id).isActive)
     c.userLeaves(user1Id)
     self.assertFalse(User.Get(user1Id).isActive)
     self.assertEqual(User.Get(user2Id).sponsor.id, MasterUser.Get().id)
Пример #5
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)
Пример #6
0
 def testCreateNewUser(self):
     self.assertEqual(0, len(User.objects.all()))
     sponsor = MasterUser.Get()
     newUser = User.CreateNewUser(sponsor)
     self.assertEqual(2, len(User.objects.all()))
     self.assertEqual("user1", newUser.username)
     self.assertEqual(sponsor.id, newUser.sponsor.id)
Пример #7
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)
Пример #8
0
 def testPayMonthlyCommission(self):
     userId = User.objects.create(username="******").id
     User.Get(userId).addNewActiveUnilevelPosition()
     position_1_1 = UnilevelPosition.objects.create(owner=User.Get(userId), parent=User.Get(userId).active_unilevel_position)
     position_1_1.save()
     self.assertEqual(User.Get(userId).unilevel_money, 0)
     Controller().payMonthlyCommission(userId)
     self.assertEqual(User.Get(userId).unilevel_money, 10)
     position_1_2 = UnilevelPosition.objects.create(owner=User.Get(userId), parent=User.Get(userId).active_unilevel_position)
     position_1_2.save()
     Controller().payMonthlyCommission(userId)
     self.assertEqual(User.Get(userId).unilevel_money, 30)
Пример #9
0
def graph_eval_more_users(request):
    for i in range(6):
        user = User.CreateNewUser(sponsor=MasterUser.Get())
        Controller().createNewBinaryPosition(user.id)
        Controller().createNewUnilevelPosition(user.id)
    return HttpResponseRedirect('/dev/graph_eval/')
Пример #10
0
 def _createBinaryPositions(self, numberOfPositions, sponsorId):
     for i in range(0, numberOfPositions):
         user = User.objects.create(username=("User%d" % i), sponsor=User.Get(sponsorId))
         self.assertTrue(User.Get(sponsorId).active_binary_position)
         Controller().createNewBinaryPosition(user.id)
Пример #11
0
 def _getFirstOrdinaryUser(self):
     return User.objects.get(id=User.IdOfFirstOrdinaryUser())
Пример #12
0
 def _createInvitedUser(self, sponsor):
     user = User.CreateNewUser(sponsor=sponsor)
     user.addNewActiveUnilevelPosition()
     return user
Пример #13
0
 def testCreateNewUser_persistency(self):
     self.assertTrue(User.Get(Controller().createNewUser(MasterUser.Get())).active_unilevel_position)
Пример #14
0
 def testSetActualUser(self):
     c = Controller()
     newUser = User.CreateNewUser(User.objects.get(id=1))
     self.assertNotEqual(newUser, c.getActualUser())
     c.setActualUser(newUser)
     self.assertEqual(newUser, c.getActualUser())