def test_credentaial_add_invalid(self, fake_cred): prov = BaseProvider(ENVIRONMENT, ENGINE) errmsg = "Invalid Credential" fake_cred.return_value = self.credential_add_cls fake_cred.return_value.is_valid = lambda s, a: (False, errmsg) f = prov.credential_add(content={}) self.assertFalse(f[0]) self.assertEqual(f[1], errmsg)
def test_credentaial_add_valid(self, fake_cred): prov = BaseProvider(ENVIRONMENT, ENGINE) fake_cred.return_value = self.credential_add_cls fake_cred.return_value.is_valid = lambda s, a: (True, "") fake_cred.return_value.save = lambda s: {'_id': FAKE_SAVE_ID} f = prov.credential_add(content={}) self.assertTrue(f[0]) self.assertEqual(f[1], FAKE_SAVE_ID)
def test_credentaial_add_raises_on_save(self, fake_cred): prov = BaseProvider(ENVIRONMENT, ENGINE) errmsg = "Error on save" def raise_(ex): raise ex fake_cred.return_value = self.credential_add_cls fake_cred.return_value.is_valid = lambda s, a: (True, "") fake_cred.return_value.save = lambda s: raise_(Exception(errmsg)) f = prov.credential_add(content={}) self.assertFalse(f[0]) self.assertEqual(f[1], errmsg)
def test_credential_add_raise(self): prov = BaseProvider(ENVIRONMENT, ENGINE) with self.assertRaises(NotImplementedError): prov.credential_add(None)