Ejemplo n.º 1
0
class TestBank(unittest.TestCase):
    def setUp(self):
        self.filename = "test_database.db"
        open(self.filename, "w").close()
        self.dom = SqlLiteDom(self.filename)
        self.dom.createBankTables()

    def tearDown(self):
        os.remove(self.filename)

    def testAward(self):
        self.dom.createAccount("jacob")
        bank.award(self.dom, "jacob", 100)
        balance = bank.balance(self.dom, "jacob")
        self.assertEquals(balance, 100)

    def testTransfer(self):
        self.dom.createAccount("jacob")
        self.dom.createAccount("noah")
        bank.award(self.dom, "jacob", 100)
        bank.transfer(self.dom, "jacob", "noah", 25)
        self.assertTrue(75, bank.balance(self.dom, "jacob"))
        self.assertTrue(25, bank.balance(self.dom, "noah"))
Ejemplo n.º 2
0
class TestHr(unittest.TestCase):
    def setUp(self):
        self.filename = "test_database.db"
        open(self.filename, "w").close()
        self.dom = SqlLiteDom(self.filename)
        self.dom.createDatabaseTables()
        self.dom.createBankTables()
        self.dom.createGameAccountMappingTable()

    def tearDown(self):
        os.remove(self.filename)

    def testProcessPerformace(self):
        hr.conscript(self.dom, "jacob", "psn", "creatif_craxy")
        stat0a = {
            'data': {
                'segments': [{
                    'stats': {
                        'wins': {
                            'value': 1
                        },
                        "kills": {
                            'value': 0
                        }
                    }
                }]
            }
        }
        stat0b = {
            'data': {
                'segments': [{
                    'stats': {
                        'wins': {
                            'value': 5
                        },
                        "kills": {
                            'value': 100
                        }
                    }
                }]
            }
        }
        self.dom.loadStat('creatif_craxy', 0, json.dumps(stat0a))
        self.dom.loadStat('creatif_craxy', 1, json.dumps(stat0b))
        hr.processPerformance(self.dom, 0, 1)
        self.assertEquals(self.dom.balance("jacob"), 5)

    def testReport(self):
        hr.conscript(self.dom, "jacob", "psn", "creatif_craxy")
        stat0a = {
            'data': {
                'segments': [{
                    'stats': {
                        'wins': {
                            'value': 1
                        },
                        "kills": {
                            'value': 0
                        }
                    }
                }]
            }
        }
        stat0b = {
            'data': {
                'segments': [{
                    'stats': {
                        'wins': {
                            'value': 5
                        },
                        "kills": {
                            'value': 100
                        }
                    }
                }]
            }
        }
        self.dom.loadStat('creatif_craxy', 0, json.dumps(stat0a))
        self.dom.loadStat('creatif_craxy', 1, json.dumps(stat0b))
        performanceInfo = hr.processPerformance(self.dom, 0, 1)
        self.assertEquals(self.dom.balance("jacob"), 5)
        report = hr.generateReports(performanceInfo, None)
        print(report)

    def testComplexPerformace(self):
        hr.conscript(self.dom, "jacob", "psn", "creatif_craxy")
        hr.conscript(self.dom, "noah", "psn", "ugly_noah")
        stat0a = {
            'data': {
                'segments': [{
                    'stats': {
                        'wins': {
                            'value': 1
                        },
                        "kills": {
                            'value': 0
                        }
                    }
                }]
            }
        }
        stat0b = {
            'data': {
                'segments': [{
                    'stats': {
                        'wins': {
                            'value': 5
                        },
                        "kills": {
                            'value': 100
                        }
                    }
                }]
            }
        }
        self.dom.loadStat('creatif_craxy', 0, json.dumps(stat0a))
        self.dom.loadStat('creatif_craxy', 1, json.dumps(stat0b))
        self.dom.loadStat('ugly_noah', 0, json.dumps(stat0a))
        self.dom.loadStat('ugly_noah', 1, json.dumps(stat0b))
        hr.processPerformance(self.dom, 0, 1)
        self.assertEquals(self.dom.balance("jacob"), 5)
        self.assertEquals(self.dom.balance("noah"), 5)

    def testAwardTokensToGameAccounts(self):
        hr.conscript(self.dom, "jacob", "psn", "creatif_craxy")
        hr.conscript(self.dom, "jacob", "psn", "my_alt")
        hr.conscript(self.dom, "noah", "psn", "uglynoah")
        table = [["creatif_craxy", 10], ["my_alt", 3], ["uglynoah", 8]]
        hr.awardTokensToGameAccounts(self.dom, table)
        self.assertEquals(self.dom.balance("jacob"), 13)
        self.assertEquals(self.dom.balance("noah"), 8)

    def testAwardTokensToGameAccounts(self):
        hr.conscript(self.dom, "jacob", "psn", "creatif_craxy")
        hr.conscript(self.dom, "jacob", "psn", "my_alt")
        hr.conscript(self.dom, "noah", "psn", "uglynoah")
        table = [["creatif_craxy", 10, 0], ["my_alt", 3, 0],
                 ["uglynoah", 8, 0]]
        hr.awardTokensToGameAccounts(self.dom, table)
        self.assertEquals(self.dom.balance("jacob"), 13)
        self.assertEquals(self.dom.balance("noah"), 8)

    def testConscript(self):
        hr.conscript(self.dom, "jacob", "psn", "creatif_craxy")
        print(self.dom.getUsers())
        self.assertTrue(self.dom.userExists("creatif_craxy"))
        self.assertTrue(self.dom.hasAccount("jacob"))
        account = self.dom.getAccountForPlatformUsername(
            "psn", "creatif_craxy")
        self.assertEquals(account, "jacob")
