Skip to content

Commit

Permalink
[pytx] change unittest to pytest (#1690)
Browse files Browse the repository at this point in the history
  • Loading branch information
haianhng31 authored Nov 8, 2024
1 parent ed144f7 commit 65c92ce
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
43 changes: 22 additions & 21 deletions python-threatexchange/threatexchange/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

import os
import unittest
import pytest
import collections.abc

from threatexchange.exchanges.clients.fb_threatexchange.api import ThreatExchangeAPI
Expand All @@ -14,24 +14,25 @@
)


@unittest.skipUnless(
THREAT_EXCHANGE_INTEGRATION_TEST_TOKEN,
"Integration Test requires tokens. Use THREAT_EXCHANGE_INTEGRATION_TEST_TOKEN environment variable.",
@pytest.fixture
def api():
return ThreatExchangeAPI(THREAT_EXCHANGE_INTEGRATION_TEST_TOKEN)


need_token = pytest.mark.skipif(
not THREAT_EXCHANGE_INTEGRATION_TEST_TOKEN,
reason="Integration Test requires tokens. Use THREAT_EXCHANGE_INTEGRATION_TEST_TOKEN environment variable.",
)
class APIIntegrationTest(unittest.TestCase):
def setUp(self):
self.api = ThreatExchangeAPI(THREAT_EXCHANGE_INTEGRATION_TEST_TOKEN)

def test_get_threat_privacy_groups_member(self):
"""
Assumes that the app (if token is provided) will have at least one
privacy group.
"""
response = self.api.get_threat_privacy_groups_member()
self.assertTrue(
isinstance(response, collections.abc.Sequence)
and not isinstance(response, staticmethod),
"API returned something that's not a list!",
)

self.assertTrue(isinstance(response[0], ThreatPrivacyGroup))


@need_token
def test_get_threat_privacy_groups_member(api):
"""
Assumes that the app (if token is provided) will have at least one
privacy group.
"""
response = api.get_threat_privacy_groups_member()
assert isinstance(response, collections.abc.Sequence) and not isinstance(
response, (str, bytes)
), "API returned something that's not a list!"
assert isinstance(response[0], ThreatPrivacyGroup)
7 changes: 2 additions & 5 deletions python-threatexchange/threatexchange/tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

import unittest

import threatexchange.common


class TestCommon(unittest.TestCase):
def test_camel_case_to_underscore(self):
assert threatexchange.common.camel_case_to_underscore("AbcXyz") == "abc_xyz"
def test_camel_case_to_underscore():
assert threatexchange.common.camel_case_to_underscore("AbcXyz") == "abc_xyz"

0 comments on commit 65c92ce

Please sign in to comment.