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()