Example #1
0
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientStore(self.mgr, 'default')

        self.default_client = self.clientStore.getDefaultClient()
Example #2
0
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.modules.admin.stores.clients import ClientsStore
        from saas.app.core.stores.client import ClientStore
        from saas.app.core.stores.user import UserStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientsStore(self.mgr, 'default')
        self.cStore = ClientStore(self.mgr, 'default')
        self.userStore = UserStore(self.mgr, 'default')
Example #3
0
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.project.stores.projects import ProjectStore

        mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientStore(mgr, 'default')
        self.projects = ProjectStore(mgr, 'default')

        self.defaultClient = self.clientStore.getDefaultClient()
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.clients.stores.organizations import OrganizationsStore

        self.mgr = ConnectionManager({
            'app.config': '../../etc'
        })
        self.clientStore = ClientStore(self.mgr, 'default')
        self.orgStore = OrganizationsStore(self.mgr, 'default')
        self.client = self.clientStore.getDefaultClient()
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.modules.inventory.stores.facility import FacilityStore
        from saas.app.modules.inventory.stores.locations import LocationStore
        from saas.app.core.stores.client import ClientStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.facilityStore = FacilityStore(self.mgr, 'default')
        self.locationStore = LocationStore(self.mgr, 'default')
        self.clientStore = ClientStore(self.mgr, 'default')
        self.client = self.clientStore.getDefaultClient()
Example #6
0
    def setUp(self):
        self.settings = get_appsettings('testing.ini', name='main')

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientStore(self.mgr, 'default')
        self.defaultClient = self.clientStore.getDefaultClient()

        default_client_id = self.defaultClient[0]

        usersStore = UsersStore(self.mgr, 'default')
        users = usersStore.getAllClientUsers(default_client_id)
        default_user = users[0]
        default_user_email = default_user[2]

        log.warning('email: %s', default_user_email)
        log.warning('client: %s', self.defaultClient[2])

        # self.session = webdriver.Firefox()
        self.session = webdriver.Chrome()
        self.session.get('http://saas.com')

        # set up cookie
        JWT_KEY = self.settings['jwt.secret']
        COOKIE_MAX_AGE = self.settings['cookie.max_age']

        now = time.time()
        created = renewed = accessed = now

        cookie_value = jwt.encode(
            {
                'email': default_user_email,
                'client': default_client_id,
                'iat': created,
                'updated_at': renewed
            },
            key=JWT_KEY,
            algorithm='HS256')

        self.session.add_cookie({
            'name': 'session',
            'value': cookie_value.decode('utf-8'),
            'max_age': COOKIE_MAX_AGE,
            'path': '/',
            'secure': False,
            'samesite': 'Lax'
        })

        # reload page
        self.session.get('http://saas.com')
Example #7
0
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.hr.stores.members import MembersStore
        from saas.app.modules.hr.stores.time_entries import TimeEntriesStore

        self.mgr = ConnectionManager({
            'app.config': '../../etc'
        })
        self.clientStore = ClientStore(self.mgr, 'default')
        self.defaultClient = self.clientStore.getDefaultClient()
        self.mStore = MembersStore(self.mgr, 'default')
        self.store = TimeEntriesStore(self.mgr, 'default')
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.accounting.stores.accounts import AccountsStore
        from saas.app.modules.accounting.stores.groups import GroupStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientStore(self.mgr, 'default')
        self.groupStore = GroupStore(self.mgr, 'default')
        self.accountsStore = AccountsStore(self.mgr, 'default',
                                           self.groupStore)

        self.defaultClient = self.clientStore.getDefaultClient()
Example #9
0
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.purchasing.stores.purchase_order import PurchaseOrderStore
        from saas.app.modules.inventory.stores.facility import FacilityStore
        from saas.app.modules.purchasing.stores.vendors import VendorStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientStore(self.mgr, 'default')
        self.poStore = PurchaseOrderStore(self.mgr, 'default')
        self.facilityStore = FacilityStore(self.mgr, 'default')
        self.vendorStore = VendorStore(self.mgr, 'default')

        self.defaultClient = self.clientStore.getDefaultClient()
