Exemplo n.º 1
0
 def setUp(self):
     self.config_file_name = 'tests/config.ini'
     self.connector = Connector(config_file_name=self.config_file_name)
     Installer(connector=self.connector, overwrite=True)
     self.client = Client(connector=self.connector)
     self.client.user_manager.sign_in('administrator', 'admin')
     self.test_user = self.client.user_manager.create_user('jack', 'pass', '*****@*****.**', 'Jack', 'Black')
     self.test_user2 = self.client.user_manager.create_user('jessy', 'pass', '*****@*****.**', 'Jessy', 'Kriek')
     self.client.user_manager.sign_out()
Exemplo n.º 2
0
 def test_client(self):
     connector = Connector(config_file_name=self.config_file_name)
     Installer(connector=connector, overwrite=True)
     cl = Client(connector=connector)
     cl.user_manager.user = None
     cl.user_manager._generate_session_data()
     with self.assertRaises(ValueError):
         cl.user = '******'
     with self.assertRaises(ValueError):
         cl.session_data = 'session data'
     with self.assertRaises(ValueError):
         cl.project = 'project'
Exemplo n.º 3
0
 def test_client(self):
     connector = Connector(config_file_name=self.config_file_name)
     Installer(connector=connector, overwrite=True)
     cl = Client(connector=connector)
     cl.user_manager.user = None
     cl.user_manager._generate_session_data()
     with self.assertRaises(ValueError):
         cl.user = '******'
     with self.assertRaises(ValueError):
         cl.session_data = 'session data'
     with self.assertRaises(ValueError):
         cl.project = 'project'
Exemplo n.º 4
0
 def test_kick_off(self):
     self.client.user_manager.sign_in('administrator', 'admin')
     client = Client(connector=self.connector)
     client.user_manager.sign_in('jessy', 'pass')
     client.user_manager.logoff_user(self.test_user)
     self.client.user_manager.logoff_user(self.test_user2)
     client.user_manager.sign_in('jessy', 'pass')
     self.client.user_manager.logoff_all()
Exemplo n.º 5
0
 def test_log_user_info(self):
     self.client.user_manager.sign_in('administrator', 'admin')
     client = Client(connector=self.connector)
     client.user_manager.sign_in('jessy', 'pass')
     self.client.user_manager.log_user_info(self.test_user, True)
     self.client.user_manager.log_user_info(self.test_user2, True)
     client.user_manager.sign_out()
     client.user_manager.sign_in('jack', 'pass')
     self.client.user_manager.log_user_info(self.test_user2, True)
     result = self.client.user_manager.log_user_info('jessy')
     self.assertFalse(result)
     self.client.user_manager.log_signed_in_users(True)
     self.client.user_manager.logoff_all()
Exemplo n.º 6
0
from __future__ import division, print_function
import numpy as np

from BDProjects.Client import Connector, Client

client = Client(Connector(config_file_name='config.ini'))

client.user_manager.sign_in('john_smith', 'secret_password')

project_name = 'Super Project'
project = client.user_manager.project_manager.open_project(project_name)
print(project)

sample = client.user_manager.sample_manager.get_samples(name='SCF343')[0]
tool = client.user_manager.equipment_manager.get_equipment(
    name='Super setup')[0]
measurement_type = client.user_manager.measurement_type_manager.get_measurement_types(
    'IV measurement')[0]

measurement = client.user_manager.measurement_manager.get_measurements(
    name='Test IV measurement')
if measurement:
    measurement = measurement[0]
else:
    measurement = client.user_manager.measurement_manager.create_measurement(
        name='Test IV measurement',
        measurement_type=measurement_type,
        equipment=tool,
        description='Fake measurement for testing')
client.user_manager.measurement_manager.add_sample_to_measurement(
    measurement, sample)
Exemplo n.º 7
0
from __future__ import division, print_function
import time

from BDProjects.Client import Connector, Client

connector = Connector(config_file_name='config.ini')
client = Client(connector=connector)
client.user_manager.sign_in('administrator', 'admin')
client.user_manager.create_user('john_smith', 'secret_password',
                                '*****@*****.**', 'John', 'Smith')
