예제 #1
0
    def test_get_last_record(self, requests_get_patched):
        mock_response = Mock(spec=Response)
        mock_response.status_code = 200
        mock_response.text = self.expected_current.xml
        requests_get_patched.return_value = mock_response

        last_record = NistBeacon.get_last_record()
        self.assertIsInstance(last_record, NistBeaconValue)
예제 #2
0
    def test_get_last_record_exceptions(self, requests_get_patched):
        exceptions_to_test = [
            requests.exceptions.RequestException(),
            requests.exceptions.ConnectionError(),
            requests.exceptions.HTTPError(),
            requests.exceptions.URLRequired(),
            requests.exceptions.TooManyRedirects(),
            requests.exceptions.Timeout(),
        ]

        for exception_to_test in exceptions_to_test:
            requests_get_patched.side_effect = exception_to_test
            self.assertIsNone(NistBeacon.get_last_record())
예제 #3
0
from nistbeacon import NistBeacon
import time

print()
print('Coin flip 0 or 1 tails or heads')
print()
print('Run five times')

for count in range(5):
    time.sleep(66)  # wait for new beacon every 66 seconds
    h = NistBeacon.get_last_record()
    v = h.output_value  # 512 hex
    d = int(v, 16)  # convert to decimal
    coin = d % 2  # modulus of record (0 or 1)

    if coin == 0:
        print('tails')
    else:
        print('heads')
예제 #4
0
    def test_get_last_record_404(self, requests_get_patched):
        mock_response = Mock(spec=Response)
        mock_response.status_code = 404
        requests_get_patched.return_value = mock_response

        self.assertIsNone(NistBeacon.get_last_record())
예제 #5
0
    def test_get_last_record(self):
        actual = NistBeacon.get_last_record()

        self.assertTrue(actual.valid_signature)