예제 #1
0
    def test_unparsable_body(self):
        """Assert the message JSON is sent if the long form fails."""
        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: jcline\n'
            'X-Fedmsg-Num-Packages: 0\n'
            'Subject: jcline updated the rules on a fmn email filter\n'
            'MIME-Version: 1.0\n'
            'Content-Type: text/plain; charset="utf-8"\n'
            'Content-Transfer-Encoding: base64\n\n'
            'Tm90aWZpY2F0aW9uIHRpbWUgc3RhbXBlZCAyMDE3LTEwLTA2IDE3OjI1OjMwIFVUQwoKewogICAg\n'
            'Im1zZyI6IHsKICAgICAgICAiY2hhbmdlZCI6ICJydWxlcyIsCiAgICAgICAgImNvbnRleHQiOiAi\n'
            'ZW1haWwiLAogICAgICAgICJvcGVuaWQiOiAiamNsaW5lLmlkLmZlZG9yYXByb2plY3Qub3JnIgog\n'
            'ICAgfSwKICAgICJtc2dfaWQiOiAiMjAxNy02YWE3MWQ1Yi1mYmU0LTQ5ZTctYWZkZC1hZmNmMGQy\n'
            'MjgwMmIiLAogICAgInRpbWVzdGFtcCI6IDE1MDczMTA3MzAsCiAgICAidG9waWMiOiAib3JnLmZl\n'
            'ZG9yYXByb2plY3QuZGV2LmZtbi5maWx0ZXIudXBkYXRlIiwKICAgICJ1c2VybmFtZSI6ICJ2YWdy\n'
            'YW50Igp9CglodHRwczovL2FwcHMuZmVkb3JhcHJvamVjdC5vcmcvbm90aWZpY2F0aW9ucy8=\n'
        )

        actual = formatters.email(self.message, self.recipient)
        self.assertEqual(expected, actual)
예제 #2
0
    def test_unparsable_body(self):
        """Assert the message JSON is sent of the long form fails."""
        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: jcline\n'
            'X-Fedmsg-Num-Packages: 0\n'
            'Subject: jcline updated the rules on a fmn email filter\n'
            'MIME-Version: 1.0\n'
            'Content-Type: text/plain; charset="utf-8"\n'
            'Content-Transfer-Encoding: base64\n\n'
            'Tm90aWZpY2F0aW9uIHRpbWUgc3RhbXBlZCAyMDE3LTEwLTA2IDE3OjI1OjMwIFVUQwoKewogICAg\n'
            'Im1zZyI6IHsKICAgICAgICAiY2hhbmdlZCI6ICJydWxlcyIsIAogICAgICAgICJjb250ZXh0Ijog\n'
            'ImVtYWlsIiwgCiAgICAgICAgIm9wZW5pZCI6ICJqY2xpbmUuaWQuZmVkb3JhcHJvamVjdC5vcmci\n'
            'CiAgICB9LCAKICAgICJtc2dfaWQiOiAiMjAxNy02YWE3MWQ1Yi1mYmU0LTQ5ZTctYWZkZC1hZmNm\n'
            'MGQyMjgwMmIiLCAKICAgICJ0aW1lc3RhbXAiOiAxNTA3MzEwNzMwLCAKICAgICJ0b3BpYyI6ICJv\n'
            'cmcuZmVkb3JhcHJvamVjdC5kZXYuZm1uLmZpbHRlci51cGRhdGUiLCAKICAgICJ1c2VybmFtZSI6\n'
            'ICJ2YWdyYW50Igp9CglodHRwczovL2FwcHMuZmVkb3JhcHJvamVjdC5vcmcvbm90aWZpY2F0aW9u\n'
            'cy8=\n')

        actual = formatters.email(self.message, self.recipient)
        self.assertEqual(expected, actual)
예제 #3
0
    def test_unparsable_category(self):
        """Assert failing to parse the topic works and just leaves those headers off."""
        expected = (
            'Precedence: Bulk\n'
            'Auto-Submitted: auto-generated\n'
            'From: [email protected]\n'
            'To: [email protected]\n'
            'X-Fedmsg-Topic: so.short\n'
            'X-Fedmsg-Num-Packages: 0\n'
            'Subject: fedmsg notification\n'
            'MIME-Version: 1.0\n'
            'Content-Type: text/plain; charset="utf-8"\n'
            'Content-Transfer-Encoding: base64\n\n'
            'Tm90aWZpY2F0aW9uIHRpbWUgc3RhbXBlZCAyMDE3LTEwLTA2IDE3OjI1OjMwIFVUQwoK\n'
        )
        self.message['topic'] = 'so.short'

        actual = formatters.email(self.message, self.recipient)
        self.assertEqual(expected, actual)
