Spaces:
Sleeping
Sleeping
Download tests/test_vk_counters.py from PRAnalytics/PR_Tool: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/PRAnalytics/PR_Tool/resolve/main/tests/test_vk_counters.py
- Command line
-
hf download hf://spaces/PRAnalytics/PR_Tool/tests/test_vk_counters.py
-
curl -L -o test_vk_counters.py https://huggingface.co/spaces/PRAnalytics/PR_Tool/resolve/main/tests/test_vk_counters.py
1.36 kB
| import unittest | |
| from unittest.mock import Mock, patch | |
| import legacy_parser as engine | |
| class VkCountersTests(unittest.TestCase): | |
| def test_missing_counter_is_not_fabricated_zero(self): | |
| url = 'https://vk.com/wall-123_456' | |
| for field in ({}, {'views': {}}, {'views': None}, {'views': {'count': '100'}}): | |
| with self.subTest(field=field): | |
| post = dict(id=456, owner_id=-123, **field) | |
| response = Mock(status_code=200, json=lambda: {'response': {'items': [post], 'groups': [{'id': 123, 'name': 'Сообщество'}]}}) | |
| with patch.object(engine.requests, 'get', return_value=response): | |
| result = engine.process_vk_batch([(url, -123, '456')]) | |
| self.assertEqual(result[url], ('Сообщество', None)) | |
| def test_real_zero_and_nonzero_are_preserved(self): | |
| url = 'https://vk.com/wall-123_456' | |
| for count in (0, 23000): | |
| post = {'id': 456, 'owner_id': -123, 'views': {'count': count}} | |
| response = Mock(status_code=200, json=lambda: {'response': {'items': [post]}}) | |
| with patch.object(engine.requests, 'get', return_value=response): | |
| result = engine.process_vk_batch([(url, -123, '456')]) | |
| self.assertEqual(result[url][1], count) | |
| if __name__ == '__main__': | |
| unittest.main() | |