<commit_before>from twisted.trial.unittest import TestCase

from axiom.store import Store

from bdm.main import Donation
from bdm.resource import DonationAPI


class TestDonationAPI(TestCase):
    """
    Tests for L{bdm.resource.DonationAPI}.
    """<commit_msg>Add test for serverStats.<commit_after>from twisted.trial.unittest import TestCase

from axiom.store import Store

from bdm.main import Donation
from bdm.resource import DonationAPI


class TestDonationAPI(TestCase):
    """
    Tests for L{bdm.resource.DonationAPI}.
    """
    def setUp(self):
        self.store = Store()
        self.api = DonationAPI(self.store, 'nothing')


    def test_serverStats(self):
        def _cb(result):
            self.assertEqual([{
                'server_name': '<NAME>',
                'map': 'testmap',
                'player_count': 8,
                'max_players': 16
            }], result)

        servers = [
            ['1.1.1.1', 27015]
        ]

        return self.api.serverStats(servers, querier=MockServerQuerier).addCallback(_cb)



class MockServerQuerier(object):
    def __init__(self, address, timeout=5.0):
        self.host = address[0]
        self.port = address[1]
        self.timeout = timeout


    def get_info(self):
        return {
            'server_name': '<NAME>',
            'map': 'testmap',
            'player_count': 8,
            'max_players': 16
        }
{'fraction_non_alphanumeric': 0.11426543647977289, 'fraction_numerical': 0.0134847409510291, 'mean_word_length': 2.25635103926097, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4479275', 'n_tokens_mistral': 446, 'n_tokens_neox': 420, 'n_words': 95}