Best Python code snippet using autotest_python
scheduler_lib_unittest.py
Source: scheduler_lib_unittest.py
1#!/usr/bin/python2#3# Copyright (c) 2014 The Chromium OS Authors. All rights reserved.4# Use of this source code is governed by a BSD-style license that can be5# found in the LICENSE file.6import mock7import unittest8import common9from autotest_lib.database import database_connection10from autotest_lib.frontend import setup_django_environment11from autotest_lib.frontend.afe import readonly_connection12from autotest_lib.server import utils as server_utils13from autotest_lib.scheduler import scheduler_lib14from django.db import utils as django_utils15class ConnectionManagerTests(unittest.TestCase):16 """Connection manager unittests."""17 def setUp(self):18 self.connection_manager = None19 readonly_connection.set_globally_disabled = mock.MagicMock()20 setup_django_environment.enable_autocommit = mock.MagicMock()21 server_utils.Singleton._instances = {}22 def tearDown(self):23 readonly_connection.set_globally_disabled.reset_mock()24 setup_django_environment.enable_autocommit.reset_mock()25 def testConnectionDisconnect(self):26 """Test connection and disconnecting from the database."""27 # Test that the connection manager only opens a connection once.28 connection_manager = scheduler_lib.ConnectionManager()29 connection_manager.open_connection = mock.MagicMock()30 connection = connection_manager.get_connection()31 connection_manager.open_connection.assert_called_once_with()32 connection_manager.open_connection.reset_mock()33 connection = connection_manager.get_connection()34 self.assertTrue(35 connection_manager.open_connection.call_count == 0)36 connection_manager.open_connection.reset_mock()37 # Test that del on the connection manager closes the connection38 connection_manager.disconnect = mock.MagicMock()39 connection_manager.__del__()40 connection_manager.disconnect.assert_called_once_with()41 def testConnectionReconnect(self):42 """Test that retries don't destroy the connection."""43 database_connection._DjangoBackend.execute = mock.MagicMock()44 database_connection._DjangoBackend.execute.side_effect = (45 django_utils.DatabaseError('Database Error'))46 connection_manager = scheduler_lib.ConnectionManager()47 connection = connection_manager.get_connection()48 self.assertRaises(django_utils.DatabaseError,49 connection.execute, *('', None, True))50 self.assertTrue(51 database_connection._DjangoBackend.execute.call_count == 2)52 database_connection._DjangoBackend.execute.reset_mock()53 self.assertTrue(connection_manager.db_connection ==54 connection_manager.get_connection())55 def testConnectionManagerSingleton(self):56 """Test that the singleton works as expected."""57 # Confirm that instantiating the class applies global db settings.58 connection_manager = scheduler_lib.ConnectionManager()59 readonly_connection.set_globally_disabled.assert_called_once_with(True)60 setup_django_environment.enable_autocommit.assert_called_once_with()61 readonly_connection.set_globally_disabled.reset_mock()62 setup_django_environment.enable_autocommit.reset_mock()63 # Confirm that instantiating another connection manager doesn't change64 # the database settings, and in fact, returns the original manager.65 connection_manager_2 = scheduler_lib.ConnectionManager()66 self.assertTrue(connection_manager == connection_manager_2)67 self.assertTrue(68 readonly_connection.set_globally_disabled.call_count == 0)69 self.assertTrue(70 setup_django_environment.enable_autocommit.call_count == 0)71 # Confirm that we don't open the connection when the class is72 # instantiated.73 self.assertTrue(connection_manager.db_connection is None)74if __name__ == '__main__':...
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!!