class TestAdminUsersStore(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.modules.admin.stores.clients import ClientsStore
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.admin.stores.roles import RolesStore
        from saas.app.modules.admin.stores.users import UsersStore
        from saas.app.core.stores.user import UserStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientsStore = ClientsStore(self.mgr, 'default')
        self.clientStore = ClientStore(self.mgr, 'default')
        self.rolesStore = RolesStore(self.mgr, 'default')
        self.usersStore = UsersStore(self.mgr, 'default')
        self.userStore = UserStore(self.mgr, 'default')

        self.defaultClient = self.clientStore.getDefaultClient()

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_client_get_users(self):
        try:
            client_id = self.defaultClient[0]
            users = self.usersStore.getAllClientUsers(client_id)
        except Exception as e:
            self.fail(e)

    def test_client_get_roles(self):
        try:
            client_id = self.defaultClient[0]
            users = self.usersStore.getAllClientUsers(client_id)
            user_id = users[0][0]
            roles = self.usersStore.clientRoles(client_id, user_id)
        except Exception as e:
            self.fail(e)

    def test_filter_users(self):
        try:
            result = self.usersStore.filter('com')
            self.assertGreater(len(result), 0, '{0}'.format(result))
        except Exception as e:
            self.fail(e)

    def test_client_set_user_active(self):
        client_id = self.defaultClient[0]

        random_name = self.generate_random_str(10)
        user_id = uuid.uuid4()
        email = '{0}@{1}.com'.format(random_name, random_name)
        self.userStore.userAdd(user_id, email, random_name)

        try:
            self.usersStore.client_user_set_active(client_id, user_id, True)
        except Exception as e:
            self.fail(e)
class TestAuthenticatedPage(unittest.TestCase):
    def setUp(self):
        self.settings = get_appsettings('testing.ini', name='main')

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientStore(self.mgr, 'default')
        self.defaultClient = self.clientStore.getDefaultClient()

        default_client_id = self.defaultClient[0]

        usersStore = UsersStore(self.mgr, 'default')
        users = usersStore.getAllClientUsers(default_client_id)
        default_user = users[0]
        default_user_email = default_user[2]

        self.session = self.driver = webdriver.Firefox()
        self.session.get('http://saas.com')

        # set up cookie
        JWT_KEY = self.settings['jwt.secret']
        COOKIE_MAX_AGE = self.settings['cookie.max_age']

        now = time.time()
        created = renewed = accessed = now

        cookie_value = jwt.encode(
            {
                'email': default_user_email,
                'client': default_client_id,
                'iat': created,
                'updated_at': renewed
            },
            key=JWT_KEY,
            algorithm='HS256')

        self.session.add_cookie({
            'name': 'session',
            'value': cookie_value.decode('utf-8'),
            'max_age': COOKIE_MAX_AGE,
            'path': '/',
            'secure': False,
            'samesite': 'Lax'
        })

        # reload page
        self.session.get('http://saas.com')

    def tearDown(self):
        self.driver.close()

    def test_authenticate(self):
        WebDriverWait(self.session, 10).until(
            EC.presence_of_element_located((By.ID, 'nav-user')))

        elem = self.session.find_element_by_id('nav-user')
        self.assertTrue(elem)
Example #12
0
class TestClientStore(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientStore(self.mgr, 'default')

        self.default_client = self.clientStore.getDefaultClient()

    def test_get_default_client(self):
        client = self.clientStore.getDefaultClient()
        self.assertEqual('default', client[2], '{0}'.format(client))

    def test_get_client_by_name(self):
        client = self.clientStore.by_name('deFaUlt')
        self.assertTrue(client, '{0}'.format(client))
Example #13
0
def includeme(config):
    log.info('including: saas.app.core.stores')

    services = get_service(None)
    mgr = services['connection.manager']

    userStore = UserStore(mgr, 'default')
    services['store.user'] = userStore

    clientStore = ClientStore(mgr, 'default')
    services['store.client'] = clientStore
class TestUOMStore(unittest.TestCase):

    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.modules.common.stores.uom import UOMStore
        from saas.app.core.stores.client import ClientStore

        self.mgr = ConnectionManager({
            'app.config': '../../etc'
        })
        self.uomStore = UOMStore(self.mgr, 'default')
        self.clientStore = ClientStore(self.mgr, 'default')

        self.defaultClient = self.clientStore.getDefaultClient()

    def test_uom_length(self):
        result = self.uomStore.length()
        self.assertGreater(len(result), 0)

    def test_uom_area(self):
        result = self.uomStore.area()
        self.assertGreater(len(result), 0)

    def test_uom_volume(self):
        result = self.uomStore.volume()
        self.assertGreater(len(result), 0)

    def test_uom_weight(self):
        result = self.uomStore.weight()
        self.assertGreater(len(result), 0)
    
    def test_uom_quantity(self):
        result = self.uomStore.quantity()
        self.assertGreater(len(result), 0)

    def test_uom_all(self):
        result = self.uomStore.all()
        self.assertGreater(len(result), 0)

    def test_uom_filter(self):
        client_id = self.defaultClient[0]
        result = self.uomStore.filter(client_id, 'length', '')
        self.assertGreater(len(result), 0, '{0}'.format(result))

    def test_uom_get(self):
        client_id = self.defaultClient[0]
        result = self.uomStore.filter(client_id, 'length', '')
        result = self.uomStore.get(client_id, 'length', result[0][0])
        self.assertGreater(len(result), 0, '{0}'.format(result))
Example #15
0
class TestHRShiftsStore(unittest.TestCase):

    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.modules.hr.stores.shifts import ShiftsStore
        from saas.app.core.stores.client import ClientStore

        self.mgr = ConnectionManager({
            'app.config': '../../etc'
        })
        self.store = ShiftsStore(self.mgr, 'default')
        self.clientStore = ClientStore(self.mgr, 'default')
        self.defaultClient = self.clientStore.getDefaultClient()

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_save(self):
        random_str = self.generate_random_str(10)
        shift_id = str(uuid.uuid4())
        self.store.save(self.defaultClient[0], shift_id, random_str, datetime.time(8), datetime.time(12))

    def test_all(self):
        random_str = self.generate_random_str(10)
        shift_id = str(uuid.uuid4())
        self.store.save(self.defaultClient[0], shift_id, random_str, datetime.time(8), datetime.time(12))
        result = self.store.all(self.defaultClient[0])
        self.assertGreater(len(result), 0, '{0}'.format(result))

    def test_filter(self):
        random_str = self.generate_random_str(10)
        shift_id = str(uuid.uuid4())
        self.store.save(self.defaultClient[0], shift_id, random_str, datetime.time(8), datetime.time(12))
        result = self.store.filter(self.defaultClient[0], random_str[2:8])
        self.assertGreater(len(result), 0, '{0}'.format(result))
Example #16
0
class TestAdminClientStore(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.modules.admin.stores.clients import ClientsStore
        from saas.app.core.stores.client import ClientStore
        from saas.app.core.stores.user import UserStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientsStore(self.mgr, 'default')
        self.cStore = ClientStore(self.mgr, 'default')
        self.userStore = UserStore(self.mgr, 'default')

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_get_all_clients(self):
        result = self.clientStore.getAll()
        self.assertNotEqual(0, len(result), '{0}'.format(result))

    def test_add_client(self):
        random_name = self.generate_random_str(10)
        client_id = str(uuid.uuid4())
        country_id = 608  # philippines
        currency_id = 108  # philippine peso
        try:
            self.clientStore.add(client_id, random_name, random_name,
                                 country_id, currency_id)
        except Exception as e:
            self.fail(e)

    def test_update_client(self):
        random_name = self.generate_random_str(10)
        client_id = str(uuid.uuid4())
        country_id = 608  # philippines
        currency_id = 108  # philippine peso
        try:
            self.clientStore.add(client_id, random_name, random_name,
                                 country_id, currency_id)
            self.clientStore.update(client_id, random_name, random_name,
                                    country_id, currency_id)
        except Exception as e:
            self.fail(e)

    def test_add_client_not_unique(self):
        random_name = self.generate_random_str(10)
        client_id = str(uuid.uuid4())
        country_id = 608  # philippines
        currency_id = 108  # philippine peso
        self.clientStore.add(client_id, random_name, random_name, country_id,
                             currency_id)
        client_id2 = str(uuid.uuid4())
        self.assertRaises(Exception, self.clientStore.add, client_id2,
                          random_name, random_name, random_name, country_id,
                          currency_id)

    def test_get_client(self):
        random_name = self.generate_random_str(10)
        client_id = str(uuid.uuid4())
        country_id = 608  # philippines
        currency_id = 108  # philippine peso
        self.clientStore.add(client_id, random_name, random_name, country_id,
                             currency_id)
        try:
            client = self.clientStore.get(client_id)
            self.assertEqual(client_id, client[0], '{0}'.format(client))
        except Exception as e:
            self.fail(e)

    def test_set_active(self):
        random_name = self.generate_random_str(10)
        client_id = str(uuid.uuid4())
        country_id = 608  # philippines
        currency_id = 108  # philippine peso
        self.clientStore.add(client_id, random_name, random_name, country_id,
                             currency_id)
        try:
            self.clientStore.setActive(client_id, False)
        except Exception as e:
            self.fail(e)

    def test_filter(self):
        try:
            result = self.clientStore.filter('defau')
            self.assertGreater(len(result), 0)
        except Exception as e:
            self.fail(e)

    def test_client_join(self) -> None:
        random_name = self.generate_random_str(10)
        client_id = str(uuid.uuid4())
        country_id = 608  # philippines
        currency_id = 108  # philippine peso
        self.clientStore.add(client_id, random_name, random_name, country_id,
                             currency_id)

        random_name = self.generate_random_str(10)
        user_id = uuid.uuid4()
        email = '{0}@{1}.com'.format(random_name, random_name)
        self.userStore.userAdd(user_id, email, random_name)

        try:
            self.cStore.join(client_id, user_id)
        except Exception as e:
            self.fail(e)
class TestAdminRolesStore(unittest.TestCase):

    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.modules.admin.stores.clients import ClientsStore
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.admin.stores.roles import RolesStore

        self.mgr = ConnectionManager({
            'app.config': '../../etc'
        })
        self.clientsStore = ClientsStore(self.mgr, 'default')
        self.clientStore = ClientStore(self.mgr, 'default')
        self.rolesStore = RolesStore(self.mgr, 'default')
        self.client = self.clientStore.getDefaultClient()

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_get_all_roles(self):
        client_id = self.client[0]
        try:
            result = self.rolesStore.getAll(client_id)
        except Exception as e:
            self.fail(e)

    def test_add_role(self):
        client_id = self.client[0]
        try:
            role_id = uuid.uuid4()
            random_name = self.generate_random_str(10)
            self.rolesStore.add(client_id, role_id, random_name)
        except Exception as e:
            self.fail(e)

    def test_add_role_not_unique(self):
        client_id = self.client[0]
        role_id1 = uuid.uuid4()
        role_id2 = uuid.uuid4()
        random_name = self.generate_random_str(10)
        self.rolesStore.add(client_id, role_id1, random_name)
        self.assertRaises(
            Exception,
            self.rolesStore.add,
            client_id,
            role_id2,
            random_name
        )

    def test_set_active_role(self):
        client_id = self.client[0]
        role_id = str(uuid.uuid4())
        random_name = self.generate_random_str(10)
        try:
            self.rolesStore.add(client_id, role_id, random_name)
            self.rolesStore.setActive(role_id, False)
        except Exception as e:
            self.fail(e)

    def test_role_filter(self):
        client_id = self.client[0]
        try:
            result = self.rolesStore.filter(client_id, 'every')
            self.assertGreater(len(result), 0, '{0}'.format(result))
        except Exception as e:
            self.fail(e)
Example #18
0
class TestAdminModulePage(unittest.TestCase):
    def setUp(self):
        self.settings = get_appsettings('testing.ini', name='main')

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientStore(self.mgr, 'default')
        self.defaultClient = self.clientStore.getDefaultClient()

        default_client_id = self.defaultClient[0]

        usersStore = UsersStore(self.mgr, 'default')
        users = usersStore.getAllClientUsers(default_client_id)
        default_user = users[0]
        default_user_email = default_user[2]

        log.warning('email: %s', default_user_email)
        log.warning('client: %s', self.defaultClient[2])

        # self.session = webdriver.Firefox()
        self.session = webdriver.Chrome()
        self.session.get('http://saas.com')

        # set up cookie
        JWT_KEY = self.settings['jwt.secret']
        COOKIE_MAX_AGE = self.settings['cookie.max_age']

        now = time.time()
        created = renewed = accessed = now

        cookie_value = jwt.encode(
            {
                'email': default_user_email,
                'client': default_client_id,
                'iat': created,
                'updated_at': renewed
            },
            key=JWT_KEY,
            algorithm='HS256')

        self.session.add_cookie({
            'name': 'session',
            'value': cookie_value.decode('utf-8'),
            'max_age': COOKIE_MAX_AGE,
            'path': '/',
            'secure': False,
            'samesite': 'Lax'
        })

        # reload page
        self.session.get('http://saas.com')

    def tearDown(self):
        self.session.close()

    def get_shadow_root(self, element):
        # element = self.session.find_element_by_css_selector(selector)
        return self.session.execute_script('return arguments[0].shadowRoot;',
                                           element)

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_add_client(self):
        WebDriverWait(self.session, 10).until(
            EC.presence_of_element_located((By.ID, 'nav-admin')))

        elem = self.session.find_element_by_id('nav-admin')
        elem.click()

        elem = self.session.find_element_by_css_selector(
            '[data-action="admin.clients"]')
        elem.click()

        tab = self.get_shadow_root(
            self.session.find_element_by_css_selector('tab-container'))

        clients_table = tab.find_element_by_css_selector('clients-table')
        sr = self.get_shadow_root(clients_table)
        btn = sr.find_element_by_id('btn-new')
        btn.click()

        client_editor = tab.find_element_by_css_selector('client-editor')
        sr = self.get_shadow_root(client_editor)
        random_str = self.generate_random_str(10)

        input_name = sr.find_element_by_id('name')
        input_name.send_keys(random_str)

        input_address = sr.find_element_by_id('address')
        input_address.send_keys(random_str)

        btn_save = sr.find_element_by_id('btn-save')
        btn_save.click()

        notifier = self.get_shadow_root(
            self.session.find_element_by_css_selector('notification-list'))
        try:
            elem = WebDriverWait(self.session, 10).until(
                lambda notifier: notifier.find_element_by_css_selector(
                    '.notification .is-success'))
            self.assertTrue(elem)
        except Exception as e:
            self.fail(e)
Example #19
0
class TestPurchasingVendorStore(unittest.TestCase):

    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.purchasing.stores.vendors import VendorStore
        from saas.app.modules.crm.stores.organizations import OrganizationStore

        self.mgr = ConnectionManager({
            'app.config': '../../etc'
        })
        self.clientStore = ClientStore(self.mgr, 'default')
        self.defaultClient = self.clientStore.getDefaultClient()
        self.vStore = VendorStore(self.mgr, 'default')
        self.orgStore = OrganizationStore(self.mgr, 'default')

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_add(self):
        client_id = self.defaultClient[0]
        random_str = self.generate_random_str(10)
        vendor_id = str(uuid.uuid4())
        try:
            self.vStore.add(client_id, vendor_id, random_str, random_str, 1)
        except Exception as e:
            self.fail(e)

    def test_update(self):
        client_id = self.defaultClient[0]
        random_str = self.generate_random_str(10)
        vendor_id = str(uuid.uuid4())
        try:
            self.vStore.add(client_id, vendor_id, random_str, random_str, 1)
            random_str = self.generate_random_str(10)
            self.vStore.update(client_id, vendor_id, random_str, random_str, 608)
        except Exception as e:
            self.fail(e)


    def test_assign_organization(self):
        client_id = self.defaultClient[0]
        random_str = self.generate_random_str(10)
        vendor_id = str(uuid.uuid4())
        organization_id = str(uuid.uuid4())
        try:
            self.orgStore.save(client_id, organization_id, random_str, random_str, 608)
            self.vStore.assignOrganization(client_id, vendor_id, organization_id)
        except Exception as e:
            self.fail(e)


    def test_filter(self):
        client_id = self.defaultClient[0]
        random_str = self.generate_random_str(10)
        org_id = str(uuid.uuid4())
        try:
            self.vStore.add(client_id, org_id, random_str, random_str, 1)
            result = self.vStore.filter(client_id, '')
            self.assertGreater(len(result), 0, '{0}'.format(result))
        except Exception as e:
            self.fail(e)

    def test_get(self):
        client_id = self.defaultClient[0]
        random_str = self.generate_random_str(10)
        org_id = str(uuid.uuid4())
        try:
            self.vStore.add(client_id, org_id, random_str, random_str, 1)
            result = self.vStore.get(client_id, org_id)
            self.assertEqual(result[0], org_id, '{0}'.format(result))
        except Exception as e:
            self.fail(e)
Example #20
0
class TestOrganizationStore(unittest.TestCase):

    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.crm.stores.organizations import OrganizationStore

        self.mgr = ConnectionManager({
            'app.config': '../../etc'
        })
        self.clientStore = ClientStore(self.mgr, 'default')
        self.orgStore = OrganizationStore(self.mgr, 'default')

        self.defaultClient = self.clientStore.getDefaultClient()

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_save(self):
        client_id = self.defaultClient[0]
        country_id = self.defaultClient[4]
        org_id = str(uuid.uuid4())
        random_str = self.generate_random_str(10)
        self.orgStore.save(
            client_id,
            org_id,
            random_str,
            random_str,
            country_id
        )

    def test_filter(self):
        client_id = self.defaultClient[0]
        country_id = self.defaultClient[4]
        org_id = str(uuid.uuid4())
        random_str = self.generate_random_str(10)
        self.orgStore.save(
            client_id,
            org_id,
            random_str,
            random_str,
            country_id
        )
        try:
            result = self.orgStore.filter(client_id, random_str[2:5])
            self.assertGreater(len(result), 0, '{0}'.format(result))
        except Exception as e:
            self.fail(e)

    def test_get(self):
        client_id = self.defaultClient[0]
        country_id = self.defaultClient[4]
        org_id = str(uuid.uuid4())
        random_str = self.generate_random_str(10)
        self.orgStore.save(
            client_id,
            org_id,
            random_str,
            random_str,
            country_id
        )
        try:
            result = self.orgStore.get(client_id, org_id)
            self.assertEqual(result[0], org_id, '{0}'.format(result))
        except Exception as e:
            self.fail(e)
class TestTransactionStore(unittest.TestCase):

    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.accounting.stores.accounts import AccountsStore
        from saas.app.modules.accounting.stores.groups import GroupStore
        from saas.app.modules.accounting.stores.transactions import TransactionStore

        self.mgr = ConnectionManager({
            'app.config': '../../etc'
        })
        self.clientStore = ClientStore(self.mgr, 'default')
        self.groupStore = GroupStore(self.mgr, 'default')
        self.accountsStore = AccountsStore(self.mgr, 'default', self.groupStore)
        self.transactionStore = TransactionStore(self.mgr, 'default')

        self.defaultClient = self.clientStore.getDefaultClient()
    
    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_transaction_add(self):
        client_id = self.defaultClient[0]
        transaction_id = str(uuid.uuid4())
        currency_id = self.defaultClient[5]
        description = self.generate_random_str(10)

        account_id_1 = str(uuid.uuid4())
        account_id_2 = str(uuid.uuid4())

        account_name_1 = self.generate_random_str(10)
        account_name_2 = self.generate_random_str(10)

        self.accountsStore.add(client_id, account_id_1, AccountTypes.ASSETS, account_name_1, account_name_1)
        self.accountsStore.add(client_id, account_id_2, AccountTypes.ASSETS, account_name_2, account_name_2)

        transaction = {
            'clientId': client_id,
            'transactionId': transaction_id,
            'description': description,
            'currencyId': currency_id,
            'entries': [
                {
                    'id': str(uuid.uuid4()),
                    'accountId': account_id_1,
                    'debit': 100,
                    'credit': 0
                },
                {
                    'id': str(uuid.uuid4()),
                    'accountId': account_id_2,
                    'debit': 0,
                    'credit': 100
                }
            ],
            'attachments': [
                {
                    'id': str(uuid.uuid4()),
                    'filename': f'{account_name_1}.pdf',
                    'type': 'document/pdf',
                    'size': '100',
                    'data': '1234567890'
                }
            ]
        }

        try:
            self.transactionStore.add(transaction)
        except Exception as e:
            self.fail(e)

    def test_transaction_update(self):
        client_id = self.defaultClient[0]
        transaction_id = str(uuid.uuid4())
        currency_id = self.defaultClient[5]
        description = self.generate_random_str(10)

        account_id_1 = str(uuid.uuid4())
        account_id_2 = str(uuid.uuid4())

        account_name_1 = self.generate_random_str(10)
        account_name_2 = self.generate_random_str(10)

        self.accountsStore.add(client_id, account_id_1, AccountTypes.ASSETS, account_name_1, account_name_1)
        self.accountsStore.add(client_id, account_id_2, AccountTypes.ASSETS, account_name_2, account_name_2)

        transaction = {
            'clientId': client_id,
            'transactionId': transaction_id,
            'description': description,
            'currencyId': currency_id,
            'entries': [
                {
                    'id': str(uuid.uuid4()),
                    'accountId': account_id_1,
                    'debit': 100,
                    'credit': 0,
                    'status': 'update'
                },
                {
                    'id': str(uuid.uuid4()),
                    'accountId': account_id_2,
                    'debit': 0,
                    'credit': 100,
                    'status': 'update'
                }
            ],
            'attachments': [
                {
                    'id': str(uuid.uuid4()),
                    'filename': f'{account_name_1}.pdf',
                    'type': 'document/pdf',
                    'size': '100',
                    'data': '1234567890',
                    'status': 'update'
                }
            ]
        }


        self.transactionStore.add(transaction)
        transaction['description'] = self.generate_random_str(10)

        try:
            self.transactionStore.update(transaction)
        except Exception as e:
            self.fail(e)

    def test_transaction_get(self):
        client_id = self.defaultClient[0]
        transaction_id = str(uuid.uuid4())
        currency_id = self.defaultClient[5]
        description = self.generate_random_str(10)

        account_id_1 = str(uuid.uuid4())
        account_id_2 = str(uuid.uuid4())

        account_name_1 = self.generate_random_str(10)
        account_name_2 = self.generate_random_str(10)

        self.accountsStore.add(client_id, account_id_1, AccountTypes.ASSETS, account_name_1, account_name_1)
        self.accountsStore.add(client_id, account_id_2, AccountTypes.ASSETS, account_name_2, account_name_2)

        transaction = {
            'clientId': client_id,
            'transactionId': transaction_id,
            'description': description,
            'currencyId': currency_id,
            'entries': [
                {
                    'id': str(uuid.uuid4()),
                    'accountId': account_id_1,
                    'debit': 100,
                    'credit': 0,
                    'status': 'update'
                },
                {
                    'id': str(uuid.uuid4()),
                    'accountId': account_id_2,
                    'debit': 0,
                    'credit': 100,
                    'status': 'update'
                }
            ],
            'attachments': [
                {
                    'id': str(uuid.uuid4()),
                    'filename': f'{account_name_1}.pdf',
                    'type': 'document/pdf',
                    'size': '100',
                    'data': '1234567890',
                    'status': 'update'
                }
            ]
        }

        self.transactionStore.add(transaction)

        try:
            result = self.transactionStore.get(client_id, transaction_id)

            self.assertEqual(result['transactionId'], transaction_id, '{0}'.format(result))
        except Exception as e:
            self.fail(e)

    def test_transaction_filter(self):
        client_id = self.defaultClient[0]
        try:
            result = self.transactionStore.filter(client_id, '')
            self.assertGreater(len(result), 0, '{0}'.format(result))
        except Exception as e:
            self.fail(e)

    def test_transaction_post(self):
        client_id = self.defaultClient[0]
        transaction_id = str(uuid.uuid4())
        currency_id = self.defaultClient[5]
        description = self.generate_random_str(10)

        account_id_1 = str(uuid.uuid4())
        account_id_2 = str(uuid.uuid4())

        account_name_1 = self.generate_random_str(10)
        account_name_2 = self.generate_random_str(10)

        self.accountsStore.add(client_id, account_id_1, AccountTypes.ASSETS, account_name_1, account_name_1)
        self.accountsStore.add(client_id, account_id_2, AccountTypes.ASSETS, account_name_2, account_name_2)

        transaction = {
            'clientId': client_id,
            'transactionId': transaction_id,
            'description': description,
            'currencyId': currency_id,
            'entries': [
                {
                    'id': str(uuid.uuid4()),
                    'accountId': account_id_1,
                    'debit': 100,
                    'credit': 0,
                    'status': 'update'
                },
                {
                    'id': str(uuid.uuid4()),
                    'accountId': account_id_2,
                    'debit': 0,
                    'credit': 100,
                    'status': 'update'
                }
            ],
            'attachments': [
                {
                    'id': str(uuid.uuid4()),
                    'filename': f'{account_name_1}.pdf',
                    'type': 'document/pdf',
                    'size': '100',
                    'data': '1234567890',
                    'status': 'update'
                }
            ]
        }

        self.transactionStore.add(transaction)

        try:
            self.transactionStore.post(client_id, transaction_id)
        except Exception as e:
            self.fail(e)
Example #22
0
class TestPurchaseOrderStore(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.purchasing.stores.purchase_order import PurchaseOrderStore
        from saas.app.modules.inventory.stores.facility import FacilityStore
        from saas.app.modules.purchasing.stores.vendors import VendorStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientStore(self.mgr, 'default')
        self.poStore = PurchaseOrderStore(self.mgr, 'default')
        self.facilityStore = FacilityStore(self.mgr, 'default')
        self.vendorStore = VendorStore(self.mgr, 'default')

        self.defaultClient = self.clientStore.getDefaultClient()

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    # def test_save_po(self):
    #     random_str = self.generate_random_str(10)
    #     client_id = self.defaultClient[0]
    #     country_id = self.defaultClient[4]

    #     facility_id = str(uuid.uuid4())
    #     uom_id = 1 #
    #     self.facilityStore.add(
    #         client_id,
    #         facility_id,
    #         random_str,
    #         random_str,
    #         random_str,
    #         country_id,
    #         100,
    #         uom_id
    #     )

    #     vendor_id = str(uuid.uuid4())
    #     vendor = self.vendorStore.add(client_id, vendor_id, random_str, random_str, country_id)

    #     po_id = str(uuid.uuid4())
    #     order = {
    #         'clientId': client_id,
    #         'purchaseOrderId': po_id,
    #         'description': random_str,
    #         'facilityId': facility_id,
    #         'vendorId': vendor_id,
    #         'instructions': random_str,
    #         'items': [
    #             {
    #                 'id': str(uuid.uuid4()),
    #                 'description': random_str,
    #                 'quantity': 1,
    #                 'uom': 1,
    #                 'status': 'new'
    #             }
    #         ]
    #     }
    #     self.poStore.save(order)

    def test_add_po(self):
        random_str = self.generate_random_str(10)
        client_id = self.defaultClient[0]
        country_id = self.defaultClient[4]

        facility_id = str(uuid.uuid4())
        uom_id = 1  #
        self.facilityStore.add(client_id, facility_id, random_str, random_str,
                               random_str, country_id, 100, uom_id)

        vendor_id = str(uuid.uuid4())
        vendor = self.vendorStore.add(client_id, vendor_id, random_str,
                                      random_str, country_id)

        po_id = str(uuid.uuid4())
        order = {
            'clientId':
            client_id,
            'purchaseOrderId':
            po_id,
            'description':
            random_str,
            'facilityId':
            facility_id,
            'vendorId':
            vendor_id,
            'instructions':
            random_str,
            'items': [{
                'id': str(uuid.uuid4()),
                'description': random_str,
                'quantity': 1,
                'uom': 1,
                'status': 'new'
            }]
        }
        self.poStore.add(order)

    def test_update_po(self):
        random_str = self.generate_random_str(10)
        client_id = self.defaultClient[0]
        country_id = self.defaultClient[4]

        facility_id = str(uuid.uuid4())
        uom_id = 1  #
        self.facilityStore.add(client_id, facility_id, random_str, random_str,
                               random_str, country_id, 100, uom_id)

        vendor_id = str(uuid.uuid4())
        vendor = self.vendorStore.add(client_id, vendor_id, random_str,
                                      random_str, country_id)

        po_id = str(uuid.uuid4())
        order = {
            'clientId':
            client_id,
            'purchaseOrderId':
            po_id,
            'description':
            random_str,
            'facilityId':
            facility_id,
            'vendorId':
            vendor_id,
            'instructions':
            random_str,
            'items': [{
                'id': str(uuid.uuid4()),
                'description': random_str,
                'quantity': 1,
                'uom': 1,
                'status': 'new'
            }]
        }
        self.poStore.add(order)

        random_str = self.generate_random_str(10)
        order = {
            'clientId':
            client_id,
            'purchaseOrderId':
            po_id,
            'description':
            random_str,
            'facilityId':
            facility_id,
            'vendorId':
            vendor_id,
            'instructions':
            random_str,
            'items': [{
                'id': str(uuid.uuid4()),
                'description': random_str,
                'quantity': 2,
                'uom': 1,
            }]
        }
        self.poStore.update(order)

    def test_filter_po(self):
        try:
            client_id = self.defaultClient[0]
            country_id = self.defaultClient[4]

            random_str = self.generate_random_str(10)
            facility_id = str(uuid.uuid4())
            uom_id = 1  #
            self.facilityStore.add(client_id, facility_id, random_str,
                                   random_str, random_str, country_id, 100,
                                   uom_id)

            vendor_id = str(uuid.uuid4())
            vendor = self.vendorStore.add(client_id, vendor_id, random_str,
                                          random_str, country_id)

            po_id = str(uuid.uuid4())
            order = {
                'clientId':
                client_id,
                'purchaseOrderId':
                po_id,
                'description':
                random_str,
                'facilityId':
                facility_id,
                'vendorId':
                vendor_id,
                'instructions':
                random_str,
                'items': [{
                    'id': str(uuid.uuid4()),
                    'description': random_str,
                    'quantity': 1,
                    'uom': 1,
                    'status': 'new'
                }]
            }
            self.poStore.add(order)

            result = self.poStore.filter(client_id, '')
            self.assertGreater(len(result), 0, '{0}'.format(result))
        except Exception as e:
            self.fail(e)

    def test_get(self):
        client_id = self.defaultClient[0]
        country_id = self.defaultClient[4]
        random_str = self.generate_random_str(10)

        facility_id = str(uuid.uuid4())
        uom_id = 1
        self.facilityStore.add(client_id, facility_id, random_str, random_str,
                               random_str, country_id, 100, uom_id)

        vendor_id = str(uuid.uuid4())
        vendor = self.vendorStore.add(client_id, vendor_id, random_str,
                                      random_str, country_id)

        po_id = str(uuid.uuid4())

        order = {
            'clientId':
            client_id,
            'purchaseOrderId':
            po_id,
            'description':
            random_str,
            'facilityId':
            facility_id,
            'vendorId':
            vendor_id,
            'instructions':
            random_str,
            'items': [{
                'id': str(uuid.uuid4()),
                'description': random_str,
                'quantity': 1,
                'uom': 1,
                'status': 'new'
            }]
        }
        self.poStore.add(order)
        try:
            result = self.poStore.get(client_id, po_id)
            self.assertEqual(result[0], po_id, '{0}'.format(result))
        except Exception as e:
            self.fail(e)

    def test_get_items(self):
        client_id = self.defaultClient[0]
        country_id = self.defaultClient[4]
        random_str = self.generate_random_str(10)

        facility_id = str(uuid.uuid4())
        uom_id = 1  #
        self.facilityStore.add(client_id, facility_id, random_str, random_str,
                               random_str, country_id, 100, uom_id)

        vendor_id = str(uuid.uuid4())
        vendor = self.vendorStore.add(client_id, vendor_id, random_str,
                                      random_str, country_id)

        po_id = str(uuid.uuid4())
        order = {
            'clientId':
            client_id,
            'purchaseOrderId':
            po_id,
            'description':
            random_str,
            'facilityId':
            facility_id,
            'vendorId':
            vendor_id,
            'instructions':
            random_str,
            'items': [{
                'id': str(uuid.uuid4()),
                'description': random_str,
                'quantity': 1,
                'uom': 1,
                'status': 'new'
            }]
        }
        self.poStore.add(order)
        try:
            result = self.poStore.get_items(client_id, po_id)
            self.assertGreater(len(result), 0, '{0}'.format(result))
        except Exception as e:
            self.fail(e)
Example #23
0
class TestUserStore(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.user import UserStore
        from saas.app.core.stores.client import ClientStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.userStore = UserStore(self.mgr, 'default')
        self.clientStore = ClientStore(self.mgr, 'default')

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_user_add(self):
        random_name = self.generate_random_str(10)
        user_id = uuid.uuid4()
        email = '{0}@{1}.com'.format(random_name, random_name)
        try:
            self.userStore.userAdd(user_id, email, random_name)
        except Exception as e:
            self.fail(e)

    def test_user_add_duplicate(self):
        random_name = self.generate_random_str(10)
        user_id = uuid.uuid4()
        email = '{0}@{1}.com'.format(random_name, random_name)
        self.userStore.userAdd(user_id, email, random_name)
        new_user_id = str(uuid.uuid4())
        self.assertRaises(Exception, self.userStore.userAdd, new_user_id,
                          email, random_name)

    def test_email_exists(self):
        random_name = self.generate_random_str(10)
        user_id = uuid.uuid4()
        email = '{0}@{1}.com'.format(random_name, random_name)
        self.userStore.userAdd(user_id, email, random_name)
        result = self.userStore.emailExists(email)
        self.assertEqual(True, result, '{0}'.format(result))

    def test_user_by_email(self):
        random_name = self.generate_random_str(10)
        user_id = uuid.uuid4()
        email = '{0}@{1}.com'.format(random_name, random_name)
        self.userStore.userAdd(user_id, email, random_name)
        result = self.userStore.userByEmail(email)
        self.assertEqual(email, result[3], '{0}'.format(result))

    def test_user_clients(self):
        random_name = self.generate_random_str(10)
        user_id = uuid.uuid4()
        email = '{0}@{1}.com'.format(random_name, random_name)
        self.userStore.userAdd(user_id, email, random_name)
        clients = self.userStore.userClients(user_id)
        self.assertNotEqual(0, len(clients), '{0}'.format(clients))

    def test_user_has_permission(self):
        random_name = self.generate_random_str(10)
        user_id = uuid.uuid4()
        email = '{0}@{1}.com'.format(random_name, random_name)
        self.userStore.userAdd(user_id, email, random_name)

        client = self.clientStore.getDefaultClient()
        client_id = client[0]

        result = self.userStore.userHasPermission(user_id, client_id,
                                                  'user.authenticated')
        self.assertEqual(True, result, '{0} {1}'.format(result, email))

    def test_user_permissions(self):
        random_name = self.generate_random_str(10)
        user_id = uuid.uuid4()
        email = '{0}@{1}.com'.format(random_name, random_name)
        self.userStore.userAdd(user_id, email, random_name)

        client = self.clientStore.getDefaultClient()
        client_id = client[0]

        result = self.userStore.permissions(client_id, user_id)
        self.assertGreater(len(result), 0, '{0}'.format(result))
class TestInventoryItemsStore(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.modules.inventory.stores.items import ItemsStore
        from saas.app.core.stores.client import ClientStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.itemsStore = ItemsStore(self.mgr, 'default')
        self.clientStore = ClientStore(self.mgr, 'default')
        self.client = self.clientStore.getDefaultClient()

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_item_add(self):
        random_str = self.generate_random_str(10)
        client_id = self.client[0]
        item_id = str(uuid.uuid4())
        try:
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id,
                'name': random_str,
                'description': random_str,
                'make': random_str,
                'brand': random_str,
                'model': random_str,
                'version': random_str,
                'sku': random_str,
                'upc': random_str,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })
        except Exception as e:
            self.fail(e)

    def test_item_get(self):
        random_str = self.generate_random_str(10)
        client_id = self.client[0]
        item_id = str(uuid.uuid4())
        try:
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id,
                'name': random_str,
                'description': random_str,
                'make': random_str,
                'brand': random_str,
                'model': random_str,
                'version': random_str,
                'sku': random_str,
                'upc': random_str,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })
            result = self.itemsStore.get(item_id)
            self.assertEqual(item_id, result[0], '{0}'.format(result))
        except Exception as e:
            self.fail(e)

    def test_item_update(self):
        random_str = self.generate_random_str(10)
        client_id = self.client[0]
        item_id = str(uuid.uuid4())
        try:
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id,
                'name': random_str,
                'description': random_str,
                'make': random_str,
                'brand': random_str,
                'model': random_str,
                'version': random_str,
                'sku': random_str,
                'upc': random_str,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })

            self.itemsStore.update({
                'clientId': client_id,
                'itemId': item_id,
                'name': random_str,
                'description': random_str,
                'make': random_str,
                'brand': random_str,
                'model': random_str,
                'version': random_str,
                'sku': random_str,
                'upc': random_str,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })
        except Exception as e:
            self.fail(e)

    def test_item_add_substitute(self):
        client_id = self.client[0]
        item_id1 = str(uuid.uuid4())
        item_id2 = str(uuid.uuid4())
        item_1 = self.generate_random_str(10)
        item_2 = self.generate_random_str(10)
        try:
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id1,
                'name': item_1,
                'description': item_1,
                'make': item_1,
                'brand': item_1,
                'model': item_1,
                'version': item_1,
                'sku': item_1,
                'upc': item_1,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id2,
                'name': item_2,
                'description': item_2,
                'make': item_2,
                'brand': item_2,
                'model': item_2,
                'version': item_2,
                'sku': item_2,
                'upc': item_2,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })

            self.itemsStore.addSubstitute(client_id, item_id1, item_id2)
        except Exception as e:
            self.fail(e)

    def test_item_substitutes(self):
        client_id = self.client[0]
        item_id1 = str(uuid.uuid4())
        item_id2 = str(uuid.uuid4())
        item_1 = self.generate_random_str(10)
        item_2 = self.generate_random_str(10)
        try:
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id1,
                'name': item_1,
                'description': item_1,
                'make': item_1,
                'brand': item_1,
                'model': item_1,
                'version': item_1,
                'sku': item_1,
                'upc': item_1,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id2,
                'name': item_2,
                'description': item_2,
                'make': item_2,
                'brand': item_2,
                'model': item_2,
                'version': item_2,
                'sku': item_2,
                'upc': item_2,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })

            self.itemsStore.addSubstitute(client_id, item_id1, item_id2)

            result = self.itemsStore.substitutes(client_id, item_id1)
            self.assertGreater(len(result), 0, '{0}'.format(result))
        except Exception as e:
            self.fail(e)

    def test_item_add_component(self):
        client_id = self.client[0]
        item_id1 = str(uuid.uuid4())
        item_id2 = str(uuid.uuid4())
        item_1 = self.generate_random_str(10)
        item_2 = self.generate_random_str(10)
        try:
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id1,
                'name': item_1,
                'description': item_1,
                'make': item_1,
                'brand': item_1,
                'model': item_1,
                'version': item_1,
                'sku': item_1,
                'upc': item_1,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id2,
                'name': item_2,
                'description': item_2,
                'make': item_2,
                'brand': item_2,
                'model': item_2,
                'version': item_2,
                'sku': item_2,
                'upc': item_2,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })

            self.itemsStore.addComponent(client_id, item_id1, item_id2, 1, 1,
                                         1)
        except Exception as e:
            self.fail(e)

    def test_unique_component(self):
        client_id = self.client[0]
        item_id1 = str(uuid.uuid4())
        item_id2 = str(uuid.uuid4())
        item_1 = self.generate_random_str(10)
        item_2 = self.generate_random_str(10)
        try:
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id1,
                'name': item_1,
                'description': item_1,
                'make': item_1,
                'brand': item_1,
                'model': item_1,
                'version': item_1,
                'sku': item_1,
                'upc': item_1,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id2,
                'name': item_2,
                'description': item_2,
                'make': item_2,
                'brand': item_2,
                'model': item_2,
                'version': item_2,
                'sku': item_2,
                'upc': item_2,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })

            self.itemsStore.addComponent(client_id, item_id1, item_id2, 1, 1,
                                         1)
            self.itemsStore.addComponent(client_id, item_id1, item_id2, 2, 1,
                                         1)
        except Exception as e:
            self.fail(e)

    def test_item_components(self):
        client_id = self.client[0]
        item_id1 = str(uuid.uuid4())
        item_id2 = str(uuid.uuid4())
        item_1 = self.generate_random_str(10)
        item_2 = self.generate_random_str(10)
        try:
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id1,
                'name': item_1,
                'description': item_1,
                'make': item_1,
                'brand': item_1,
                'model': item_1,
                'version': item_1,
                'sku': item_1,
                'upc': item_1,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id2,
                'name': item_2,
                'description': item_2,
                'make': item_2,
                'brand': item_2,
                'model': item_2,
                'version': item_2,
                'sku': item_2,
                'upc': item_2,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })

            self.itemsStore.addComponent(client_id, item_id1, item_id2, 1, 1,
                                         1)
            result = self.itemsStore.components(client_id, item_id1)
            self.assertGreater(len(result), 0, '{0}'.format(result))
        except Exception as e:
            self.fail(e)

    def test_item_unique_component(self):
        client_id = self.client[0]
        item_id1 = str(uuid.uuid4())
        item_id2 = str(uuid.uuid4())
        item_1 = self.generate_random_str(10)
        item_2 = self.generate_random_str(10)
        try:
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id1,
                'name': item_1,
                'description': item_1,
                'make': item_1,
                'brand': item_1,
                'model': item_1,
                'version': item_1,
                'sku': item_1,
                'upc': item_1,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })
            self.itemsStore.add({
                'clientId': client_id,
                'itemId': item_id2,
                'name': item_2,
                'description': item_2,
                'make': item_2,
                'brand': item_2,
                'model': item_2,
                'version': item_2,
                'sku': item_2,
                'upc': item_2,
                'length': 1,
                "length_unit_id": 1,
                'width': 1,
                "width_unit_id": 1,
                'height': 1,
                "height_unit_id": 1,
                'weight': 1,
                "weight_unit_id": 1,
                'perishable': True,
                'hazardous': False
            })

            self.itemsStore.addComponent(client_id, item_id1, item_id2, 1, 1,
                                         1)
            self.itemsStore.addComponent(client_id, item_id1, item_id2, 2, 1,
                                         1)
        except Exception as e:
            self.fail(e)