Ejemplo n.º 3
0
class TestDomOperations(unittest.TestCase):
    
    defaultUsername = '******'
    defaultBattalion = 'ugly'

    #TODO add alternate data 
    #TODO map all returns to entry

    def setUp(self):
        self.filename = "test_database.db"
        open(self.filename, "w").close()
        self.dom = SqlLiteDom(self.filename)

    def tearDown(self):
        os.remove(self.filename)

    def testCreateConnection(self):
        conn = self.dom.createConnection()
        self.assertTrue(conn.cursor())
        conn.close()

    def testKeyOperations(self):
        self.dom.createDatabaseTables()
        key = self.dom.getKey()
        self.assertEquals(None, key)
        key = self.dom.incremementKey()
        self.assertEquals(0, key)
        key = self.dom.getKey()
        self.assertEquals(0, key)
        index = self.dom.getIndex(key)
        self.assertTrue(index[0][1] > 10)

    def testRegisterChannel(self):
        self.dom.createDatabaseTables()
        self.dom.registerChannel(1616171771178818181818181881)
        self.dom.registerChannel(171717717)
        channels = self.dom.getChannels()
        self.assertEquals(2, len(channels))
        self.dom.clearChannels()
        channels = self.dom.getChannels()
        self.assertEquals(0, len(channels))

    def testEnlistUser(self):
        self.dom.createDatabaseTables()
        self.dom.enlistUser(self.defaultUsername)
        users = self.dom.getUsers()
        
        self.assertEquals(1, len(users))
        self.assertEquals(self.defaultUsername, users[0][0])

    def testDischargeUser(self):
        self.dom.createDatabaseTables()
        self.dom.enlistUser(self.defaultUsername)
        self.dom.dischargeUser(self.defaultUsername)
        users = self.dom.getUsers()
        self.assertEquals(0, len(users)) 

    def testGetJoinedStat(self):
        self.dom.createDatabaseTables()
        stat1a = {'data':{'segments':[{'stats':{'metric':{'value':2}}}]}}
        #stat1b = {'data':{'segments':[{'stats':{'metric':{'value':1}}}]}}
        stat2a = {'data':{'segments':[{'stats':{'metric':{'value':3}}}]}}
        stat2b = {'data':{'segments':[{'stats':{'metric':{'value':5}}}]}}
        stat3a = {'data':{'segments':[{'stats':{'metric':{'value':8}}}]}}
        stat3b = {'data':{'segments':[{'stats':{'metric':{'value':8}}}]}}
        self.dom.loadStat('usera',0, json.dumps(stat1a))
        #self.dom.loadStat('userb',0, json.dumps(stat1b))
        self.dom.loadStat('usera',1, json.dumps(stat2a))
        self.dom.loadStat('userb',1, json.dumps(stat2b))
        self.dom.loadStat('usera',2, json.dumps(stat3a))
        self.dom.loadStat('userb',2, json.dumps(stat3b))
        joinedStat = self.dom.getFriendlyJoinedStat(0, 1)
        self.assertEquals(2, len(joinedStat))

    def testGetFriendlyJoinedStat(self):
        self.dom.createDatabaseTables()
        stat1a = {'data':{'segments':[{'stats':{'metric':{'value':2}}}]}}
        stat2a = {'data':{'segments':[{'stats':{'metric':{'value':3}}}]}}
        stat2b = {'data':{'segments':[{'stats':{'metric':{'value':5}}}]}}
        stat3a = {'data':{'segments':[{'stats':{'metric':{'value':8}}}]}}
        stat3b = {'data':{'segments':[{'stats':{'metric':{'value':8}}}]}}
        self.dom.loadStat('usera',0, json.dumps(stat1a))
        self.dom.loadStat('usera',1, json.dumps(stat2a))
        self.dom.loadStat('userb',1, json.dumps(stat2b))
        self.dom.loadStat('usera',2, json.dumps(stat3a))
        self.dom.loadStat('userb',2, json.dumps(stat3b))
        joinedStat = self.dom.getFriendlyJoinedStat(0, 1)
        self.assertEquals(2, len(joinedStat))
        self.assertEquals(0, joinedStat[0][3])
        self.assertEquals(1, joinedStat[1][3])


    #### BANKING TESTS
    def testGetNoAccount(self):
        self.dom.createBankTables()
        account = self.dom.getAccount("user")
        self.assertEquals(len(account), 0)

    def testGetAccount(self):
        self.dom.createBankTables()
        self.dom.createAccount("user")
        account = self.dom.getAccount("user")
        self.assertEquals(len(account), 1)
        self.assertEquals(account[0][0], "user")
        self.assertEquals(account[0][1], 0)

    def testDeltaBalance(self):
        self.dom.createBankTables()
        self.dom.createAccount("user")
        self.dom.deltaBalance("user", 50)
        account = self.dom.getAccount("user")
        self.assertEqual(len(account), 1)
        self.assertEquals(account[0][0], "user")
        self.assertEquals(account[0][1], 50)
        self.dom.deltaBalance("user", -30)
        self.assertTrue(len(account), 1)
        account = self.dom.getAccount("user")
        self.assertEquals(account[0][1], 20)

    def testCreateDuplicateAccountFail(self):
        self.dom.createBankTables()
        self.dom.createAccount("user")
        self.assertRaises(
            sqlite3.IntegrityError,
             self.dom.createAccount,
              "user"
        )

    def createAndDropTable(self):
        self.dom.createBankTables()
        self.dom.createAccount("user")
        self.dom.dropBankTables()
        self.dom.createBankTables()
        account = self.dom.getAccount("user")
        self.assertEquals(len(account), 0)

    #### CONSCRIPTION TESTS #
    def testConscriptUser(self):
        self.dom.createGameAccountMappingTable()
        self.dom.conscriptUser("jacob", "psn", "creatif_craxy")
        account = self.dom.getAccountForPlatformUsername("psn", "creatif_craxy")
        self.assertEquals("jacob", account)

    def testConscriptUser(self):
        self.dom.createGameAccountMappingTable()
        self.dom.conscriptUser("jacob", "psn", "creatif_craxy")
        self.assertRaises(
            sqlite3.IntegrityError,
             self.dom.conscriptUser,
              "some_schmuck", "psn", "creatif_craxy"
        )

    def testGetAccountForPlatformUserName(self):
        self.dom.createGameAccountMappingTable()
        self.dom.conscriptUser("jacob", "psn", "creatif_craxy")
        accountMapping = self.dom.getAccountForPlatformUsername("psn", "creatif_craxy")
        self.assertEquals("jacob", accountMapping)

    def testGetAccountForPlatformUserName(self):
        self.dom.createGameAccountMappingTable()
        accountMapping = self.dom.getAccountForPlatformUsername("psn", "creatif_craxy")
        self.assertEquals(None, accountMapping)

    def testCreateAndDropTable(self):
        self.dom.createGameAccountMappingTable()
        self.dom.conscriptUser("jacob", "psn", "creatif_craxy")
        accountMapping = self.dom.getAccountForPlatformUsername("psn", "creatif_craxy")
        self.dom.dropMappingTable()
        self.dom.createGameAccountMappingTable()
        accountMapping = self.dom.getAccountForPlatformUsername("psn", "creatif_craxy")
        self.assertEquals(None, accountMapping)

    def testBattalionOperations(self):
        self.dom.createBattalionTables()
        self.dom.createBattalion("UGLY")
        battalions = self.dom.getBattalions()
        self.assertEquals(battalions[0][0], "UGLY")
        self.dom.setUserPermissionOnBattalion("jacob", "UGLY", "ADMIN")
        permissions = self.dom.getUserBattalionPermission("jacob", "COMMANDER")
        self.assertEquals(permissions[0][0], "COMMANDER")