Пример #1
0
    def test_link_server_error(self):
        config.footprints.append(('my-PC', footprint.footprint()))
        config.titles['my-PC'] = 'My PC'

        domain_config = get_domain_config(None)

        responses.add(responses.POST,
                      "http://api.domain.com/domain/acquire",
                      status=403,
                      body='{"message": "Authentication failed"}',
                      content_type="application/json")

        insider_config = get_insider_config('domain.com', 'http://api.domain.com')
        dns = Dns(insider_config, domain_config, service_config=None, port_mapper=None, local_ip='127.0.0.1')
        with self.assertRaises(Exception) as context:
            result = dns.acquire('*****@*****.**', 'pass1234', 'boris')

        self.assertEquals(context.exception.message, "Authentication failed")

        domain = domain_config.load()
        self.assertIsNone(domain)
Пример #2
0
    def test_link_success(self):
        config.footprints.append(('my-PC', footprint.footprint()))
        config.titles['my-PC'] = 'My PC'
        device_id = id.id()

        domain_config = get_domain_config(None)

        responses.add(responses.POST,
                      "http://api.domain.com/domain/acquire",
                      status=200,
                      body='{"user_domain": "boris", "update_token": "some_update_token"}',
                      content_type="application/json")

        insider_config = get_insider_config('domain.com', 'http://api.domain.com')
        dns = Dns(insider_config, domain_config, service_config=None, port_mapper=None, local_ip='127.0.0.1')
        result = dns.acquire('*****@*****.**', 'pass1234', 'boris')

        self.assertIsNotNone(result)
        self.assertEquals(result.user_domain, "boris")
        self.assertEquals(result.update_token, "some_update_token")

        expected_request_data = {
            "password": "******",
            "email": "*****@*****.**",
            "user_domain": "boris",
            'device_mac_address': device_id.mac_address,
            'device_name': device_id.name,
            'device_title': device_id.title,
        }
        # Need to assert all passed POST parameters
        # self.assertSingleRequest(convertible.to_json(expected_request_data))

        domain = domain_config.load()
        self.assertIsNotNone(domain)
        self.assertEquals(domain.user_domain, "boris")
        self.assertEquals(domain.update_token, "some_update_token")