From 3b50c4f49d44b1b82de4e4e1b65f1d20da8b91da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Tue, 7 Apr 2020 20:26:12 +0200 Subject: [PATCH] add tests for "Extractors" in oauth.py (#670) --- test/test_extractor.py | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/test_extractor.py b/test/test_extractor.py index e163b936..8afa6e3f 100644 --- a/test/test_extractor.py +++ b/test/test_extractor.py @@ -234,5 +234,52 @@ class TestExtractorWait(unittest.TestCase): return int(parts[0]) * 3600 + int(parts[1]) * 60 + int(parts[2]) +class TextExtractorOAuth(unittest.TestCase): + + def test_oauth1(self): + for category in ("flickr", "smugmug", "tumblr"): + extr = extractor.find("oauth:" + category) + + with patch.object(extr, "_oauth1_authorization_flow") as m: + for msg in extr: + pass + self.assertEqual(len(m.mock_calls), 1) + + def test_oauth2(self): + for category in ("deviantart", "reddit"): + extr = extractor.find("oauth:" + category) + + with patch.object(extr, "_oauth2_authorization_code_grant") as m: + for msg in extr: + pass + self.assertEqual(len(m.mock_calls), 1) + + def test_oauth2_mastodon(self): + extr = extractor.find("oauth:mastodon:pawoo.net") + + with patch.object(extr, "_oauth2_authorization_code_grant") as m, \ + patch.object(extr, "_register") as r: + for msg in extr: + pass + self.assertEqual(len(r.mock_calls), 0) + self.assertEqual(len(m.mock_calls), 1) + + def test_oauth2_mastodon_unknown(self): + extr = extractor.find("oauth:mastodon:example.com") + + with patch.object(extr, "_oauth2_authorization_code_grant") as m, \ + patch.object(extr, "_register") as r: + r.return_value = { + "client-id" : "foo", + "client-secret": "bar", + } + + for msg in extr: + pass + + self.assertEqual(len(r.mock_calls), 1) + self.assertEqual(len(m.mock_calls), 1) + + if __name__ == "__main__": unittest.main()