示例#1
0
 def tearDown(self):
     self.strategy = None
     User.reset_cache()
     TestUserSocialAuth.reset_cache()
     TestNonce.reset_cache()
     TestAssociation.reset_cache()
     HTTPretty.disable()
示例#2
0
 def setUp(self):
     HTTPretty.enable()
     self.strategy = TestStrategy(self.backend, TestStorage)
     User.reset_cache()
     TestUserSocialAuth.reset_cache()
     TestNonce.reset_cache()
     TestAssociation.reset_cache()
 def test_multiple_accounts_with_same_email(self):
     user1 = User(username='******')
     user2 = User(username='******')
     user1.email = '*****@*****.**'
     user2.email = '*****@*****.**'
     self.do_login.when.called_with(after_complete_checks=False)\
         .should.throw(AuthException)
示例#4
0
    def test_get_rest_name(self):
        """ Get user REST name """
        session = start_session(username="******", password="******", enterprise="Alcatel", api_url="https://example.com", version="3.0", api_prefix="api")

        user = User()
        self.assertEquals(user.rest_name, 'me')
        self.assertEquals(user.get_resource_url(), 'https://example.com/api/v3_0/me')
示例#5
0
    def test_parent_for_matching_rest_name(self):
        """ """
        enterprise1 = Enterprise(id='4', name='enterprise')
        user = User()
        user.parent_object = enterprise1

        self.assertEquals(user.parent_for_matching_rest_name(['enterprise']), enterprise1)
        self.assertIsNone(user.parent_for_matching_rest_name(['not-enterprise']))
 def setUp(self):
     HTTPretty.enable()
     User.reset_cache()
     TestUserSocialAuth.reset_cache()
     TestNonce.reset_cache()
     TestAssociation.reset_cache()
     self.backend = module_member('social.backends.github.GithubOAuth2')
     self.strategy = TestStrategy(self.backend, TestStorage)
     self.user = None
 def tearDown(self):
     self.backend = None
     self.strategy = None
     self.user = None
     User.reset_cache()
     User.set_active(True)
     TestUserSocialAuth.reset_cache()
     TestNonce.reset_cache()
     TestAssociation.reset_cache()
     HTTPretty.disable()
示例#8
0
    def test_fetchers(self):
        """ test fetchers registry methods """

        user = User()

        rest_names = user.children_rest_names
        self.assertEquals(rest_names, ['group', 'enterprise'])
        self.assertEquals(user.fetcher_for_rest_name('group'), [])
        self.assertEquals(user.fetcher_for_rest_name('enterprise'), [])

        self.assertEquals(user.fetcher_for_rest_name('nothing'), None)
示例#9
0
    def test_contains(self):
        """ Fetcher contains object """

        user = User()

        group1 = Group(id='xxxx-xxxx-xxx', name="group1")
        group2 = Group(id='yyyy-yyyy-yyy', name="group2")
        group3 = Group(id='zzzz-zzzz-zzz', name="group3")

        user.add_child(group1)
        user.add_child(group2)

        self.assertEquals(group1 in user.groups, True)
        self.assertEquals(group2 in user.groups, True)
        self.assertEquals(group3 in user.groups, False)
    def test_disconnect_with_partial_pipeline(self):
        self.strategy.set_settings({
            'SOCIAL_AUTH_DISCONNECT_PIPELINE': (
                'social.pipeline.partial.save_status_to_session',
                'tests.pipeline.ask_for_password',
                'tests.pipeline.set_password',
                'social.pipeline.disconnect.allowed_to_disconnect',
                'social.pipeline.disconnect.get_entries',
                'social.pipeline.disconnect.revoke_tokens',
                'social.pipeline.disconnect.disconnect'
            )
        })
        self.do_login()
        user = User.get(self.expected_username)
        redirect = do_disconnect(self.strategy, user)

        url = self.strategy.build_absolute_uri('/password')
        expect(redirect.url).to.equal(url)
        HTTPretty.register_uri(HTTPretty.GET, redirect.url, status=200,
                               body='foobar')
        HTTPretty.register_uri(HTTPretty.POST, redirect.url, status=200)

        password = '******'
        requests.get(url)
        requests.post(url, data={'password': password})
        data = parse_qs(HTTPretty.last_request.body)
        expect(data['password']).to.equal(password)
        self.strategy.session_set('password', data['password'])

        redirect = do_disconnect(self.strategy, user)
        expect(len(user.social)).to.equal(0)
