示例#1
0
    def test_email_availabilities(self):
        email = '*****@*****.**'

        with self.given('The availability of an email address',
                        '/apiv1/availabilities/emails',
                        'CHECK',
                        form=dict(email=email)):
            assert response.status == 200

            when('Email not contain @', form=Update(email='userexample.com'))
            assert status == '701 Invalid Email Format'

            when('Email not contain dot', form=Update(email='user@examplecom'))
            assert status == '701 Invalid Email Format'

            when('Invalid email format', form=Update(email='@example.com'))
            assert status == '701 Invalid Email Format'

            when('Email not contains any domain', form=Update(email='[email protected]'))
            assert status == '701 Invalid Email Format'

            when('Email address is already registered',
                 form=Update(email='*****@*****.**'))
            assert status == '601 Email Address Is Already Registered'

            when('Request without email parametes', form=Remove('email'))
            assert status == '701 Invalid Email Format'
def test_update_from_fields():
    call = dict(title='test remove form fields',
                url='/apiv1/devices/name: SM-12345678/id: 1',
                verb='POST',
                form=dict(activationCode='746727', email='*****@*****.**'))

    with Given(wsgi_application, **call):
        assert response.status == '200 OK'
        assert response.json == dict(activationCode='746727',
                                     email='*****@*****.**')

        when('Updating email and phone fields',
             form=Update(email='*****@*****.**', phone='+98123456789'))
        assert response.json == dict(activationCode='746727',
                                     phone='+98123456789',
                                     email='*****@*****.**')

        when('Updating only acitvation code',
             form=Update(activationCode='666'))
        assert response.json == dict(activationCode='666',
                                     email='*****@*****.**')

        when('Not updating at all')
        assert response.json == dict(activationCode='746727',
                                     email='*****@*****.**')
    def test_reset_password(self):
        session = self.create_session()
        messanger = create_messenger()
        email = '*****@*****.**'
        password = '******'

        hash_old_password = session.query(Member).one().password

        with self.given('Ask reset password token',
                        '/apiv1/resetpasswordtokens',
                        'ASK',
                        form=dict(email=email)):
            assert status == 200

            task = ResetPasswordEmail.pop()
            task.do_(None)

            reset_password_token =\
                messanger.last_message['body']['reset_password_token']

        with self.given('Reset your CAS account password',
                        '/apiv1/passwords',
                        'RESET',
                        form=dict(password=password,
                                  resetPasswordToken=reset_password_token)):
            assert status == 200

            hash_new_password = session.query(Member).one().password
            assert hash_new_password != hash_old_password

            when('Trying to pass a short password',
                 form=Update(password='******'))
            assert status == '702 Invalid Password Length'

            when('Trying to a pass long password',
                 form=Update(password='******'))
            assert status == '702 Invalid Password Length'

            when('Request without password parameter', form=Remove('password'))
            assert status == '702 Invalid Password Length'

            when('The token has been damaged',
                 form=Update(resetPasswordToken='token'))
            assert status == '611 Malformed Token'

            when('Trying to pass with empty form', form={})
            assert status == '400 Empty Form'
