Passed
Push — master ( 91831d...3add59 )
by Steffen
01:51
created

test_players.TestPlayers.test_eq()   A

Complexity

Conditions 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 1
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
import random
4
import unittest
5
6
from tw_serverinfo.models.player import Player
7
from tw_serverinfo.utility import custom_countries
8
9
10
class TestPlayers(unittest.TestCase):
11
12
    def test_country_functions(self):
13
        """Test the country functions since they are the only property containing logic
14
        instead of plain getters and setters
15
16
        :return:
17
        """
18
        for custom_country_code in custom_countries.keys():
19
            p = Player(name='dummy', country=int(custom_country_code))
20
            self.assertEqual(p.country, custom_countries[custom_country_code]['name'])
21
            self.assertEqual(p.country_code, custom_countries[custom_country_code]['code'])
22
            self.assertEqual(p.country_index, int(custom_country_code))
23
24
        for i in range(100):
25
            country_numeric = random.randint(1, 900)
26
            p = Player(name='dummy', country=country_numeric)
27
            self.assertIsInstance(p.country, str)
28
            self.assertIsInstance(p.country_code, str)
29
            self.assertIsInstance(p.country_index, int)
30
31
    def test_repr(self):
32
        """Test if all attributes in the repr function can get called properly
33
34
        :return:
35
        """
36
        p1 = Player(name='dummy')
37
        self.assertIsInstance(p1.__repr__(), str)
38
39
    def test_eq(self):
40
        """Check if equality check works. MasterServer objects with the same ip and same port should
41
        return True even if another attribute is set
42
43
        :return:
44
        """
45
        p1 = Player(name='dummy', score=0)
46
        p2 = Player(name='dummy2', score=1)
47
        p3 = Player(name='dummy', score=1)
48
        self.assertEqual(p1, p3)
49
        self.assertNotEqual(p1, p2)
50
        self.assertNotEqual(p2, p3)
51
52
53
if __name__ == '__main__':
54
    suite = unittest.TestLoader().loadTestsFromTestCase(TestPlayers)
55
    unittest.TextTestRunner(verbosity=2).run(suite)
56