class TestWorkProjectTaskStore(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.project.stores.projects import ProjectStore
        from saas.app.modules.project.stores.tasks import TaskStore

        mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientStore(mgr, 'default')
        self.projects = ProjectStore(mgr, 'default')
        self.tasks = TaskStore(mgr, 'default')

        self.defaultClient = self.clientStore.getDefaultClient()

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_add(self):
        client_id = self.defaultClient[0]
        project_id = str(uuid.uuid4())
        task_id = str(uuid.uuid4())
        random_str = self.generate_random_str(10)

        self.projects.add(client_id, project_id, random_str, random_str,
                          datetime.datetime.now(), datetime.datetime.now(), [])

        try:
            self.tasks.add(client_id, project_id, task_id, random_str,
                           random_str)
        except Exception as e:
            self.fail(e)

    def test_update(self):
        client_id = self.defaultClient[0]
        project_id = str(uuid.uuid4())
        task_id = str(uuid.uuid4())
        random_str = self.generate_random_str(10)

        self.projects.add(client_id, project_id, random_str, random_str,
                          datetime.datetime.now(), datetime.datetime.now(), [])

        self.tasks.add(client_id, project_id, task_id, random_str, random_str)

        random_str = self.generate_random_str(10)

        try:
            self.tasks.update(client_id, project_id, task_id, random_str,
                              random_str)
        except Exception as e:
            self.fail(e)

    def test_remove(self):
        client_id = self.defaultClient[0]
        project_id = str(uuid.uuid4())
        task_id = str(uuid.uuid4())
        random_str = self.generate_random_str(10)

        self.projects.add(client_id, project_id, random_str, random_str,
                          datetime.datetime.now(), datetime.datetime.now(), [])

        self.tasks.add(client_id, project_id, task_id, random_str, random_str)

        self.tasks.remove(client_id, project_id, task_id)

    def test_get(self):
        client_id = self.defaultClient[0]
        project_id = str(uuid.uuid4())
        task_id = str(uuid.uuid4())
        random_str = self.generate_random_str(10)

        self.projects.add(client_id, project_id, random_str, random_str,
                          datetime.datetime.now(), datetime.datetime.now(), [])

        self.tasks.add(client_id, project_id, task_id, random_str, random_str)

        random_str = self.generate_random_str(10)

        try:
            result = self.tasks.get(client_id, project_id, task_id)
            self.assertGreater(len(result), 0, '{0}'.format(result))
        except Exception as e:
            self.fail(e)
Example #26
0
class TestHRShiftsStore(unittest.TestCase):

    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.hr.stores.members import MembersStore
        from saas.app.modules.hr.stores.time_entries import TimeEntriesStore

        self.mgr = ConnectionManager({
            'app.config': '../../etc'
        })
        self.clientStore = ClientStore(self.mgr, 'default')
        self.defaultClient = self.clientStore.getDefaultClient()
        self.mStore = MembersStore(self.mgr, 'default')
        self.store = TimeEntriesStore(self.mgr, 'default')

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_save(self):
        random_str = self.generate_random_str(10)

        client_id = self.defaultClient[0]

        member_id = str(uuid.uuid4())
        self.mStore.save({
            'clientId': client_id,
            'memberId': member_id,
            'firstName': random_str,
            'middleName': random_str,
            'lastName': random_str,
            'prefix': random_str,
            'suffix': random_str,
            'identifiers': [
                {
                    'idType': 1,
                    'value': '123'
                },
                {
                    'idType': 2,
                    'value': '123'
                }
            ]
        })

        entries = []
        entries.append({
            'timeEntryId': str(uuid.uuid4()),
            'start': '2020-06-30 08:00',
            'end': '2020-06-30 12:00',
            'hours': 4
        })
        entries.append({
            'timeEntryId': str(uuid.uuid4()),
            'start': '2020-06-30 13:00',
            'end': '2020-06-30 18:00',
            'hours': 5
        })

        self.store.save(client_id, member_id, { 'entries': entries })
class TestInventoryLocationStore(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.modules.inventory.stores.facility import FacilityStore
        from saas.app.modules.inventory.stores.locations import LocationStore
        from saas.app.core.stores.client import ClientStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.facilityStore = FacilityStore(self.mgr, 'default')
        self.locationStore = LocationStore(self.mgr, 'default')
        self.clientStore = ClientStore(self.mgr, 'default')
        self.client = self.clientStore.getDefaultClient()

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_location_add(self):
        random_str = self.generate_random_str(10)
        client_id = self.client[0]
        location_id = str(uuid.uuid4())
        facility_id = str(uuid.uuid4())
        country_id = self.client[4]
        area_uom_id = 1
        try:
            self.facilityStore.add(client_id, facility_id, random_str,
                                   random_str, random_str, country_id, 100,
                                   area_uom_id)
            self.locationStore.add(client_id, location_id, facility_id,
                                   random_str, random_str, random_str,
                                   random_str, random_str, random_str,
                                   random_str, random_str, random_str)
        except Exception as e:
            self.fail(e)

    def test_location_add_duplicate(self):
        random_str = self.generate_random_str(10)
        client_id = self.client[0]
        location_id = str(uuid.uuid4())
        facility_id = str(uuid.uuid4())
        country_id = self.client[4]
        area_uom_id = 1

        self.facilityStore.add(client_id, facility_id, random_str, random_str,
                               random_str, country_id, 100, area_uom_id)
        try:
            self.locationStore.add(client_id, location_id, facility_id,
                                   random_str, random_str, random_str,
                                   random_str, random_str, random_str,
                                   random_str, random_str, random_str)

            location_id = str(uuid.uuid4())
            self.assertRaises(StoreException, self.locationStore.add,
                              client_id, location_id, facility_id, random_str,
                              random_str, random_str, random_str, random_str,
                              random_str, random_str, random_str, random_str)
        except Exception as e:
            self.fail(e)

    def test_location_update(self):
        random_str = self.generate_random_str(10)
        client_id = self.client[0]
        location_id = str(uuid.uuid4())
        facility_id = str(uuid.uuid4())
        country_id = self.client[4]
        area_uom_id = 1

        self.facilityStore.add(client_id, facility_id, random_str, random_str,
                               random_str, country_id, 100, area_uom_id)
        self.locationStore.add(client_id, location_id, facility_id, random_str,
                               random_str, random_str, random_str, random_str,
                               random_str, random_str, random_str, random_str)

        try:
            random_str = self.generate_random_str(10)
            self.locationStore.update(client_id, location_id, facility_id,
                                      random_str, random_str, random_str,
                                      random_str, random_str, random_str,
                                      random_str, random_str, random_str)
        except Exception as e:
            self.fail(e)

    def test_location_get(self):
        random_str = self.generate_random_str(10)
        client_id = self.client[0]
        location_id = str(uuid.uuid4())
        facility_id = str(uuid.uuid4())
        country_id = self.client[4]
        area_uom_id = 1

        self.facilityStore.add(client_id, facility_id, random_str, random_str,
                               random_str, country_id, 100, area_uom_id)
        self.locationStore.add(client_id, location_id, facility_id, random_str,
                               random_str, random_str, random_str, random_str,
                               random_str, random_str, random_str, random_str)

        try:
            result = self.locationStore.get(client_id, location_id)
            self.assertGreater(len(result), 0, '{0}'.format(result))
        except Exception as e:
            self.fail(e)

    def test_location_filter(self):
        random_str = self.generate_random_str(10)
        client_id = self.client[0]
        location_id = str(uuid.uuid4())
        facility_id = str(uuid.uuid4())
        country_id = self.client[4]
        area_uom_id = 1

        self.facilityStore.add(client_id, facility_id, random_str, random_str,
                               random_str, country_id, 100, area_uom_id)
        self.locationStore.add(client_id, location_id, facility_id, random_str,
                               random_str, random_str, random_str, random_str,
                               random_str, random_str, random_str, random_str)

        try:
            result = self.locationStore.filter(client_id, random_str[1:9])
            self.assertGreater(
                len(result), 0, '{0} {1} {2}'.format(result, random_str,
                                                     random_str[1:9]))
        except Exception as e:
            self.fail(e)
Example #28
0
class TestAdminClients(unittest.TestCase):
    def setUp(self):
        self.settings = get_appsettings('testing.ini', name='main')

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientStore(self.mgr, 'default')
        self.defaultClient = self.clientStore.getDefaultClient()

        default_client_id = self.defaultClient[0]

        usersStore = UsersStore(self.mgr, 'default')
        users = usersStore.getAllClientUsers(default_client_id)
        default_user = users[0]
        default_user_email = default_user[2]

        log.warning('email: %s', default_user_email)
        log.warning('client: %s', self.defaultClient[2])

        # self.session = webdriver.Firefox()
        self.session = webdriver.Chrome()
        self.session.get('http://saas.com')

        # set up cookie
        JWT_KEY = self.settings['jwt.secret']
        COOKIE_MAX_AGE = self.settings['cookie.max_age']

        now = time.time()
        created = renewed = accessed = now

        cookie_value = jwt.encode(
            {
                'email': default_user_email,
                'client': default_client_id,
                'iat': created,
                'updated_at': renewed
            },
            key=JWT_KEY,
            algorithm='HS256')

        self.session.add_cookie({
            'name': 'session',
            'value': cookie_value.decode('utf-8'),
            'max_age': COOKIE_MAX_AGE,
            'path': '/',
            'secure': False,
            'samesite': 'Lax'
        })

        # reload page
        self.session.get('http://saas.com')

    def tearDown(self):
        self.session.close()

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def get_shadow_root(self, element):
        return self.session.execute_script('return arguments[0].shadowRoot;',
                                           element)

    def test_add_client(self):
        elem = WebDriverWait(self.session, 10).until(
            EC.presence_of_element_located((By.ID, 'nav-admin')))

        # elem = self.session.find_element_by_id('nav-admin')
        elem.click()

        elem = self.session.find_element_by_css_selector(
            '[data-action="admin.clients"]')
        elem.click()

        tab = self.get_shadow_root(
            self.session.find_element_by_css_selector('tab-container'))

        clients_table = tab.find_element_by_css_selector('clients-table')
        sr = self.get_shadow_root(clients_table)
        btn = sr.find_element_by_id('btn-new')
        btn.click()

        client_editor = tab.find_element_by_css_selector('client-editor')
        sr_ce = self.get_shadow_root(client_editor)
        random_str = self.generate_random_str(10)

        input_name = sr_ce.find_element_by_id('name')
        input_name.send_keys(random_str)

        input_address = sr_ce.find_element_by_id('address')
        input_address.send_keys(random_str)

        # press country selector
        country = sr_ce.find_element_by_id('country')
        sr_country = self.get_shadow_root(country)
        btn = sr_country.find_element_by_id('btn-select')
        btn.click()

        # country-selector-view
        try:
            country_selector_view = WebDriverWait(self.session, 10).until(
                EC.presence_of_element_located(
                    (By.CSS_SELECTOR, 'country-selector-view')))
            # country_selector_view = self.session.find_element_by_css_selector('country-selector-view')
            sr_csv = self.get_shadow_root(country_selector_view)
            form_search = sr_csv.find_element_by_id('search')
            sr_fs = self.get_shadow_root(form_search)
            sr_fs.find_element_by_id('filter').send_keys('philippines')
            sr_fs.find_element_by_id('btn-filter').click()
            radio_phil = WebDriverWait(sr_csv, 10).until(
                EC.presence_of_element_located(
                    (By.CSS_SELECTOR, '.form-input-selected[value="608"]')))
            # radio_phil = sr_csv.find_element_by_css_selector('.form-input-selected[value="608"]')
            radio_phil.click()
        except TimeoutException as e:
            self.fail(e)

        # press currency selector
        currency = sr_ce.find_element_by_id('currency')
        sr_currency = self.get_shadow_root(currency)
        btn = sr_currency.find_element_by_id('btn-select')
        btn.click()

        # currency-selector-view
        try:
            currency_selector_view = WebDriverWait(self.session, 10).until(
                EC.presence_of_element_located(
                    (By.CSS_SELECTOR, 'currency-selector-view')))
            # currency_selector_view = self.session.find_element_by_css_selector('currency-selector-view')
            sr_csv = self.get_shadow_root(currency_selector_view)
            sr_csv.find_element_by_id('filter').send_keys('peso')
            sr_csv.find_element_by_id('btn-filter').click()
            radio_peso = WebDriverWait(sr_csv, 10).until(
                EC.presence_of_element_located(
                    (By.CSS_SELECTOR, '.form-input-selected[value="108"]')))
            # radio_peso = sr_csv.find_element_by_css_selector('.form-input-selected[value="108"]')
            radio_peso.click()
        except TimeoutException as e:
            self.fail(e)

        btn_save = sr_ce.find_element_by_id('btn-save')
        btn_save.click()

        nl = self.session.find_element_by_css_selector('notification-list')
        log.error(nl.get_attribute('innerHTML'))

        try:
            # notification = notifier.find_element_by_css_selector('.notification .is-success')
            # notification = WebDriverWait(notifier, 10).until(
            #     EC.presence_of_element_located((By.CSS_SELECTOR, '.notification .is-success'))
            # )
            log.error(notifier)
            # self.assertIsNotNone(notification, 'Client was not added')
        except TimeoutException as e:
            log.error(e)
            self.fail(e)
class TestOrganizationsStore(unittest.TestCase):

    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.clients.stores.organizations import OrganizationsStore

        self.mgr = ConnectionManager({
            'app.config': '../../etc'
        })
        self.clientStore = ClientStore(self.mgr, 'default')
        self.orgStore = OrganizationsStore(self.mgr, 'default')
        self.client = self.clientStore.getDefaultClient()

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_add_organization(self):
        org_name = self.generate_random_str(10)
        client_id = self.client[0]
        organization_id = str(uuid.uuid4())
        try:
            self.orgStore.add(client_id, organization_id, org_name, org_name)
        except Exception as e:
            self.fail(e)

    def test_update_organization(self):
        org_name = self.generate_random_str(10)
        new_org_name = self.generate_random_str(10)
        client_id = self.client[0]
        organization_id = str(uuid.uuid4())
        try:
            self.orgStore.add(client_id, organization_id, org_name, org_name)
            self.orgStore.update(client_id, organization_id, new_org_name, new_org_name)
        except Exception as e:
            self.fail(e)

    def test_get_organization(self):
        org_name = self.generate_random_str(10)
        client_id = self.client[0]
        organization_id = str(uuid.uuid4())
        try:
            self.orgStore.add(client_id, organization_id, org_name, org_name)
            [t_org_id, active, name, description] = self.orgStore.get(organization_id)
            self.assertEqual(organization_id, t_org_id)
        except Exception as e:
            self.fail(e)

    def test_get_root_organization(self):
        client_id = self.client[0]
        try:
            result = self.orgStore.getRoot(client_id)
        except Exception as e:
            self.fail(e)

    def test_set_parent_organization(self):
        org_name_1 = self.generate_random_str(10)
        org_name_2 = self.generate_random_str(10)
        org_name_3 = self.generate_random_str(10)
        org_name_4 = self.generate_random_str(10)
        client_id = self.client[0]
        organization_id1 = str(uuid.uuid4())
        organization_id2 = str(uuid.uuid4())
        organization_id3 = str(uuid.uuid4())
        organization_id4 = str(uuid.uuid4())
        try:
            self.orgStore.add(client_id, organization_id1, org_name_1, org_name_1)
            self.orgStore.add(client_id, organization_id2, org_name_2, org_name_2)
            self.orgStore.add(client_id, organization_id3, org_name_3, org_name_3)
            self.orgStore.add(client_id, organization_id4, org_name_4, org_name_4)

            # org_id_3 -> org_id_2 -> org_id_1
            self.orgStore.setParentOrg(client_id, organization_id3, organization_id2)
            self.orgStore.setParentOrg(client_id, organization_id2, organization_id1)

            # org_id_2 -> org_id_4
            self.orgStore.setParentOrg(client_id, organization_id2, organization_id4)
        except Exception as e:
            self.fail(e)

    def test_get_tree(self):
        client_id = self.client[0]
        try:
            result = self.orgStore.tree(client_id)
        except Exception as e:
            self.fail(e)
class TestAccountGroupStore(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()

        from saas.app.core.services.connection import ConnectionManager
        from saas.app.core.stores.client import ClientStore
        from saas.app.modules.accounting.stores.accounts import AccountsStore
        from saas.app.modules.accounting.stores.groups import GroupStore

        self.mgr = ConnectionManager({'app.config': '../../etc'})
        self.clientStore = ClientStore(self.mgr, 'default')
        self.groupStore = GroupStore(self.mgr, 'default')
        self.accountsStore = AccountsStore(self.mgr, 'default',
                                           self.groupStore)

        self.defaultClient = self.clientStore.getDefaultClient()

    def generate_random_str(self, length: int):
        allowed = string.ascii_lowercase + string.digits
        return ''.join(random.choice(allowed) for i in range(length))

    def test_group_add(self):
        client_id = self.defaultClient[0]
        group_id = str(uuid.uuid4())
        random_str = self.generate_random_str(10)
        try:
            self.groupStore.add(client_id, group_id, AccountTypes.ASSETS,
                                random_str, random_str)
        except StoreException as e:
            self.fail(e)

    def test_group_add_fail(self):
        '''should not be able to add group named 'asset' - predefined group
        '''
        client_id = self.defaultClient[0]
        group_id = str(uuid.uuid4())
        random_str = 'asset'
        self.assertRaises(Exception, self.groupStore.add, client_id, group_id,
                          AccountTypes.ASSETS, random_str, random_str)

    def test_group_update(self):
        client_id = self.defaultClient[0]
        group_id = str(uuid.uuid4())
        random_str = self.generate_random_str(10)

        self.groupStore.add(client_id, group_id, AccountTypes.ASSETS,
                            random_str, random_str)
        try:
            random_str = self.generate_random_str(10)
            self.groupStore.update(client_id, group_id, AccountTypes.ASSETS,
                                   random_str, random_str)
        except StoreException as e:
            self.fail(e)

    def test_group_get(self):
        client_id = self.defaultClient[0]
        group_id = str(uuid.uuid4())
        random_str = self.generate_random_str(10)

        self.groupStore.add(client_id, group_id, AccountTypes.ASSETS,
                            random_str, random_str)
        try:
            result = self.groupStore.get(client_id, group_id)

        except StoreException as e:
            self.fail(e)

    def test_group_update_fail(self):
        '''should not be able to update name to a predefined group
        '''
        client_id = self.defaultClient[0]
        group_id = str(uuid.uuid4())
        random_str = self.generate_random_str(10)
        self.groupStore.add(client_id, group_id, AccountTypes.ASSETS,
                            random_str, random_str)
        random_str = 'asset'
        self.assertRaises(Exception, self.groupStore.update, client_id,
                          group_id, AccountTypes.ASSETS, random_str,
                          random_str)

    def test_group_update_fail2(self):
        '''should not be able to update a predefined group
        '''
        # client_id = self.defaultClient[0]
        # group_id = str(uuid.uuid4())
        # random_str = self.generate_random_str(10)
        # self.groupStore.add(client_id, group_id, random_str, random_str)
        # self.assertRaises(
        #     Exception,
        #     self.groupStore.update,
        #     client_id,
        #     group_id,
        #     random_str,
        #     random_str
        # )
        # // TODO: how to retrieve predefined group
        pass

    def test_assign_parent(self):
        client_id = self.defaultClient[0]

        group_id_1 = str(uuid.uuid4())
        random_str_1 = self.generate_random_str(10)

        group_id_2 = str(uuid.uuid4())
        random_str_2 = self.generate_random_str(10)
        try:
            self.groupStore.add(client_id, group_id_1, AccountTypes.ASSETS,
                                random_str_1, random_str_1)
            self.groupStore.add(client_id, group_id_2, AccountTypes.ASSETS,
                                random_str_2, random_str_2)

            self.groupStore.assignParent(client_id, group_id_1, group_id_2)
        except StoreException as e:
            self.fail(e)

    def test_tree(self):
        client_id = self.defaultClient[0]
        try:
            result = self.groupStore.tree(client_id)
            self.assertGreater(len(result), 0, '{0}'.format(result))
        except StoreException as e:
            self.fail(e)