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_remove_headers_field(): with Given(wsgi_application, 'test remove header field', headers={'header1': '1'}): assert status == '200 OK' assert response.json['header1'] == '1' when('Removing an existing header: 2-tuple', headers=Remove(('header1', '1'))) assert 'header1' not in response.json when('Remove header by key', headers=Remove('header1')) # Remove an invalid header(Not exists) with pytest.raises(ValueError): when('Invalid key', headers=Remove('invalid header'))
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'
def test_remove_from_fields(): call = dict(title='test remove form fields', url='/apiv1/devices/name: SM-12345678/id: 1', verb='POST', form=dict(activationCode='746727', phone='+9897654321', email='*****@*****.**')) with Given(wsgi_application, **call): assert response.status == '200 OK' when('Removing fields', form=Remove('email', 'phone')) assert response.json == dict(activationCode='746727') with pytest.raises(ValueError): Remove('a').apply(['b', 'c']) with pytest.raises(ValueError): Remove('a').apply({'b': 'c'})
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'
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'