示例#11
0
    def test_index(self):
        """ Fetcher index object """

        user = User()

        group1 = Group(id='xxxx-xxxx-xxx', name="group1")
        group2 = Group(id='yyyy-yyyy-yyy', name="group2")
        group3 = Group(id='zzzz-zzzz-zzz', name="group3")

        user.add_child(group1)
        user.add_child(group2)

        self.assertEquals(user.groups.index(group1), 0)
        self.assertEquals(user.groups.index(group2), 1)

        with self.assertRaises(ValueError):
            user.groups.index(group3)
示例#12
0
    def test_flush(self):
        """ Flush fetcher """

        user = User()

        group1 = Group(name="group1")
        group2 = Group(name="group2")
        group3 = Group(name="group3")

        user.add_child(group1)
        user.add_child(group2)

        user.groups.append(group3)

        self.assertEquals(user.groups, [group1, group2, group3])

        user.groups.flush()
        self.assertEquals(user.groups, [])
示例#13
0
    def test_from_dict(self):
        """ Fill object from a dictionary """

        to_dict = dict()
        to_dict['ID'] = 3
        to_dict['userName'] = '******'
        to_dict['password'] = '******'
        to_dict['APIKey'] = '12453'
        #to_dict['creationDate'] = '2014-04-25 17:05:34'

        user = User()
        user.from_dict(to_dict)

        self.assertEquals(user.id, 3)
        self.assertEquals(user.user_name, 'Employee')
        self.assertEquals(user.password, 'anotherPassword')
        self.assertEquals(user.api_key, '12453')
        self.assertEquals(user.parent_id, None)
        self.assertEquals(user.parent_type, None)
示例#14
0
 def test_revoke_token(self):
     self.strategy.set_settings({
         'SOCIAL_AUTH_REVOKE_TOKENS_ON_DISCONNECT': True
     })
     self.do_login()
     user = User.get(self.expected_username)
     user.password = '******'
     backend = self.backend
     HTTPretty.register_uri(self._method(backend.REVOKE_TOKEN_METHOD),
                            backend.REVOKE_TOKEN_URL,
                            status=200)
     do_disconnect(self.strategy, user)
示例#15
0
    def test_distinct_values_of(self):
        user, new = User.objects.get_or_create(name="Sergio Mena")
        role_lst = []
        with BlockSave(Role):
            for i in range(1, 6, 1):
                role = Role(name="Musician%s" % i, usr=user)
                role.save()
                role_lst.append(role)

        user_dict_1 = Role.objects.filter(name="Musician1").distinct_values_of("usr_id")
        assert sum(user_dict_1.values()) == 1

        user_dict_2 = Role.objects.filter(usr_id=user.key).distinct_values_of("usr_id")
        assert sum(user_dict_2.values()) == 5

        Role.objects.filter(active=True).delete()

        with BlockSave(Role, query_dict={'active': True}):
            for i, r in enumerate(role_lst):
                if i == 3:
                    pass
                else:
                    r.active = True
                    r.save()

        user_dict_3 = Role.objects.filter(active=True).distinct_values_of("usr_id")
        assert sum(user_dict_3.values()) == 4

        new_user = User(name="Valnetin Hegg")
        new_user.blocking_save()
        role_lst[0].usr = new_user
        role_lst[0].blocking_save(query_dict={'usr': new_user})
        user_dict_4 = Role.objects.filter(active=True, usr_id=user.key).distinct_values_of("usr_id")
        assert sum(user_dict_4.values()) == 3
        
        with BlockDelete(Role):
            for r in role_lst:
                r.delete()
