Best Python code snippet using django-test-plus_python
tests.py
Source:tests.py
...30class SearchViewTestCase(TestCase):31 def setUp(self):32 self.client = Client()33 self.factory = RequestFactory()34 def test_get_query(self):35 request = self.factory.get('')36 session = self.client.session37 session['tags'] = [{'name': 'minions',38 'status': 'ready'}]39 session.save()40 request.session = session41 response = SearchView.as_view()(request)42 self.assertEqual(response.status_code, 200)43 def test_post_query(self):44 response = self.client.post('', {'tag': 'minions'})45 self.assertEqual(response.status_code, 200)46class ResultViewTestCase(TestCase):47 def setUp(self):48 self.client = Client()49 def test_get_query(self):50 tag = Tag.objects.get_or_create_tag(name='minions')51 SearchResult.objects.create(tag=tag,52 image_url='https://encrypted-tbn2.'53 'gstatic.com/images?q=tbn:ANd9Gc'54 'TFOtVrw6Lzf-NulP3kmQ5BcTkCnduI'55 'LwZdgpgdW9F2Ty8DXr8mVQ24NwE',56 site='google.com.ua',57 date=datetime.now(),58 rank=1)59 response = self.client.get('/result/?tag=' + tag.name)...
test_autocomplete.py
Source:test_autocomplete.py
...5class OrganisationsAutocompleteTest(TestCase):6 def setUp(self):7 database_population.create_organisation_names()8 self._organisations_autocomplete = OrganisationsAutocomplete(create_field='name')9 def test_get_query(self):10 self._organisations_autocomplete.q = ''11 query_set = self._organisations_autocomplete.get_queryset()12 self.assertEqual(query_set.count(), 2)13 self._organisations_autocomplete.q = 'EPFL'14 query_set = self._organisations_autocomplete.get_queryset()15 self.assertEqual(query_set.count(), 1)16 def test_create_object(self):17 new_organisation = 'this_is_organisation_from_unittest'18 self.assertEqual(OrganisationName.objects.filter(name=new_organisation).count(), 0)19 self._organisations_autocomplete.q = new_organisation20 self._organisations_autocomplete.create_object(new_organisation)21 self.assertEqual(OrganisationName.objects.filter(name=new_organisation).count(), 1)22class KeywordsAutocompleteTest(TestCase):23 def setUp(self):24 database_population.create_keywords()25 self._keywords_autocomplete = KeywordsAutocomplete(create_field='name')26 def test_get_query(self):27 self._keywords_autocomplete.q = ''28 query_set = self._keywords_autocomplete.get_queryset()29 self.assertEqual(query_set.count(), 8)30 self._keywords_autocomplete.q = 'algae'31 query_set = self._keywords_autocomplete.get_queryset()32 self.assertEqual(query_set.count(), 1)33 def test_create_object(self):34 new_keyword = 'this_is_keyword_from_unittest'35 self.assertEqual(Keyword.objects.filter(name=new_keyword).count(), 0)36 self._keywords_autocomplete.q = new_keyword37 self._keywords_autocomplete.create_object(new_keyword)...
test_morningstar.py
Source:test_morningstar.py
...7 morningstar.get_financial_data()8910@pytest.mark.skip()11def test_get_query():12 morningstar._get_query()131415@pytest.mark.skip()16def test_convert_exchange():
...
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!!