class TestBlacklistCache(TestCase):
    def setUp(self):
        self.client = mock_strict_redis_client()
        self.cache = BlacklistCache(self.client)

    @patch('redis.StrictRedis', mock_strict_redis_client)
    def test_blacklist_is_updated_with_new_word(self):
        text = "new info"
        key_name = "my script"
        self.cache.key_name = Mock(return_value=key_name)
        self.cache.encoder = Encoder()

        self.cache.add_to_blacklist(text)
        self.assertTrue(self.client.sismember(key_name, "a3e8c519de8eedc62d52727c059053e2"))

    @patch('redis.StrictRedis', mock_strict_redis_client)
    def test_blacklist_is_not_updated_without_text(self):
        text = None
        key_name = "my script"
        self.cache.key_name = Mock(return_value=key_name)
        self.cache.encoder = Encoder()

        self.assertRaises(AssertionError, self.cache.add_to_blacklist, text)

    def test_that_key_name_is_blacklist(self):
        self.assertEquals(self.cache.key_name(), "ureport-high-priority-blacklist")
Exemple #2
0
def add_to_blacklist():
    "curl -i -X POST -d 'text=example_text' http://127.0.0.1:5000/add_to_blacklist"
    if request.form['text']:
        client = get_redis_client()
        blacklist_cache = BlacklistCache(client)
        blacklist_cache.add_to_blacklist(request.form['text'])
        return "Successfully added to blacklist"
    else:
        return "None text found"
class TestBlacklistCache(TestCase):
    def setUp(self):
        self.client = mock_strict_redis_client()
        self.cache = BlacklistCache(self.client)

    @patch('redis.StrictRedis', mock_strict_redis_client)
    def test_blacklist_is_updated_with_new_word(self):
        text = "new info"
        key_name = "my script"
        self.cache.key_name = Mock(return_value=key_name)
        encoder_mock = Mock()
        encoder_mock.encode.return_value="encrypted_value"
        self.cache.encoder = encoder_mock

        self.cache.add_to_blacklist(text)
        self.assertTrue(self.client.sismember(key_name, "encrypted_value"))

    def test_that_key_name_is_blacklist(self):
        self.assertEquals(self.cache.key_name(), "ureport-high-priority-blacklist")
 def setUp(self):
     self.client = mock_strict_redis_client()
     self.cache = BlacklistCache(self.client)