def test_Signature_to_selector(self): s = Signature(id='1234') self.assertEqual(s.to_selector(), {'id': '1234'}) self.assertIsInstance(s.to_selector(), dict) s = Signature(name='jdoe') self.assertEqual(s.to_selector(), {'name': 'jdoe'}) s = Signature(id='1234', name='jdoe') self.assertEqual(s.to_selector(), {'id': '1234'})
def test_get_a_signature_by_id(self): sig1 = self.zc.create_signature('unittest', 'CONTENT', "text/html") sig2 = self.zc.create_signature('unittest1', 'CONTENT', "text/html") resp = self.zc.get_signature(Signature(id=sig1.id)) self.assertIsInstance(resp, Signature) self.assertEqual(resp, sig1) resp = self.zc.get_signature(Signature(id=sig2.id)) self.assertIsInstance(resp, Signature) self.assertEqual(resp, sig2)
def test_get_a_signature_by_name(self): sig1 = self.zc.create_signature('unittest', 'CONTENT', "text/html") self.zc.create_signature('unittest1', 'CONTENT', "text/html") resp = self.zc.get_signature(Signature(name='unittest')) self.assertIsInstance(resp, Signature) self.assertEqual(resp, sig1)
def test_Signature_to_selector(self): s = Signature(id="1234") self.assertEqual(s.to_selector(), {"id": "1234"}) self.assertIsInstance(s.to_selector(), dict) s = Signature(name="jdoe") self.assertEqual(s.to_selector(), {"name": "jdoe"}) s = Signature(id="1234", name="jdoe") self.assertEqual(s.to_selector(), {"id": "1234"})
def test_get_a_signature_by_name_case_insensitive(self): """ Zimbra considers that the signature name should be unique two signatures with same name, diferently cased is not allowed, so it's logical to be able to query a signature with any case. """ sig1 = self.zc.create_signature('unittest', 'CONTENT', "text/html") self.zc.create_signature('unittest1', 'CONTENT', "text/html") resp = self.zc.get_signature(Signature(name='unitTEST')) self.assertIsInstance(resp, Signature) self.assertEqual(resp, sig1)
def test_delete_signature_by_id(self): sig = self.test_create_signature() self.zc.delete_signature(Signature(name=sig.name))
def test_Signature_set_content(self): s = Signature(name='unittest') s.set_content('TEST_CONTENT', contenttype='text/plain') self.assertEqual(s._contenttype, 'text/plain') self.assertEqual(s._content, 'TEST_CONTENT')
def test_Signature_dict_import(self): s = Signature.from_dict(self.signature_dict['signature']) self.assertIsInstance(s, Signature) self.assertIsInstance(s.get_content(), (text_type, binary_type)) self.assertEqual(s.get_content(), 'CONTENT') self.assertEqual(s.get_content_type(), 'text/html')
def test_delete_signature_by_name(self): sig = self.test_create_signature() self.zc.delete_signature(Signature(id=sig.id))
def test_Signature_creator_default_format(self): s = Signature(name="unittest") s.set_content("TEST_CONTENT") self.assertEqual(s._contenttype, "text/html")
def test_Signature_creator_success(self): s = Signature(name='unittest') s.set_content('TEST_CONTENT', contenttype='text/plain') d = s.to_creator() self.assertTrue(d['content'], 'TEST_CONTENT')
def test_Signature_creator_default_format(self): s = Signature(name='unittest') s.set_content('TEST_CONTENT') self.assertEqual(s._contenttype, 'text/html')
def test_modify_signature_without_id_attribute_error(self): sig1 = Signature(name='foo') sig1.set_content('NEW-CONTENT', "text/plain") with self.assertRaises(AttributeError): self.zc.modify_signature(sig1)
def test_Signature_dict_import(self): s = Signature.from_dict(self.signature_dict["signature"]) self.assertIsInstance(s, Signature) self.assertIsInstance(s.get_content(), (text_type, binary_type)) self.assertEqual(s.get_content(), "CONTENT") self.assertEqual(s.get_content_type(), "text/html")
def test_Signature_creator_success(self): s = Signature(name="unittest") s.set_content("TEST_CONTENT", contenttype="text/plain") d = s.to_creator() self.assertTrue(d["content"], "TEST_CONTENT")
def test_Signature_set_content(self): s = Signature(name="unittest") s.set_content("TEST_CONTENT", contenttype="text/plain") self.assertEqual(s._contenttype, "text/plain") self.assertEqual(s._content, "TEST_CONTENT")
def test_get_a_signature_by_nonexistant_name_returns_none(self): resp = self.zc.get_signature(Signature(name='idonotexist')) self.assertEqual(resp, None)
def test_get_a_signature_by_nonexistant_id_returns_none(self): resp = self.zc.get_signature( Signature(id='42428c6a-d764-479f-ae7d-d2d626b44242')) self.assertEqual(resp, None)
def test_Signature_creator_fails_without_content(self): s = Signature(name="unittest") with self.assertRaises(AttributeError): s.to_xml_creator()
def test_Signature_creator_fails_without_content(self): s = Signature(name='unittest') with self.assertRaises(AttributeError): s.to_xml_creator()