How to use assert_objects method in localstack

Best Python code snippet using localstack_python

test_controlpanel_api.py

Source:test_controlpanel_api.py Github

copy

Full Screen

...10from apps.billing.models import PricingPlan, Subscription11from apps.core.tests.mixins import CleanupTestCaseMixin12class AdminListViewTestCase(CleanupTestCaseMixin, APITestCase):13 url = reverse('v1:cp-admin-list')14 def assert_objects(self, data):15 self.assertTrue('objects' in data)16 self.assertTrue(len(data['objects']) > 0)17 def setUp(self):18 self.admin = G(Admin, email='john@doe.com', is_active=True,19 first_name='John', last_name='Doe', is_staff=True)20 self.admin.set_password('test')21 self.admin.save()22 self.apikey = self.admin.key23 self.client.defaults['HTTP_X_API_KEY'] = self.apikey24 def test_get_returns_200(self):25 response = self.client.get(self.url)26 self.assertEqual(response.status_code, status.HTTP_200_OK)27 def test_get_return_403_for_unauthorized_admin(self):28 invalid_admin = G(Admin, email='invalid@doe.com', is_active=True,29 is_staff=False)30 invalid_admin.set_password('test')31 invalid_admin.save()32 self.client.defaults['HTTP_X_API_KEY'] = invalid_admin.key33 response = self.client.get(self.url)34 self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)35 def test_get_return_403_for_anonymous_access(self):36 del self.client.defaults['HTTP_X_API_KEY']37 response = self.client.get(self.url)38 self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)39 def test_email_filter(self):40 E = 'jo'41 response = self.client.get(self.url, {'email': E})42 data = response.data43 self.assert_objects(data)44 self.assertFalse(any(x for x in data['objects']45 if not x['email'].lower().startswith(E)))46 def test_first_name_filter(self):47 F = 'John'48 response = self.client.get(self.url, {'first_name': F})49 data = response.data50 self.assert_objects(data)51 self.assertFalse(any(x for x in data['objects']52 if x['first_name'] != F))53 def test_last_name_filter(self):54 L = 'Doe'55 response = self.client.get(self.url, {'last_name': L})56 data = response.data57 self.assert_objects(data)58 self.assertFalse(any(x for x in data['objects']59 if x['last_name'] != L))60 def test_multi_filter(self):61 F, L = 'John', 'Doe'62 response = self.client.get(self.url, {'first_name': F,63 'last_name': L})64 data = response.data65 self.assert_objects(data)66 self.assertFalse(any(x for x in data['objects']67 if (x['first_name'], x['last_name']) != (F, L)))68 def test_list_returns_key(self):69 response = self.client.get(self.url, {'email': self.admin.email})70 self.assertIn(self.apikey, [x['key'] for x in response.data['objects']])71class AdminExtendPlanTestCase(CleanupTestCaseMixin, APITestCase):72 def setUp(self):73 self.admin = G(Admin, email='john@doe.com', is_active=True,74 first_name='John', last_name='Doe', is_staff=True)75 self.admin.save()76 self.apikey = self.admin.key77 self.url = reverse('v1:cp-admin-extend-builder-plan', args=(self.admin.id,))78 self.client.defaults['HTTP_X_API_KEY'] = self.apikey79 def test_extending_non_builder_plan(self):...

Full Screen

Full Screen

test_setup_league.py

Source:test_setup_league.py Github

copy

Full Screen

2from leagues.models import League, Season3class SetupTest(IntegrationTestCase):4 def test__setup__mvl_2016(self):5 self.assert_command('setup', '-a', 35, '-d', 35, '-s', 2016, '-l', 21666)6 season = self.assert_objects(Season)7 self.assertEqual(season.start_year, 2016)8 league = self.assert_objects(League)9 self.assertEqual(league.name, "Verbandsliga Männer")10 self.assertEqual(league.abbreviation, "M-VL")11 self.assertEqual(league.bhv_id, 21666)12 self.assertEqual(league.season, season)13 def test__setup__mvl_2017(self):14 self.assert_command('setup', '-a', 35, '-d', 35, '-s', 2017, '-l', 26777)15 season = self.assert_objects(Season)16 self.assertEqual(season.start_year, 2017)17 league = self.assert_objects(League)18 self.assertEqual(league.name, "Verbandsliga Männer")19 self.assertEqual(league.abbreviation, "M-VL")20 self.assertEqual(league.bhv_id, 26777)21 self.assertEqual(league.season, season)22 def test__setup__mwls_2016(self):23 self.assert_command('setup', '-a', 3, '-d', 3, '-s', 2016, '-l', 21747)24 season = self.assert_objects(Season)25 self.assertEqual(season.start_year, 2016)26 league = self.assert_objects(League)27 self.assertEqual(league.name, "Männer Württemberg-Liga Süd")28 self.assertEqual(league.abbreviation, "M-WL-S")29 self.assertEqual(league.bhv_id, 21747)30 self.assertEqual(league.season, season)31 def test__setup__mwls_2017(self):32 self.assert_command('setup', '-a', 3, '-d', 3, '-s', 2017, '-l', 27505)33 season = self.assert_objects(Season)34 self.assertEqual(season.start_year, 2017)35 league = self.assert_objects(League)36 self.assertEqual(league.name, "Männer Württemberg-Liga Süd")37 self.assertEqual(league.abbreviation, "M-WL-S")38 self.assertEqual(league.bhv_id, 27505)39 self.assertEqual(league.season, season)40 def test__setup__mklc2_2007(self):41 self.assert_command('setup', '-a', 3, '-d', 7, '-s', 2007, '-l', 7423, 7424)42 self.assert_objects(League, count=2)43 mklc2 = League.objects.get(abbreviation="M-KLC-2")44 mklc3 = League.objects.get(abbreviation="M-KLC-3")45 self.assertEqual(mklc2.name, "Männer Kreisliga C Staffel 2")46 self.assertEqual(mklc3.name, "Männer Kreisliga C Staffel 3")47 def test__setup__mkl2_2005(self):48 self.assert_command('setup', '-a', 3, '-d', 10, '-s', 2005, '-l', 5380, 5381)49 self.assert_objects(League, count=2)50 mkl21 = League.objects.get(abbreviation="M-KL2-1")51 mkl22 = League.objects.get(abbreviation="M-KL2-2")52 self.assertEqual(mkl21.name, "Männer Kreisliga 2-1")53 self.assertEqual(mkl22.name, "Männer Kreisliga 2-2")54class Youth(IntegrationTestCase):55 def test_youth(self):56 self.assert_command('setup', '-a', 35, '-d', 35, '-s', 2019, '-l', 46921, '--youth')57 league: League = self.assert_objects(League)58 self.assertTrue(league.youth)59 def test_no_youth(self):60 self.assert_command('setup', '-a', 35, '-d', 35, '-s', 2019, '-l', 46921)61 self.assert_objects(League, count=0)62class LongLeagueNames(IntegrationTestCase):63 def test_youth(self):64 self.assert_command('setup', '-a', 83, '-d', 83, '-s', 2019, '-l', 45646, 45651, '--youth')65 leagues = self.assert_objects(League, count=2).order_by('name')66 self.assertEqual(leagues[0].name, 'männliche Jgd. B - Kreisklasse')67 self.assertEqual(leagues[1].name, 'männliche Jgd. B - Rheinhessenliga')68class Pokal(IntegrationTestCase):69 def test_fpokk_2019(self):70 self.assert_command('setup', '-a', 56, '-d', 62, '-s', 2019, '-l', 45411)...

