def test_basic_batch_not_verbose(self): """Assert a well-formed not verbose email is returned from a basic message.""" expected = ( 'Precedence: Bulk\n' 'Auto-Submitted: auto-generated\n' 'From: [email protected]\n' 'To: [email protected]\n' 'X-Fedmsg-Topic: org.fedoraproject.dev.fmn.filter.update\n' 'X-Fedmsg-Category: fmn\n' 'X-Fedmsg-Username: bowlofeggs\n' 'X-Fedmsg-Username: jcline\n' 'X-Fedmsg-Num-Packages: 0\n' 'Subject: Fedora Notifications Digest (2 updates)\n' 'MIME-Version: 1.0\n' 'Content-Type: text/plain; charset="utf-8"\n' 'Content-Transfer-Encoding: base64\n\n' 'KDIwMTctMTAtMDYgMTc6MjU6MzAgVVRDKSBqY2xpbmUgdXBkYXRlZCB0aGUgcnVsZXMgb24gYSBm\n' 'bW4gZW1haWwgZmlsdGVyCi0gaHR0cHM6Ly9hcHBzLmZlZG9yYXByb2plY3Qub3JnL25vdGlmaWNh\n' 'dGlvbnMvCgotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t\n' 'LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tCgooMjAxNy0xMC0wNiAxNzoyNTozMCBVVEMp\n' 'IGJvd2xvZmVnZ3MgdXBkYXRlZCB0aGUgcnVsZXMgb24gYSBmbW4gZW1haWwgZmlsdGVyCi0gaHR0\n' 'cHM6Ly9hcHBzLmZlZG9yYXByb2plY3Qub3JnL25vdGlmaWNhdGlvbnMv\n') actual = formatters.email_batch(self.messages, self.not_verbose_recipient) self.assertEqual(expected, actual)
def test_basic_batch_verbose(self): """Assert a well-formed verbose email is returned from a basic message.""" expected = ( 'Precedence: Bulk\n' 'Auto-Submitted: auto-generated\n' 'From: [email protected]\n' 'To: [email protected]\n' 'X-Fedmsg-Topic: org.fedoraproject.dev.fmn.filter.update\n' 'X-Fedmsg-Category: fmn\n' 'X-Fedmsg-Username: bowlofeggs\n' 'X-Fedmsg-Username: jcline\n' 'X-Fedmsg-Num-Packages: 0\n' 'Subject: Fedora Notifications Digest (2 updates)\n' 'MIME-Version: 1.0\n' 'Content-Type: text/plain; charset="utf-8"\n' 'Content-Transfer-Encoding: base64\n\n' 'RGlnZXN0IFN1bW1hcnk6CjEuCWpjbGluZSB1cGRhdGVkIHRoZSBydWxlcyBvbiBhIGZtbiBlbWFp\n' 'bCBmaWx0ZXIKMi4JYm93bG9mZWdncyB1cGRhdGVkIHRoZSBydWxlcyBvbiBhIGZtbiBlbWFpbCBm\n' 'aWx0ZXIKCi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t\n' 'LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0KCigyMDE3LTEwLTA2IDE3OjI1OjMwIFVUQykg\n' 'amNsaW5lIHVwZGF0ZWQgdGhlIHJ1bGVzIG9uIGEgZm1uIGVtYWlsIGZpbHRlcgotIGh0dHBzOi8v\n' 'YXBwcy5mZWRvcmFwcm9qZWN0Lm9yZy9ub3RpZmljYXRpb25zLwoKamNsaW5lIHVwZGF0ZWQgdGhl\n' 'IHJ1bGVzIG9uIGEgZm1uIGVtYWlsIGZpbHRlcgoKLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t\n' 'LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLQoKKDIw\n' 'MTctMTAtMDYgMTc6MjU6MzAgVVRDKSBib3dsb2ZlZ2dzIHVwZGF0ZWQgdGhlIHJ1bGVzIG9uIGEg\n' 'Zm1uIGVtYWlsIGZpbHRlcgotIGh0dHBzOi8vYXBwcy5mZWRvcmFwcm9qZWN0Lm9yZy9ub3RpZmlj\n' 'YXRpb25zLwoKYm93bG9mZWdncyB1cGRhdGVkIHRoZSBydWxlcyBvbiBhIGZtbiBlbWFpbCBmaWx0\n' 'ZXI=\n') actual = formatters.email_batch(self.messages, self.verbose_recipient) self.assertEqual(expected, actual)
def test_too_many_messages(self): """Test batch content when too many messages are queued.""" big_batch = self.messages * 500 expected = ( 'Precedence: Bulk\n' 'Auto-Submitted: auto-generated\n' 'From: [email protected]\n' 'To: [email protected]\n' 'Subject: Fedora Notifications Digest error\n' 'MIME-Version: 1.0\n' 'Content-Type: text/plain; charset="utf-8"\n' 'Content-Transfer-Encoding: base64\n\n' 'VG9vIG1hbnkgbWVzc2FnZXMgd2VyZSBxdWV1ZWQgdG8gYmUgc2VudCBpbiB0aGlzIGRpZ2VzdCAo\n' 'MTAwMCkhCkNvbnNpZGVyIGFkanVzdGluZyB5b3VyIEZNTiBzZXR0aW5ncy4K\n') actual = formatters.email_batch(big_batch, self.verbose_recipient) self.assertEqual(expected, actual)
def test_unique_username_headers(self): """Test that usernames are added only once for each in headers.""" double_messages = self.messages * 2 expected_start = ( 'Precedence: Bulk\n' 'Auto-Submitted: auto-generated\n' 'From: [email protected]\n' 'To: [email protected]\n' 'X-Fedmsg-Topic: org.fedoraproject.dev.fmn.filter.update\n' 'X-Fedmsg-Category: fmn\n' 'X-Fedmsg-Username: bowlofeggs\n' 'X-Fedmsg-Username: jcline\n' 'X-Fedmsg-Num-Packages: 0\n' 'Subject: Fedora Notifications Digest (4 updates)\n' 'MIME-Version: 1.0\n' 'Content-Type: text/plain; charset="utf-8"\n' 'Content-Transfer-Encoding: base64\n\n') actual = formatters.email_batch(double_messages, self.verbose_recipient) self.assertIn(expected_start, actual)
def test_digest_content_too_long(self): """Test batch content when it exceeds 500k characters limit.""" expected = ( 'Precedence: Bulk\n' 'Auto-Submitted: auto-generated\n' 'From: [email protected]\n' 'To: [email protected]\n' 'X-Fedmsg-Topic: org.fedoraproject.dev.fmn.filter.update\n' 'X-Fedmsg-Category: fmn\n' 'X-Fedmsg-Username: bowlofeggs\n' 'X-Fedmsg-Username: jcline\n' 'X-Fedmsg-Num-Packages: 0\n' 'Subject: Fedora Notifications Digest (2 updates)\n' 'MIME-Version: 1.0\n' 'Content-Type: text/plain; charset="utf-8"\n' 'Content-Transfer-Encoding: base64\n\n' 'VGhpcyBtZXNzYWdlIGRpZ2VzdCB3YXMgdG9vIGxhcmdlIHRvIGJlIHNlbnQhClRoZSBmb2xsb3dp\n' 'bmcgbWVzc2FnZXMgd2VyZSBiYXRjaGVkOgoKMjAxNy02YWE3MWQ1Yi1mYmU0LTQ5ZTctYWZkZC1h\n' 'ZmNmMGQyMjgwMmIKMjAxNy02YWE3MWQ1Yi1hYWFhLWJiYmItY2NjYy1hZmNmMGQyMjgwMnoK\n' ) actual = formatters.email_batch(self.messages, self.verbose_recipient) self.assertEqual(expected, actual)
def test_single_message(self): """Assert if the batch is of length one, it's the same as a plain email.""" self.assertEqual( formatters.email(self.messages[0], self.verbose_recipient), formatters.email_batch([self.messages[0]], self.verbose_recipient), )