示例#4
0
    def test_title_availabilities(self):
        title = 'nickname_example'

        with self.given('The availability of a tile',
                        '/apiv1/availabilities/nicknames',
                        'CHECK',
                        form=dict(title=title)):
            assert response.status == 200

            when('Title contain @', form=Update(title='nick@name'))
            assert status == '705 Invalid Title Format'

            when('Title is already registered', form=Update(title='username'))
            assert status == '604 Title Is Already Registered'

            when('Request without title parametes', form=Remove('title'))
            assert status == '705 Invalid Title Format'
    def test_ask_reset_password_tokens(self):
        messanger = create_messenger()
        email = '*****@*****.**'

        with self.given('Ask a reset password token',
                        '/apiv1/resetpasswordtokens',
                        'ASK',
                        form=dict(email=email)):
            assert status == 200
            assert response.json['email'] == email

            task = ResetPasswordEmail.pop()
            task.do_(None)

            assert messanger.last_message['to'] == email

            assert settings.reset_password.callback_url == \
                messanger.last_message['body']['reset_password_callback_url']

            assert messanger.last_message['subject'] ==\
                'Reset your CAS account password'

            when('Email not contain @', form=Update(email='userexample.com'))
            assert status == '701 Invalid Email Format'

            when('Email not contain dot', form=Update(email='user@examplecom'))
            assert status == '701 Invalid Email Format'

            when('Invalid email format', form=Update(email='@example.com'))
            assert status == '701 Invalid Email Format'

            when('Email not contains any domain',
                 form=Update(email='[email protected]'))
            assert status == '701 Invalid Email Format'

            when('Email address is already registered',
                 form=Update(email='*****@*****.**'))
            assert status == 200
            assert response.json['email'] == '*****@*****.**'

            when('Request without email parametes',
                 form=given_form - 'email' + dict(a='a'))
            assert status == '701 Invalid Email Format'

            when('Trying to pass with empty form', form={})
            assert status == '400 Empty Form'
    def test_change_password(self):
        session = self.create_session()
        old_password_hash = session.query(Member).one().password

        self.login(email='*****@*****.**',
                   password='******',
                   url='/apiv1/tokens',
                   verb='CREATE')

        with self.given('The password has been successfully changed',
                        '/apiv1/passwords',
                        'change',
                        form=dict(currentPassword='******',
                                  newPassword='******')):
            assert status == 200

            new_password_hash = session.query(Member).one().password
            assert new_password_hash != old_password_hash

            when('Trying to pass using the wrong password',
                 form=Update(currentPassword='******',
                             newPassword='******'))
            assert status == '602 Invalid Current Password'

            when('Trying to pass without current password parameter',
                 form=Remove('currentPassword'))
            assert status == '602 Invalid Current Password'

            when('Trying to pass a simple password',
                 form=Update(newPassword='******'))
            assert status == '703 Password Not Complex Enough'

            when('Trying to pass a short password',
                 form=Update(newPassword='******'))
            assert status == '702 Invalid Password Length'

            when('Trying to pass a long password',
                 form=Update(newPassword='******'))
            assert status == '702 Invalid Password Length'

            when('Trying to pass without new password parameter',
                 form=Remove('newPassword'))
            assert status == '702 Invalid Password Length'

            when('Trying to pass with empty form', form={})
            assert status == '400 Empty Form'
示例#7
0
    def test_claim_email_ownership(self):
        messanger = create_messenger()
        email = '*****@*****.**'

        with self.given('Claim a email',
                        '/apiv1/emails',
                        'CLAIM',
                        form=dict(email=email)):
            assert response.status == 200
            assert 'email' in response.json
            assert response.json['email'] == email

            task = RegisterEmail.pop()
            task.do_(None)

            assert messanger.last_message['to'] == email

            assert settings.registeration.callback_url == \
                messanger.last_message['body']['registeration_callback_url']

            assert messanger.last_message['subject'] == \
                'Register your CAS account'

            when('Email not contain @', form=Update(email='userexample.com'))
            assert status == '701 Invalid Email Format'

            when('Email not contain dot', form=Update(email='user@examplecom'))
            assert status == '701 Invalid Email Format'

            when('Invalid email format', form=Update(email='@example.com'))
            assert status == '701 Invalid Email Format'

            when('Email not contains any domain',
                 form=Update(email='[email protected]'))
            assert status == '701 Invalid Email Format'

            when('Email address is already registered',
                 form=Update(email='*****@*****.**'))
            assert status == '601 Email Address Is Already Registered'

            when('Request without email parametes',
                 form=given_form - 'email' + dict(a='a'))
            assert status == '701 Invalid Email Format'

            when('Trying to pass with empty form', form={})
            assert status == '400 Empty Form'
