Exemple #1
0
 def test_add_application_reference(self):
     profile = UserProfile(store=self.store, name=u"foo")
     assert profile.profile_settings.count() == 0
     profile.add_application_reference(
         u'my_app', has_permission=True)
     assert len(list(profile.profile_settings)) == 1
     assert profile.check_app_permission(u'my_app')
Exemple #2
0
 def test_add_application_reference(self):
     profile = UserProfile(store=self.store, name=u"foo")
     assert profile.profile_settings.count() == 0
     profile.add_application_reference(
         u'my_app', has_permission=True)
     assert len(list(profile.profile_settings)) == 1
     assert profile.check_app_permission(u'my_app')
Exemple #3
0
    def test_update_profile_applications(self):
        profile = UserProfile(store=self.store, name=u'assistant')

        profile.add_application_reference(u'stock', has_permission=True)
        items = profile.profile_settings
        assert len(list(items)) == 1

        new_profile = UserProfile(store=self.store, name=u'assistant')
        update_profile_applications(self.store, new_profile)
        items = new_profile.profile_settings
Exemple #4
0
 def test_set_permission(self):
     profile = UserProfile(store=self.store, name=u'boss')
     profile.add_application_reference(u'app', False)
     setting = self.store.find(ProfileSettings, user_profile=profile,
                                          app_dir_name=u'app').one()
     self.failIf(setting.has_permission)
     ProfileSettings.set_permission(self.store, profile, u'app', True)
     self.failUnless(setting.has_permission)
     ProfileSettings.set_permission(self.store, profile, u'app', False)
     self.failIf(setting.has_permission)
Exemple #5
0
 def test_set_permission(self):
     profile = UserProfile(store=self.store, name=u'boss')
     profile.add_application_reference(u'app', False)
     setting = self.store.find(ProfileSettings, user_profile=profile,
                               app_dir_name=u'app').one()
     self.assertFalse(setting.has_permission)
     ProfileSettings.set_permission(self.store, profile, u'app', True)
     self.assertTrue(setting.has_permission)
     ProfileSettings.set_permission(self.store, profile, u'app', False)
     self.assertFalse(setting.has_permission)
Exemple #6
0
    def test_update_profile_applications(self):
        profile = UserProfile(store=self.store, name=u'assistant')

        profile.add_application_reference(u'stock',
                                          has_permission=True)
        items = profile.profile_settings
        assert len(list(items)) == 1

        new_profile = UserProfile(store=self.store, name=u'assistant')
        update_profile_applications(self.store, new_profile)
        items = new_profile.profile_settings
Exemple #7
0
    def test_get_default(self):
        profile = UserProfile.get_default(self.store)
        self.failUnless(isinstance(profile, UserProfile))
        self.assertEquals(profile.name, _(u'Salesperson'))

        # Change Salesperson's profile name so get_default won't find it
        # and it will fallback to any
        profile.name = u'XXX'
        profile2 = UserProfile.get_default(self.store)
        self.assertTrue(isinstance(profile2, UserProfile))
        self.assertIn(profile2, self.store.find(UserProfile))
Exemple #8
0
    def test_get_default(self):
        profile = UserProfile.get_default(self.store)
        self.failUnless(isinstance(profile, UserProfile))
        self.assertEquals(profile.name, _(u'Salesperson'))

        # Change Salesperson's profile name so get_default won't find it
        # and it will fallback to any
        profile.name = u'XXX'
        profile2 = UserProfile.get_default(self.store)
        self.assertTrue(isinstance(profile2, UserProfile))
        self.assertIn(profile2, self.store.find(UserProfile))
Exemple #9
0
 def test_default_receiving_cfop(self):
     branch = self.create_branch()
     param = self.sparam.get_object(self.store, 'DEFAULT_RECEIVING_CFOP')
     person = Person(name=u'Craudinho', store=self.store)
     Individual(person=person, store=self.store)
     profile = UserProfile(name=u'profile', store=self.store)
     responsible = LoginUser(person=person,
                             store=self.store,
                             password=u'asdfgh',
                             profile=profile,
                             username=u'craudio')
     receiving_order = ReceivingOrder(responsible=responsible,
                                      branch=branch,
                                      store=self.store,
                                      invoice_number=876,
                                      supplier=None)
     param2 = self.sparam.get_object(self.store, 'DEFAULT_SALES_CFOP')
     receiving_order2 = ReceivingOrder(responsible=responsible,
                                       cfop=param2,
                                       branch=branch,
                                       store=self.store,
                                       invoice_number=1231,
                                       supplier=None)
     self.assertEqual(param, receiving_order.cfop)
     self.failIfEqual(param, receiving_order2.cfop)