示例#16
0
文件: __init__.py 项目: Dogild/bambou
def start_session(username="******", password="******", enterprise="enterprise", api_url="https://*****:*****@enterprse.com"
    user.enterprise_id ="<enterprise_id>"
    user.enterprise_name ="enterprise"
    user.firstname ="John",
    user.id ="<user_id>"
    user.lastname ="Doe"
    user.role ="ROLE"

    # Set API KEY
    session._login_controller.api_key = user.api_key

    # Activate session
    _NURESTSessionCurrentContext.session = session

    return user
示例#17
0
    def test_to_dict(self):
        """ Get object as dictionary """

        user = User()
        user.id = 3
        user.user_name ="Christophe"
        user.password = '******'
        user.api_key = 'ABCD'

        to_dict = user.to_dict()

        self.assertEquals(to_dict['userName'], 'Christophe')
        self.assertEquals(to_dict['password'], 'sorry')
        self.assertEquals(to_dict['APIKey'], 'ABCD')
        self.assertEquals(to_dict['parentID'], None)
        self.assertEquals(to_dict['parentType'], None)
        self.assertEquals(to_dict['owner'], None)
        self.assertEquals(to_dict['creationDate'], None)
示例#18
0
 def index(self):
     user = User()
     if user.is_authenticated():
         return "WooHoo"
     return "Fail"
 def reader_thread(q, num):
     for _ in range(num):
         data_queue.put(User.select().count())
示例#20
0
 def setUp(self):
     super(AlreadyAssociatedErrorTest, self).setUp()
     self.user1 = User(username='******', email='*****@*****.**')
     self.user = None
示例#21
0
 def test_already_associated_error(self):
     self.user = self.user1
     self.do_login()
     self.user = User(username='******', email='*****@*****.**')
     self.do_login.when.called_with().should.throw(
         AuthAlreadyAssociated, 'This github account is already in use.')
示例#22
0
 def test_multiple_accounts_with_same_email(self):
     user = User(username='******')
     user.email = '*****@*****.**'
     self.do_login(after_complete_checks=False)
     expect(self.strategy.session_get('username').startswith('foobar')) \
             .to.equal(True)
示例#23
0
    def test_get_resource_url_for_child_type(self):
        """ Get user for child type """

        user = User()
        self.assertEquals(user.get_resource_url_for_child_type(Enterprise), 'https://vsd:8443/api/v3_2/enterprises')
示例#24
0
 def test_fetcher_parent_assignation(self):
     """ Test is parent obects are correctly set"""
     user = User()
     self.assertEquals(user.fetcher_for_rest_name("group").parent_object, user)
示例#25
0
    def test_parents_relationship(self):
        """ Test is parent obects are correctly set"""
        user = User()

        group1 = Group(id='xxxx-xxxx-xxx', name="group1")

        user.add_child(group1)
        self.assertEquals(group1.parent_object, user)

        user.remove_child(group1)
        self.assertEquals(group1.parent_object, None)

        user.add_child(group1)
        updated_group = Group(id='xxxx-xxxx-xxx', name="group-updated")
        user.update_child(updated_group)

        self.assertEquals(user.groups[0], updated_group)
        self.assertEquals(user.groups[0].name, 'group-updated')

        with self.assertRaises(InternalConsitencyError):
            user.add_child(user)
 def test_multiple_accounts_with_same_email(self):
     user = User(username='******')
     user.email = '*****@*****.**'
     self.do_login(after_complete_checks=False)
     expect(self.strategy.session_get('username').startswith('foobar')) \
             .to.equal(True)
示例#27
0
 def test_safe_save_to_database_error(self):
     assert not safe_save_to_database(User())
 def test_inactive_user(self):
     self.strategy.set_settings({"SOCIAL_AUTH_INACTIVE_USER_URL": "/inactive"})
     User.set_active(False)
     redirect = self.do_login(after_complete_checks=False)
     expect(redirect.url).to.equal("/inactive")
示例#29
0
 def test_random_username(self):
     User(username='******')
     self.do_login(after_complete_checks=False)
     expect(self.strategy.session_get('username').startswith('foobar')) \
             .to.equal(True)
示例#30
0
 def test_raise_assign_to_non_existent_field(self):
     with pytest.raises(AttributeError):
         u = User()
         u.foo = 'bar'
 def test_not_allowed_to_disconnect(self):
     self.do_login()
     user = User.get(self.expected_username)
     do_disconnect.when.called_with(self.strategy, user).should.throw(
         NotAllowedToDisconnect
     )
示例#32
0
 def test_save_to_database_error(self):
     self.assertRaises(ModelError, save_to_database, User())
 def test_disconnect(self):
     self.do_login()
     user = User.get(self.expected_username)
     user.password = '******'
     do_disconnect(self.strategy, user)
     expect(len(user.social)).to.equal(0)
        def create_user_thread(low, hi):
            for _ in range(low, hi):
                User.create(name="u%d" % i)

            User.get_connection_resolver().disconnect()
示例#35
0
 def test_user(self):
     user = User()
     user.save()
     self.assertIsNotNone(user.created_at)
     self.assertIsNotNone(user.updated_at)
     self.assertEqual(str(user), '1')
示例#36
0
 def setUp(self):
     super(AssociateActionTest, self).setUp()
     self.user = User(username='******', email='*****@*****.**')
示例#37
0
    def test_to_dict(self):
        """ Get object as dictionary """

        enterprise = Enterprise()
        enterprise.id = 3
        enterprise.name ="NewEnterprise"

        # List of objects
        admingroup = Group()
        admingroup.name = "Admins"
        othergroup = Group()
        othergroup.name = "Others"
        enterprise.groups = [admingroup, othergroup]

        # Object
        ceo = User()
        ceo.firstname = 'John'
        ceo.lastname = 'Doe'
        enterprise.ceo = ceo

        to_dict = enterprise.to_dict()


        self.assertEquals(sorted(to_dict.keys()), sorted(['groups', 'token', 'lastUpdatedDate', 'allowedForwardingClasses', 'name', 'ceo', 'parentType', 'parentID', 'owner', 'creationDate', 'ID', 'description']))
        self.assertEquals(to_dict['name'], 'NewEnterprise')
        self.assertEquals(to_dict['ID'], 3)
        #self.assertEquals(to_dict['externalID'], None)
        #self.assertEquals(to_dict['localID'], None)
        self.assertEquals(to_dict['parentID'], None)
        self.assertEquals(to_dict['parentType'], None)
        self.assertEquals(to_dict['owner'], None)
        self.assertEquals(to_dict['creationDate'], None)
        self.assertEquals(to_dict['ceo'], {
                                            'APIKey': None,
                                            'APIKeyExpiry': None,
                                            'ID': None,
                                            'avatarData': None,
                                            'avatarType': None,
                                            'creationDate': None,
                                            'email': None,
                                            'enterpriseID': None,
                                            'enterpriseName': None,
                                            'firstName': 'John',
                                            'lastName': 'Doe',
                                            'owner': None,
                                            'parentID': None,
                                            'parentType': None,
                                            'password': None,
                                            'role': None,
                                            'userName': None,
                                            'lastUpdatedDate': None
                                        })
        self.assertEquals(to_dict['groups'], [{
                                                'ID': None,
                                                 'creationDate': None,
                                                 'lastUpdatedDate': None,
                                                 'name': 'Admins',
                                                 'owner': None,
                                                 'parentID': None,
                                                 'parentType': None
                                             },
                                             {
                                                'ID': None,
                                                'creationDate': None,
                                                'lastUpdatedDate': None,
                                                'name': 'Others',
                                                'owner': None,
                                                'parentID': None,
                                                'parentType': None
                                            }])
示例#38
0
    def test_get_resource_url(self):
        """ Get user resource url """

        user = User()
        self.assertEquals(user.get_resource_url(), 'https://vsd:8443/api/v3_2/me')