Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[auth] Added new widget ui
  • Loading branch information
elpaso committed Sep 29, 2017
1 parent 91d7a9b commit db0c223
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 12 deletions.
40 changes: 40 additions & 0 deletions python/gui/auth/qgsauthenticationwidget.sip
@@ -0,0 +1,40 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/auth/qgsauthenticationwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsAuthenticationWidget : QWidget
{
%Docstring
Widget for entering authentication credentials both in the form username/password
and by using QGIS Authentication Database and its authentication configurations.
%End

%TypeHeaderCode
#include "qgsauthenticationwidget.h"
%End
public:

explicit QgsAuthenticationWidget( QWidget *parent /TransferThis/ = 0, const QString &dataprovider = QString() );
%Docstring
Create a dialog for setting an associated authentication config, either
from existing configs, or creating/removing them from auth database
\param parent Parent widget
\param dataprovider The key of the calling layer provider, if applicable
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/auth/qgsauthenticationwidget.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions src/gui/auth/qgsauthenticationwidget.cpp
Expand Up @@ -19,4 +19,5 @@ QgsAuthenticationWidget::QgsAuthenticationWidget( QWidget *parent, const QString
: QWidget( parent )
{
setupUi( new QgsAuthConfigSelect( this, dataprovider ) );
mAuthConfigSelect->hide();
}
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<height>304</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -29,7 +29,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tabConfigurations">
<attribute name="title">
Expand All @@ -47,9 +47,9 @@
</widget>
</item>
<item>
<widget class="QgsAuthConfigSelect" name="mAuthConfigSelect" native="true">
<widget class="QgsAuthConfigSelect" name="mAuthConfigSelect">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand Down Expand Up @@ -135,7 +135,7 @@
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Password</string>
<string>Passwor&amp;d</string>
</property>
<property name="buddy">
<cstring>txtPassword</cstring>
Expand Down Expand Up @@ -188,9 +188,8 @@
</customwidget>
<customwidget>
<class>QgsAuthConfigSelect</class>
<extends>QWidget</extends>
<header location="global">qgsauthconfigselect.h</header>
<container>1</container>
<extends>QLineEdit</extends>
<header>qgsauthconfigselect.h</header>
</customwidget>
</customwidgets>
<resources/>
Expand Down
1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Expand Up @@ -182,6 +182,7 @@ ADD_PYTHON_TEST(PyQgsSettings test_qgssettings.py)
ADD_PYTHON_TEST(PyQgsZipUtils test_qgsziputils.py)
ADD_PYTHON_TEST(PyQgsSourceSelectProvider test_qgssourceselectprovider.py)
ADD_PYTHON_TEST(PyQgsAuthManagerProxy test_authmanager_proxy.py)
ADD_PYTHON_TEST(PyQgsAuthenticationWidget test_authenticationwidget.py)

IF (NOT WIN32)
ADD_PYTHON_TEST(PyQgsLogger test_qgslogger.py)
Expand Down
83 changes: 83 additions & 0 deletions tests/src/python/test_authenticationwidget.py
@@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
"""
Tests for authentication widget
From build dir, run from test directory:
LC_ALL=en_US.UTF-8 ctest -R PyQgsAuthenticationWidget -V
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
import os
import re
import string
import sys
from shutil import rmtree
import tempfile
import random

from qgis.core import QgsAuthManager, QgsAuthMethodConfig, QgsNetworkAccessManager, QgsSettings
from qgis.gui import QgsAuthenticationWidget
from qgis.testing import start_app, unittest

from utilities import unitTestDataPath

__author__ = 'Alessandro Pasotti'
__date__ = '27/09/2017'
__copyright__ = 'Copyright 2017, The QGIS Project'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'


QGIS_AUTH_DB_DIR_PATH = tempfile.mkdtemp()

os.environ['QGIS_AUTH_DB_DIR_PATH'] = QGIS_AUTH_DB_DIR_PATH

qgis_app = start_app()


class TestAuthenticationWidget(unittest.TestCase):

@classmethod
def setUpClass(cls):
"""Run before all tests:
Creates an auth configuration"""
# Enable auth
# os.environ['QGIS_AUTH_PASSWORD_FILE'] = QGIS_AUTH_PASSWORD_FILE
authm = QgsAuthManager.instance()
assert (authm.setMasterPassword('masterpassword', True))
cls.auth_config = QgsAuthMethodConfig('Basic')
cls.auth_config.setName('test_auth_config')
cls.username = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(6))
cls.password = cls.username[::-1] # reversed
cls.auth_config.setConfig('username', cls.username)
cls.auth_config.setConfig('password', cls.password)
assert (authm.storeAuthenticationConfig(cls.auth_config)[0])

@classmethod
def tearDownClass(cls):
"""Run after all tests"""
rmtree(QGIS_AUTH_DB_DIR_PATH)

def setUp(self):
"""Run before each test."""
pass

def tearDown(self):
"""Run after each test."""
pass

def testWidget(self):
"""
Test the widget
"""
w = QgsAuthenticationWidget()
w.show()
from IPython import embed
embed()


if __name__ == '__main__':
unittest.main()
4 changes: 0 additions & 4 deletions tests/src/python/test_authmanager_proxy.py
Expand Up @@ -14,16 +14,13 @@
import re
import string
import sys
from functools import partial
from shutil import rmtree
import tempfile
import random

from qgis.core import QgsAuthManager, QgsAuthMethodConfig, QgsNetworkAccessManager, QgsSettings
from qgis.testing import start_app, unittest

from utilities import unitTestDataPath, waitServer

__author__ = 'Alessandro Pasotti'
__date__ = '27/09/2017'
__copyright__ = 'Copyright 2017, The QGIS Project'
Expand All @@ -44,7 +41,6 @@ class TestAuthManager(unittest.TestCase):
def setUpClass(cls):
"""Run before all tests:
Creates an auth configuration"""
cls.testdata_path = unitTestDataPath('qgis_server') + '/'
# Enable auth
# os.environ['QGIS_AUTH_PASSWORD_FILE'] = QGIS_AUTH_PASSWORD_FILE
authm = QgsAuthManager.instance()
Expand Down

0 comments on commit db0c223

Please sign in to comment.