Exemple #10
0
def create_default_profiles():
    store = new_store()

    log.info("Creating user default profiles")
    UserProfile.create_profile_template(store, _(u'Administrator'), True)
    UserProfile.create_profile_template(store, _(u'Manager'), True)
    UserProfile.create_profile_template(store, _(u'Salesperson'), False)

    store.commit(close=True)
Exemple #11
0
def create_default_profiles():
    store = new_store()

    log.info("Creating user default profiles")
    UserProfile.create_profile_template(store, _(u'Administrator'), True)
    UserProfile.create_profile_template(store, _(u'Manager'), True)
    UserProfile.create_profile_template(store, _(u'Salesperson'), False)

    store.commit(close=True)
Exemple #12
0
 def _setup_profile_entry_completion(self):
     if self.model.profile is None:
         self.model.profile = UserProfile.get_default(store=self.store)
     profiles = self.store.find(UserProfile).order_by(UserProfile.name)
     self.profile.prefill(api.for_combo(profiles, attr="name"))
Exemple #13
0
 def test_check_app_permission(self):
     profile = UserProfile(store=self.store, name=u'boss')
     profile.add_application_reference(u'test_application', True)
     assert profile.check_app_permission(u'test_application') is True
Exemple #14
0
 def create_user_profile(self):
     from stoqlib.domain.profile import UserProfile
     return UserProfile(store=self.store, name=u'assistant')
Exemple #15
0
 def get_foreign_key_data(self):
     return [UserProfile(store=self.store, name=u'Manager')]
Exemple #16
0
    def test_get_permissions(self):
        profile = UserProfile(store=self.store, name=u'boss')
        profile.add_application_reference(u'app1', False)
        profile.add_application_reference(u'app2', True)
        profile.add_application_reference(u'app3', False)

        self.assertEqual(profile.get_permissions(),
                         {'app1': False,
                          'app2': True,
                          'app3': False,
                          'link': False})

        admin_ps = profile.add_application_reference(u'admin', False)
        self.assertEqual(profile.get_permissions(),
                         {'app1': False,
                          'app2': True,
                          'app3': False,
                          'admin': False,
                          'link': False})

        admin_ps.has_permission = True
        self.assertEqual(profile.get_permissions(),
                         {'app1': False,
                          'app2': True,
                          'app3': False,
                          'admin': True,
                          'link': True})
Exemple #17
0
 def test_get_description(self):
     profile = UserProfile(store=self.store, name=u"profile name")
     self.assertEqual(profile.get_description(), 'profile name')
Exemple #18
0
    def test_get_permissions(self):
        profile = UserProfile(store=self.store, name=u'boss')
        profile.add_application_reference(u'app1', False)
        profile.add_application_reference(u'app2', True)
        profile.add_application_reference(u'app3', False)

        self.assertEqual(profile.get_permissions(), {
            'app1': False,
            'app2': True,
            'app3': False,
            'link': False
        })

        admin_ps = profile.add_application_reference(u'admin', False)
        self.assertEqual(
            profile.get_permissions(), {
                'app1': False,
                'app2': True,
                'app3': False,
                'admin': False,
                'link': False
            })

        admin_ps.has_permission = True
        self.assertEqual(
            profile.get_permissions(), {
                'app1': False,
                'app2': True,
                'app3': False,
                'admin': True,
                'link': True
            })
Exemple #19
0
 def create_model(self, store):
     return UserProfile.create_profile_template(store, u'', False)
Exemple #20
0
 def _setup_profile_entry_completion(self):
     if self.model.profile is None:
         self.model.profile = UserProfile.get_default(store=self.store)
     profiles = self.store.find(UserProfile).order_by(UserProfile.name)
     self.profile.prefill(api.for_combo(profiles, attr="name"))
Exemple #21
0
 def create_model(self, store):
     return UserProfile.create_profile_template(store, u'', False)
Exemple #22
0
 def test_get_description(self):
     profile = UserProfile(store=self.store, name=u"profile name")
     self.assertEqual(profile.get_description(), 'profile name')
Exemple #23
0
 def test_check_app_permission(self):
     profile = UserProfile(store=self.store, name=u'boss')
     profile.add_application_reference(u'test_application', True)
     assert profile.check_app_permission(u'test_application') == True