示例#8
0
    def test_get_user_by_id(self):
        self.login('*****@*****.**')

        with cas_mockup_server(), self.given(
                'Get a user by her or his id',
                '/apiv1/members/id:1',
                'GET',
        ):
            assert status == 200
            assert response.json['title'] == 'user1'

            when('Member not found', url_parameters=Update(id='3'))
            assert status == 404

            when('Ivalid use id', url_parameters=Update(id='user1'))
            assert status == 404

            when('Try to pass unauthorize request', authorization=None)
            assert status == 401
示例#9
0
    def test_create_token(self):
        email = '*****@*****.**'
        password = '******'

        with self.given('Create a login token',
                        '/apiv1/tokens',
                        'CREATE',
                        form=dict(email=email, password=password)):
            assert status == 200
            assert 'token' in response.json

            when('Invalid password', form=Update(password='******'))
            assert status == '603 Incorrect Email Or Password'

            when('Not exist email', form=Update(email='*****@*****.**'))
            assert status == '603 Incorrect Email Or Password'

            when('Invalid email format', form=Update(email='user.com'))
            assert status == '701 Invalid Email Format'

            when('Trying to pass with empty form', form={})
            assert status == '400 Empty Form'
示例#10
0
    def test_update_from_request(self):
        with self.given(
                'Posting a form',
                verb='POST',
                form=dict(
                    title='test',
                    firstName='test',
                    lastName='test',
                    email='*****@*****.**',
                    password='******',
                    birth='2001-01-01',
                    weight=1.1,
                    visible='false',
                    lastLoginTime='2017-10-10T15:44:30.000',
                    isActive=True
                )):
            assert response.json['title'] == 'test'
            assert 'avatar' not in response.json
            assert '_avatar' not in response.json
            assert 'avatarImage' in response.json

            # 400 for sending relationship attribute
            when(
                'Sending a relationship attribute',
                form=Update(email='*****@*****.**', books=[])
            )
            assert status == '200 OK'
            assert {
                'Keywords': [{'id': 2, 'keyword': 'Hello'}],
                'birth': '2001-01-01',
                'books': [],
                'email': '*****@*****.**',
                'firstName': 'test',
                'fullName': 'test test',
                'id': 2,
                'lastName': 'test',
                'title': 'test',
                'weight': '1.1000000000'
            }.items() <= response.json.items()
示例#11
0
    def test_register_member(self):
        messanger = create_messenger()
        email = '*****@*****.**'
        title = 'nickname'
        password = '******'

        with self.given(
            'Claim a email',
            '/apiv1/emails',
            'CLAIM',
            form=dict(email=email)
        ):
            assert status == 200
            assert 'email' in response.json
            assert response.json['email'] == email

            task = RegisterEmail.pop()
            task.do_(None)
            registeration_token = \
                messanger.last_message['body']['registeration_token']

        with self.given(
            'Register a member',
            '/apiv1/members',
            'REGISTER',
            form=dict(
                email=email,
                title=title,
                password=password,
                ownershipToken=registeration_token
            )
        ):
            assert status == 200
            assert response.json['title'] == title
            assert response.json['email'] == email
            assert 'id' in response.json
            assert 'X-New-JWT-Token' in response.headers

            when('Invalid password min length', form=Update(password='******'))
            assert status == '702 Invalid Password Length'

            when(
                'Invalid password max length',
                form=Update(password='******')
            )
            assert status == '702 Invalid Password Length'

            when(
                'Invalid title format',
                form=Update(password='******', title='1username')
            )
            assert status == '705 Invalid Title Format'

            when ('Duplicate title', form=Update(title='username'))
            assert status == '604 Title Is Already Registered'

            when ('Duplicate Email', form=Update(title='user_name'))
            assert status == '601 Email Address Is Already Registered'

            when (
                'The toekn has been damaged',
                form=Update(title='user_name', ownershipToken='token')
            )
            assert status == '611 Malformed Token'

            when('Trying to pass with empty form', form={})
            assert status == '400 Empty Form'