Best Python code snippet using autotest_python
test_module_users.py
Source: test_module_users.py
1''' test module/user '''2import pytest3from models.oauth_db import OAuthDB4from module.users import User5@pytest.fixture(scope='module', params=[None, 'coscup'])6def uid(request):7 ''' uid '''8 return request.param9@pytest.fixture(scope='module', params=[None, 'coscup@coscup.org'])10def mail(request):11 ''' mail '''12 return request.param13class TestUser: # pylint: disable=too-few-public-methods14 ''' Test User '''15 @staticmethod16 def test_init(uid, mail): # pylint: disable=redefined-outer-name17 ''' test init '''18 user = User(uid=uid, mail=mail)19 assert user.uid == uid20 assert user.mail == mail21 @staticmethod22 def test_get():23 ''' Test get '''24 user = User(uid='coscup')25 user.get()26 @staticmethod27 def test_create_and_oauth():28 ''' test create user '''29 _mail = 'coscup@coscup.org'30 with pytest.raises(Exception) as error:31 User.create(mail=_mail)32 assert str(error.value) == f'mail: `{_mail}` not in the oauth dbs'33 OAuthDB().add_data(mail=_mail, data={})34 OAuthDB().find_one_and_update(35 {'_id': _mail}, {'$set': {'owner': '00000000'}})36 with pytest.raises(Exception) as error:37 User.create(mail=_mail)38 assert str(error.value) == f'mail:`{_mail}` already bind'39 @staticmethod40 def test_create_success():41 ''' Test create user success '''42 _mail = 'coscup+success@coscup.org'43 OAuthDB().add_data(mail=_mail, data={})44 created_user = User.create(mail=_mail)45 assert created_user['mail'] == _mail46 @staticmethod47 def test_update_profile():48 ''' Test update profile '''49 _mail = 'coscup+updateprofile@coscup.org'50 OAuthDB().add_data(mail=_mail, data={})51 created_user = User.create(mail=_mail)52 data = {'nickname': 'nick coscup'}53 updated_user = User(uid=created_user['_id']).update_profile(data=data)54 assert updated_user['profile']['nickname'] == 'nick coscup'55 real_data = {'name': 'COSCUP'}56 updated_user = User(57 uid=created_user['_id']).update_profile_real(data=real_data)58 assert updated_user['profile_real']['name'] == 'COSCUP'59 suspend_user = User(uid=created_user['_id']).property_suspend()...
test.py
Source: test.py
1import unittest2import utils3import MailPrototype4from Models import Mail5class TestUtils(unittest.TestCase):6 def test_hash(self):7 self.assertEqual(utils.hash("test-Hash-function"), utils.hash("test-Hash-function"),8 "The result of the hash function is different on same plaintext.")9class TestMail(unittest.TestCase):10 def test_mail_class(self):11 _mail = Mail()12 _mail.setFrom("test@test.com")13 _mail.setTo("tester@test.com")14 _mail.setSubject("TEST")15 _mail.setBody("This is just a test.")16 self.assertEqual(_mail.getFrom(), "test@test.com",17 "Mail._from should be \'test@test.com\'")18 self.assertEqual(_mail.getTo(), "tester@test.com",19 "Mail._to should be \'tester@test.com\'")20 self.assertEqual(_mail.getSubject(), "TEST",21 "Mail._subject should be \'TEST\'")22 self.assertEqual(_mail.getBody(), "This is just a test.",23 "Mail._body should be \'This is just a test.\'")24class TestMailPrototype(unittest.TestCase):25 def test_mailprototype(self):26 _mail = Mail()27 _mail.setFrom("test@test.com")28 _mail.setTo("tester@test.com")29 _mail.setSubject("TEST")30 _mail.setBody("This is just a test.")31 draft_mail = MailPrototype.Draft(_mail)32 forward_mail = MailPrototype.Forward(_mail)33 sent_mail = MailPrototype.Sent(_mail)34 self.assertEqual(draft_mail.clone().getType(),35 "Draft", "Should be of type \'Draft\'.")36 self.assertEqual(forward_mail.clone().getType(),37 "Forward", "Should be of type \'Forward\'.")38 self.assertEqual(sent_mail.clone().getType(),39 "Sent", "Should be of type \'Sent\'.")40if __name__ == '__main__':...
__dispatcher.py
Source: __dispatcher.py
...16 def __init__(self):17 self._outlook = win32.dynamic.Dispatch('Outlook.Application')18 self._mail = None19 def send(self, mail: Mail) -> bool:20 self._create_new_mail(mail)21 try:22 self._mail.Send() 23 return True24 except Exception as e:25 print(e, 'erro send')26 return False27 def preview(self, mail: Mail):28 self._create_new_mail(mail)29 self._mail.Display(True)30 31 def _add_attachments(self, mail: Mail):32 for attach in mail.Attachments:33 if not os.path.isfile(attach):34 raise Exception(f'{attach} It\'s not a valid file')35 self._mail.Attachments.Add(Source=attach)36 37 def _add_copies(self, mail: Mail):38 self._mail.CC = mail.CC39 def _add_signature(self):40 self._mail.GetInspector.Activate()41 42 def _create_new_mail(self, mail: Mail):43 self._mail = self._outlook.CreateItem(0)44 self._mail.Subject = mail.Subject45 self._mail.To = mail.To46 if mail.CC:47 self._add_copies(mail)48 if mail.Signature:49 self._add_signature()50 self._mail.HTMLBody = mail.HTMLBody + self._mail.HTMLBody51 if mail.Attachments:52 self._add_attachments(mail)53 ...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!