def test_platform_data(self):
     """The platform data is correct."""
     expected = {"platform": platform.system(),
                 "platform_version": platform.release(),
                 "platform_arch": platform.machine(),
                 "client_version": clientdefs.VERSION}
     self.assertEqual(urllib.urlencode(expected), platform_data())
    def test_ping_url(self):
        """The PING_URL is BASE_PING_URL plus urlencoded platform data."""
        result = urlparse.urlparse(PING_URL)

        expected_base = urlparse.urljoin(result.scheme + '://' + result.netloc,
                                         result.path)
        self.assertEqual(expected_base, BASE_PING_URL)

        expected_query = dict(urlparse.parse_qsl(result.query))
        expected_query = urllib.urlencode(expected_query)
        self.assertEqual(expected_query, platform_data())
    def test_platform_data_non_ascii(self):
        """The platform data is correct for non ascii values."""
        system = u'Ñandú'
        release = u'ñoño'
        machine = u'rápida'
        version = u'1.2.3-ubuntu♥'

        self.patch(platform, 'system', lambda: system.encode('utf8'))
        self.patch(platform, 'release', lambda: release.encode('utf8'))
        self.patch(platform, 'machine', lambda: machine.encode('utf8'))
        self.patch(clientdefs, 'VERSION', version.encode('utf8'))

        expected = {"platform": system.encode('utf8'),
                    "platform_version": release.encode('utf8'),
                    "platform_arch": machine.encode('utf8'),
                    "client_version": version.encode('utf8')}
        expected = urllib.urlencode(expected)
        self.assertEqual(expected, platform_data())