Exemplo n.º 1
0
    def test_write_ios_qr_code_as_png(self):
        temp_directory = 'test_temp_directory'
        pyqrcode_png_mock = MagicMock()

        with patch.object(pyqrcode, 'create', return_value=pyqrcode_png_mock):
            wifi_qr_generator = WifiQrGenerator(temp_directory)
            wifi_qr_generator.generate_ios('')

            pyqrcode_png_mock.png.assert_called_once_with(
                os.path.join(temp_directory, 'ios.png'), background=BLACK, module_color=GREY, scale=5)
Exemplo n.º 2
0
    def test_generate_ios_qr_string(self):
        with patch.object(pyqrcode, 'create', return_value=MagicMock()) as pyqrcode_create_mock:
            test_config_uri = 'https://testdomain.fake:443/test.config'

            WifiQrGenerator('').generate_ios(test_config_uri)

            pyqrcode_create_mock.assert_called_once_with(test_config_uri)
Exemplo n.º 3
0
    def test_generate_windows_qr_string(self):
        with patch.object(pyqrcode, 'create', return_value=MagicMock()) as pyqrcode_create_mock:
            test_data = ('test_encryption_method',
                         'test_ssid',
                         'test_passphrase')

            WifiQrGenerator('').generate_windows(*test_data)

            expected_result = WifiQrGenerator.WINDOWS_MAGIC_STRING_TEMPLATE % test_data
            pyqrcode_create_mock.assert_called_once_with(expected_result)
Exemplo n.º 4
0
def update_wifi_information(config):
    passphrase = generate_passphrase(config.passphrase_length)

    ios_config_creator = iOSConfigurationProfileCreator(
        config.config_directory)
    config_filename = ios_config_creator.generate(config.ssid, passphrase,
                                                  config.identifier)
    config_uri = '%s://%s:%d/%s' % (config.public_protocol,
                                    config.public_domain, config.public_port,
                                    config_filename)
    # Is the mime types set correctly?

    wifi_qr_generator = WifiQrGenerator(config.temp_directory)
    wifi_qr_generator.generate_android(config.encryption, config.ssid,
                                       passphrase)
    wifi_qr_generator.generate_windows(config.encryption, config.ssid,
                                       passphrase)
    wifi_qr_generator.generate_ios(config_uri)

    HostapdConfigBuilder('/etc/hostapd/hostapd.conf').generate(
        config.ssid, passphrase)
    hostapd_restart()
    return passphrase
Exemplo n.º 5
0
 def test_store_temp_directory_in_constructor(self):
     temp_directory = 'test_temp_directory'
     wifi_qr_generator = WifiQrGenerator(temp_directory)
     assert wifi_qr_generator.temp_directory == temp_directory, 'It should store the temp-directory'