예제 #4
0
    def test_unparsable_link(self):
        """Assert no link is included if none can be derived."""
        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: jcline\n'
            'X-Fedmsg-Num-Packages: 0\n'
            'Subject: jcline updated the rules on a fmn email filter\n'
            'MIME-Version: 1.0\n'
            'Content-Type: text/plain; charset="utf-8"\n'
            'Content-Transfer-Encoding: base64\n\n'
            'Tm90aWZpY2F0aW9uIHRpbWUgc3RhbXBlZCAyMDE3LTEwLTA2IDE3OjI1OjMwIFVUQwoKamNsaW5l\n'
            'IHVwZGF0ZWQgdGhlIHJ1bGVzIG9uIGEgZm1uIGVtYWlsIGZpbHRlcg==\n')

        actual = formatters.email(self.message, self.recipient)
        self.assertEqual(expected, actual)
예제 #5
0
    def test_unparsable_usernames(self):
        """Assert unparsable usernames just exclude that header."""
        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-Num-Packages: 0\n'
            'Subject: jcline updated the rules on a fmn email filter\n'
            'MIME-Version: 1.0\n'
            'Content-Type: text/plain; charset="utf-8"\n'
            'Content-Transfer-Encoding: base64\n\n'
            'Tm90aWZpY2F0aW9uIHRpbWUgc3RhbXBlZCAyMDE3LTEwLTA2IDE3OjI1OjMwIFVUQwoKamNsaW5l\n'
            'IHVwZGF0ZWQgdGhlIHJ1bGVzIG9uIGEgZm1uIGVtYWlsIGZpbHRlcgoJaHR0cHM6Ly9hcHBzLmZl\n'
            'ZG9yYXByb2plY3Qub3JnL25vdGlmaWNhdGlvbnMv\n')

        actual = formatters.email(self.message, self.recipient)
        self.assertEqual(expected, actual)
예제 #6
0
    def test_email_too_big(self):
        """Assert huge single message emails are handled gracefully."""
        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: jcline\n'
            'X-Fedmsg-Num-Packages: 0\n'
            'Subject: jcline updated the rules on a fmn email filter\n'
            'MIME-Version: 1.0\n'
            'Content-Type: text/plain; charset="utf-8"\n'
            'Content-Transfer-Encoding: base64\n\n'
            'VGhpcyBtZXNzYWdlIHdhcyB0b28gbGFyZ2UgdG8gYmUgc2VudCEKVGhlIG1lc3NhZ2UgSUQgd2Fz\n'
            'OiAyMDE3LTZhYTcxZDViLWZiZTQtNDllNy1hZmRkLWFmY2YwZDIyODAyYgoK\n')

        actual = formatters.email(self.message, self.recipient)
        self.assertEqual(expected, actual)
예제 #7
0
    def test_footer(self):
        """Assert no link is included if none can be derived."""
        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: jcline\n'
            'X-Fedmsg-Num-Packages: 0\n'
            'Subject: jcline updated the rules on a fmn email filter\n'
            'MIME-Version: 1.0\n'
            'Content-Type: text/plain; charset="utf-8"\n'
            'Content-Transfer-Encoding: base64\n\n'
            'Tm90aWZpY2F0aW9uIHRpbWUgc3RhbXBlZCAyMDE3LTEwLTA2IDE3OjI1OjMwIFVUQwoKamNsaW5l\n'
            'IHVwZGF0ZWQgdGhlIHJ1bGVzIG9uIGEgZm1uIGVtYWlsIGZpbHRlcgoJaHR0cHM6Ly9hcHBzLmZl\n'
            'ZG9yYXByb2plY3Qub3JnL25vdGlmaWNhdGlvbnMvCgotLQpZb3UgcmVjZWl2ZWQgdGhpcyBtZXNz\n'
            'YWdlIGR1ZSB0byB5b3VyIHByZWZlcmVuY2Ugc2V0dGluZ3MgYXQgCmh0dHA6Ly9sb2NhbGhvc3Q6\n'
            'NTAwMC9qY2xpbmUuaWQuZmVkb3JhcHJvamVjdC5vcmcvZW1haWwvMTE=\n')
        self.recipient['triggered_by_links'] = True

        actual = formatters.email(self.message, self.recipient)
        self.assertEqual(expected, actual)
예제 #8
0
 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),
     )