~thelinuxguy/openlp/fix-version-check

« back to all changes in this revision

Viewing changes to tests/functional/openlp_core/common/test_projector_utilities.py

  • Committer: Tim Bentley
  • Date: 2017-12-17 14:02:03 UTC
  • mfrom: (2792.1.17 fixes)
  • Revision ID: tim.bentley@gmail.com-20171217140203-k9fg0sv6of9qinjd
Refactor asserts in api and common packages

lp:~trb143/openlp/asserts (revision 2809)
https://ci.openlp.io/job/Branch-01-Pull/2354/                          [SUCCESS]
https://ci.openlp.io/job/Branch-02-Functional-Tests/2255/              [SUCCESS]
https://ci.openlp.io/job/Branch-03-Interface-Tests/2120/               [SUCCESS]
https://ci.openlp.io/job/Branch-04a-Code_Analysis/1446/                [SUCCESS]
https://ci.openlp.io/job/Branch-04b-Test_Coverage/1263/                [SUCCESS]
https...

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
ip6_bad = 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'
46
46
 
47
47
 
48
 
class testProjectorUtilities(TestCase):
 
48
class TestProjectorUtilities(TestCase):
49
49
    """
50
50
    Validate functions in the projector utilities module
51
51
    """
57
57
        valid = verify_ip_address(addr=ip4_loopback)
58
58
 
59
59
        # THEN: Verify we received True
60
 
        self.assertTrue(valid, 'IPv4 loopback address should have been valid')
 
60
        assert valid, 'IPv4 loopback address should have been valid'
61
61
 
62
62
    def test_ip4_local_valid(self):
63
63
        """
67
67
        valid = verify_ip_address(addr=ip4_local)
68
68
 
69
69
        # THEN: Verify we received True
70
 
        self.assertTrue(valid, 'IPv4 local address should have been valid')
 
70
        assert valid is True, 'IPv4 local address should have been valid'
71
71
 
72
72
    def test_ip4_broadcast_valid(self):
73
73
        """
77
77
        valid = verify_ip_address(addr=ip4_broadcast)
78
78
 
79
79
        # THEN: Verify we received True
80
 
        self.assertTrue(valid, 'IPv4 broadcast address should have been valid')
 
80
        assert valid is True, 'IPv4 broadcast address should have been valid'
81
81
 
82
82
    def test_ip4_address_invalid(self):
83
83
        """
87
87
        valid = verify_ip_address(addr=ip4_bad)
88
88
 
89
89
        # THEN: Verify we received True
90
 
        self.assertFalse(valid, 'Bad IPv4 address should not have been valid')
 
90
        assert valid is False, 'Bad IPv4 address should not have been valid'
91
91
 
92
92
    def test_ip6_loopback_valid(self):
93
93
        """
97
97
        valid = verify_ip_address(addr=ip6_loopback)
98
98
 
99
99
        # THEN: Validate return
100
 
        self.assertTrue(valid, 'IPv6 loopback address should have been valid')
 
100
        assert valid is True, 'IPv6 loopback address should have been valid'
101
101
 
102
102
    def test_ip6_local_valid(self):
103
103
        """
107
107
        valid = verify_ip_address(addr=ip6_link_local)
108
108
 
109
109
        # THEN: Validate return
110
 
        self.assertTrue(valid, 'IPv6 link-local address should have been valid')
 
110
        assert valid is True, 'IPv6 link-local address should have been valid'
111
111
 
112
112
    def test_ip6_address_invalid(self):
113
113
        """
117
117
        valid = verify_ip_address(addr=ip6_bad)
118
118
 
119
119
        # THEN: Validate bad return
120
 
        self.assertFalse(valid, 'IPv6 bad address should have been invalid')
 
120
        assert valid is False, 'IPv6 bad address should have been invalid'
121
121
 
122
122
    def test_md5_hash(self):
123
123
        """
127
127
        hash_ = md5_hash(salt=salt.encode('utf-8'), data=pin.encode('utf-8'))
128
128
 
129
129
        # THEN: Validate return has is same
130
 
        self.assertEquals(hash_, test_hash, 'MD5 should have returned a good hash')
 
130
        assert hash_ == test_hash, 'MD5 should have returned a good hash'
131
131
 
132
132
    def test_md5_hash_bad(self):
133
133
        """
137
137
        hash_ = md5_hash(salt=pin.encode('utf-8'), data=salt.encode('utf-8'))
138
138
 
139
139
        # THEN: return data is different
140
 
        self.assertNotEquals(hash_, test_hash, 'MD5 should have returned a bad hash')
 
140
        assert hash_ is not test_hash, 'MD5 should have returned a bad hash'
141
141
 
142
142
    def test_qmd5_hash(self):
143
143
        """
147
147
        hash_ = qmd5_hash(salt=salt.encode('utf-8'), data=pin.encode('utf-8'))
148
148
 
149
149
        # THEN: Validate return has is same
150
 
        self.assertEquals(hash_, test_hash, 'Qt-MD5 should have returned a good hash')
 
150
        assert hash_ == test_hash, 'Qt-MD5 should have returned a good hash'
151
151
 
152
152
    def test_qmd5_hash_bad(self):
153
153
        """
157
157
        hash_ = qmd5_hash(salt=pin.encode('utf-8'), data=salt.encode('utf-8'))
158
158
 
159
159
        # THEN: return data is different
160
 
        self.assertNotEquals(hash_, test_hash, 'Qt-MD5 should have returned a bad hash')
 
160
        assert hash_ is not test_hash, 'Qt-MD5 should have returned a bad hash'
161
161
 
162
162
    def test_md5_non_ascii_string(self):
163
163
        """
167
167
        hash_ = md5_hash(salt=test_non_ascii_string.encode('utf-8'), data=None)
168
168
 
169
169
        # THEN: Valid MD5 hash should be returned
170
 
        self.assertEqual(hash_, test_non_ascii_hash, 'MD5 should have returned a valid hash')
 
170
        assert hash_ == test_non_ascii_hash, 'MD5 should have returned a valid hash'
171
171
 
172
172
    def test_qmd5_non_ascii_string(self):
173
173
        """
177
177
        hash_ = md5_hash(data=test_non_ascii_string.encode('utf-8'))
178
178
 
179
179
        # THEN: Valid MD5 hash should be returned
180
 
        self.assertEqual(hash_, test_non_ascii_hash, 'Qt-MD5 should have returned a valid hash')
 
180
        assert hash_ == test_non_ascii_hash, 'Qt-MD5 should have returned a valid hash'