Пример #1
0
 def test_viaScannedBadge(self):
     for b in random.sample(self.bnums[4:], 3):
         with \
         self.subTest("Badge {}".format(self.barcodes[b - 20])),\
         open('tests/sampledata/b{}.json'.format(b)) as f:
             apidata = self.loop.run_until_complete(
                 bdgchk.getAttndFromMAGAPI(self.barcodes[b - 20])).text
             sampledata = f.read()
             self.assertEqual(loads(apidata), loads(sampledata))
Пример #2
0
    def test_connectionError(self):
        bdgchk.logger.error.reset_mock()
        ce = bdgchk.requests.exceptions.ConnectionError('')
        ce.request = bdgchk.requests.Request()
        bdgchk.requests.post = MagicMock(side_effect=ce)

        expected = bdgchk.requests.Response()
        expected.status_code = 504
        expected.error = ''
        actual = self.loop.run_until_complete(bdgchk.getAttndFromMAGAPI(1))

        self.assertEqual(expected.error, actual.error)
        self.assertEqual(expected.status_code, actual.status_code)
        bdgchk.logger.error.assert_called_once_with(
            'Failed to connect to None \nHeader: {}\nError: ')
Пример #3
0
    def test_timeout(self):
        bdgchk.logger.error.reset_mock()
        bdgchk.requests.post = MagicMock(
            side_effect=bdgchk.requests.exceptions.ConnectTimeout())

        expected = bdgchk.requests.Response()
        expected.status_code = 598
        expected.error = 'Connection timed out after {}ms'.format(
            bdgchk.getSetting('timeout') * 1000)
        actual = self.loop.run_until_complete(bdgchk.getAttndFromMAGAPI(1))

        self.assertEqual(expected.error, actual.error)
        self.assertEqual(expected.status_code, actual.status_code)
        bdgchk.logger.error.assert_called_once_with(
            'Connection timed out after {}ms'.format(
                bdgchk.getSetting('timeout') * 1000))
Пример #4
0
 def test_badData(self):
     with self.assertRaises(ValueError) as context:
         self.loop.run_until_complete(bdgchk.getAttndFromMAGAPI({}))
     self.assertIn('Data was not an integer or a string',
                   context.exception.args)
Пример #5
0
 def test_badInt(self):
     with self.assertRaises(ValueError) as context:
         self.loop.run_until_complete(bdgchk.getAttndFromMAGAPI(-1))
     self.assertIn('(-1) is less than 0', context.exception.args)
Пример #6
0
 def test_emptyString(self):
     with self.assertRaises(ValueError) as context:
         self.loop.run_until_complete(bdgchk.getAttndFromMAGAPI(""))
     self.assertIn('Not a valid badge string', context.exception.args)