client.user_manager.sign_out()
client.user_manager.sign_in('john_smith', 'secret_password')
client.user_manager.create_user('jack_black', 'secret_password',
                                '*****@*****.**', 'Jack', 'Black')
client.user_manager.sign_out()
client.user_manager.sign_in('administrator', 'admin')
jb_user = client.user_manager.create_user('jack_black', 'secret_password',
                                          '*****@*****.**', 'Jack',
                                          'Black')
client.user_manager.log_opened_sessions()
time.sleep(3)
client.user_manager.log_signed_in_users()
client.user_manager.logoff_all()

client.user_manager.sign_in('john_smith', 'secret_password')
client.user_manager.sign_out()

client.user_manager.sign_in('administrator', 'admin')
client.user_manager.delete_user(jb_user)
client.user_manager.sign_out()
Exemplo n.º 8
0
class TestUserManager(unittest.TestCase):

    def setUp(self):
        self.config_file_name = 'tests/config.ini'
        self.connector = Connector(config_file_name=self.config_file_name)
        Installer(connector=self.connector, overwrite=True)
        self.client = Client(connector=self.connector)
        self.client.user_manager.sign_in('administrator', 'admin')
        self.test_user = self.client.user_manager.create_user('jack', 'pass', '*****@*****.**', 'Jack', 'Black')
        self.test_user2 = self.client.user_manager.create_user('jessy', 'pass', '*****@*****.**', 'Jessy', 'Kriek')
        self.client.user_manager.sign_out()

    def test_administrator(self):
        result = self.client.user_manager.sign_in('administrator', 'admin')
        self.assertTrue(result)
        result = self.client.user_manager.sign_in('administrator', 'admin')
        self.assertFalse(result)
        self.assertTrue(self.client.user_manager.signed_in())
        self.assertTrue(self.client.signed_in())
        self.assertTrue(self.client.user_manager.check_if_user_is_administrator())
        self.assertTrue(self.client.check_if_user_is_administrator())
        roles = self.client.user_manager.user.roles
        match = True
        for role in roles:
            match = match and role.name in ['administrator', 'user']
        self.assertTrue(match)
        self.client.user_manager.sign_out()
        result = self.client.user_manager.sign_in('administrator', 'admin_wrong_password')
        self.assertFalse(result)
        result = self.client.user_manager.sign_in('administrator_wrong_login', 'admin')
        self.assertFalse(result)

    def test_system_user(self):
        result = self.client.user_manager.sign_in('bot', 'None')
        self.assertFalse(result)
        self.assertTrue(self.client.user.login == 'bot')
        self.assertTrue(self.client.user.roles[0].name == 'system')

    def test_create_user(self):
        result = self.client.user_manager.create_user('john', 'pass', '*****@*****.**', 'John', 'Smith')
        self.assertFalse(result)
        self.client.user_manager.sign_in('administrator', 'admin')
        result = self.client.user_manager.create_user('bot', 'pass', '*****@*****.**')
        self.assertFalse(result)
        result = self.client.user_manager.create_user('john', 'pass', '*****@*****.**', 'John', 'Smith')
        self.assertTrue(result)
        result2 = self.client.user_manager.create_user('john', 'pass', '*****@*****.**', 'John', 'Smith')
        self.assertEqual(result, result2)
        self.client.user_manager.sign_out()

    def test_sign_in_sign_out(self):
        result = self.client.user_manager.sign_in('bot', 'None')
        self.assertFalse(result)
        result = self.client.user_manager.sign_in('jack', 'pass')
        self.assertTrue(result)
        self.assertEqual(self.client.user_manager.user.login, 'jack')
        self.client.user_manager.sign_out()
        result = self.client.user_manager.sign_in('jack', 'pass_wrong')
        self.assertFalse(result)
        result = self.client.user_manager.sign_in('jack_wrong', 'pass')
        self.assertFalse(result)
        self.assertEqual(self.client.user_manager.user.login, 'bot')
        result = self.client.user_manager.sign_in('*****@*****.**', 'pass')
        self.assertTrue(result)
        self.assertEqual(self.client.user_manager.user.login, 'jack')

    def test_delete_user(self):
        result = self.client.user_manager.delete_user(self.test_user)
        self.assertFalse(result)
        self.client.user_manager.sign_in('jack', 'pass')
        result = self.client.user_manager.delete_user(self.test_user2)
        self.assertFalse(result)
        result = self.client.user_manager.delete_user('jack')
        self.assertFalse(result)
        result = self.client.user_manager.delete_user(self.test_user)
        self.assertTrue(result)
        result = self.client.user_manager.delete_user(self.test_user)
        self.assertFalse(result)
        self.client.user_manager.sign_in('administrator', 'admin')
        result = self.client.user_manager.delete_user(self.test_user2)
        self.assertTrue(result)
        result = self.client.user_manager.delete_user(self.test_user2)
        self.assertFalse(result)
        self.client.user_manager.sign_out()

    def test_delete_session_data(self):
        self.client.user_manager.sign_in('jack', 'pass')
        result = self.client.user_manager.delete_session_data('jack',
                                                              self.client.user_manager.session_data)
        self.assertFalse(result)
        result = self.client.user_manager.delete_session_data(self.test_user2,
                                                              self.client.user_manager.session_data)
        self.assertFalse(result)
        result = self.client.user_manager.delete_session_data(self.client.user_manager.user,
                                                              self.client.user_manager.session_data)
        self.assertTrue(result)

    def test_close_session(self):
        self.client.user_manager.sign_in('jack', 'pass')
        session = self.client.user_manager.session_data
        self.client.user_manager.sign_out()
        self.client.user_manager.sign_in('jessy', 'pass')
        result = self.client.user_manager.close_session(session)
        self.assertFalse(result)
        result = self.client.user_manager.close_session('jessy')
        self.assertFalse(result)
        self.client.user_manager.sign_out()

    def test_kick_off(self):
        self.client.user_manager.sign_in('administrator', 'admin')
        client = Client(connector=self.connector)
        client.user_manager.sign_in('jessy', 'pass')
        client.user_manager.logoff_user(self.test_user)
        self.client.user_manager.logoff_user(self.test_user2)
        client.user_manager.sign_in('jessy', 'pass')
        self.client.user_manager.logoff_all()

    def test_log_user_info(self):
        self.client.user_manager.sign_in('administrator', 'admin')
        client = Client(connector=self.connector)
        client.user_manager.sign_in('jessy', 'pass')
        self.client.user_manager.log_user_info(self.test_user, True)
        self.client.user_manager.log_user_info(self.test_user2, True)
        client.user_manager.sign_out()
        client.user_manager.sign_in('jack', 'pass')
        self.client.user_manager.log_user_info(self.test_user2, True)
        result = self.client.user_manager.log_user_info('jessy')
        self.assertFalse(result)
        self.client.user_manager.log_signed_in_users(True)
        self.client.user_manager.logoff_all()

    def test_opened_sessions(self):
        result = self.client.user_manager.count_opened_sessions()
        self.assertFalse(result)
        result = self.client.user_manager.opened_sessions()
        self.assertFalse(result)
        self.client.user_manager.sign_in('jack', 'pass')
        result = self.client.user_manager.count_opened_sessions(self.test_user2)
        self.assertFalse(result)
        result = self.client.user_manager.opened_sessions(self.test_user2)
        self.assertFalse(result)
        self.client.user_manager.sign_out()
        self.client.user_manager.sign_in('administrator', 'admin')
        result = self.client.user_manager.count_opened_sessions()
        self.assertTrue(result)
        result = self.client.user_manager.opened_sessions()
        self.assertTrue(result)
        result = self.client.user_manager.count_opened_sessions('jessy')
        self.assertFalse(result)
        result = self.client.user_manager.opened_sessions('jessy')
        self.assertFalse(result)
        self.client.user_manager.log_opened_sessions('jessy')
        self.client.user_manager.sign_out()