def test_invalid_missing_id_and_key(self): data = { 'other': 'data', } with self.assertRaises(InvalidRequest) as ctx: authenticate(data) self.assertEqual(str(ctx.exception), 'Authentication failed (missing "unit_id" field).')
def test_disabled_unit(self): data = { 'unit_id': 456, 'secret_key': self.disabled_unit_key, 'other': 'data', } with self.assertRaises(InvalidRequest) as ctx: authenticate(data) self.assertEqual(str(ctx.exception), 'Authentication failed (unit is disabled).')
def test_invalid_id(self): data = { 'unit_id': 1234, 'secret_key': self.secret_key, 'other': 'data', } with self.assertRaises(InvalidRequest) as ctx: authenticate(data) self.assertEqual(str(ctx.exception), 'Authentication failed (wrong "unit_id" and/or "secret_key").')
def test_invalid_unit_id_format(self): data = { 'unit_id': 'asdf', 'secret_key': self.disabled_unit_key, 'other': 'data', } with self.assertRaises(InvalidRequest) as ctx: authenticate(data) self.assertEqual(str(ctx.exception), 'Authentication failed ' '("unit_id" should be an integer, not "asdf").')
def test_invalid_id(self): data = { 'unit_id': 1234, 'secret_key': self.secret_key, 'other': 'data', } with self.assertRaises(InvalidRequest) as ctx: authenticate(data) self.assertEqual( str(ctx.exception), 'Authentication failed (wrong "unit_id" and/or "secret_key").')
def test_invalid_unit_id_format(self): data = { 'unit_id': 'asdf', 'secret_key': self.disabled_unit_key, 'other': 'data', } with self.assertRaises(InvalidRequest) as ctx: authenticate(data) self.assertEqual( str(ctx.exception), 'Authentication failed ' '("unit_id" should be an integer, not "asdf").')
def test_valid(self): data = { 'unit_id': 123, 'secret_key': self.secret_key, 'other': 'data', } self.assertEqual(authenticate(data), { 'unit_id': 123, 'other': 'data', })