Full Screen

Full Screen

test_import_games.py

Source:test_import_games.py Github

copy

Full Screen

...5from leagues.tests.integration import test_setup_league6class ImportGamesTest(IntegrationTestCase):7 def test__import_games__specific_game(self):8 self.assert_command('setup', '-a', 35, '-d', 35, '-s', 2017, '-l', 26777)9 league = self.assert_objects(League)10 self.assert_command('import_games', '-g', 210226)11 game = self.assert_objects(Game)12 self.assertEqual(game.number, 210226)13 self.assertEqual(game.opening_whistle, datetime.datetime(2017, 10, 7, 19, 45))14 self.assertEqual(game.home_team.short_name, 'TSVG Malsch')15 self.assertEqual(game.guest_team.short_name, 'HSG Dittig/TBB')16 self.assertEqual(game.home_goals, 24)17 self.assertEqual(game.guest_goals, 22)18 self.assertEqual(game.report_number, 490394)19 self.assertEqual(game.sports_hall.number, 22010)20 self.assertEqual(game.league, league)21 def test__import_games__m_vl(self):22 self.assert_command('setup', '-a', 35, '-d', 35, '-s', 2017, '-l', 26777)23 self.assert_objects(League)24 self.assert_command('import_games')25 self.assert_objects(Game, 182)26 def test__import_games__missing_district(self):27 self.assert_command('import_games', '-a', 35, '-d', 0)28 self.assert_objects(Game, 0)29 def test__import_games__m_vl__multiseason(self):30 self.assert_command('setup', '-a', 35, '-d', 35, '-s', 2017, 2018, '-l', 26777, 34606)31 self.assert_objects(Season, count=2)32 leagues = self.assert_objects(League, count=2)33 self.assert_command('import_games')34 for league in leagues:35 self.assertGreater(league.game_set.count(), 0, msg="league without games: {}".format(league))36class Forfeit(IntegrationTestCase):37 def test_forfeit_with_report(self):38 self.assert_command('setup', '-a', 3, '-d', 10, '-s', 2018, '-l', 35537)39 self.assert_command('import_games', '-g', 60201)40 game: Game = self.assert_objects(Game)41 self.assertEqual(game.number, 60201)42 self.assertEqual(game.report_number, 710203)43 self.assertEqual(game.home_goals, 0)44 self.assertEqual(game.guest_goals, 0)45 self.assertEqual(game.forfeiting_team, game.guest_team)46 def test_forfeit_without_report(self):47 self.assert_command('setup', '-a', 35, '-d', 35, '-s', 2018, '-l', 34606)48 self.assert_command('import_games', '-g', 210348)49 game: Game = self.assert_objects(Game)50 self.assertEqual(game.number, 210348)51 self.assertEqual(game.report_number, None)52 self.assertEqual(game.home_goals, 0)53 self.assertEqual(game.guest_goals, 0)54 self.assertEqual(game.forfeiting_team, game.guest_team)55class Youth(IntegrationTestCase):56 def test_youth(self):57 test_setup_league.Youth.test_youth(self)58 self.assert_command('import_games', '--youth')59 league: League = self.assert_objects(League)60 self.assertGreater(league.game_set.count(), 0)61 def test_no_youth(self):62 test_setup_league.Youth.test_youth(self)63 self.assert_command('import_games')64 self.assert_objects(Game, count=0)65class BuggedGameRows(IntegrationTestCase):66 def test_additional_heading_row(self):67 self.assert_command('setup', '-a', 3, '-d', 8, '-s', 2019, '-l', 46786)68 self.assert_command('import_games', '-g', 41013)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful