Best Python code snippet using pytest-django_python
test_offer_views.py
Source:test_offer_views.py
...174 })175 response = offer_views.OfferMetaDataView.as_view()(request)176 self.assertEqual(response.status_code, 302)177 self.assertEqual(response.url, reverse('dashboard:offer-benefit'))178 self.assertJSONEqual(request.session['offer_wizard']['metadata'], {179 'data': {180 'name': 'Test offer',181 'description': 'Test description',182 'offer_type': ConditionalOffer.SITE,183 },184 })185 self.assertJSONEqual(request.session['offer_wizard']['metadata_obj'], [{186 'model': 'offer.conditionaloffer',187 'pk': None,188 'fields': {189 'name': 'Test offer',190 'slug': '',191 'description': 'Test description',192 'offer_type': ConditionalOffer.SITE,193 'exclusive': True,194 'status': ConditionalOffer.OPEN,195 'condition': None,196 'benefit': None,197 'priority': 0,198 'start_datetime': None,199 'end_datetime': None,200 'max_global_applications': None,201 'max_user_applications': None,202 'max_basket_applications': None,203 'max_discount': None,204 'total_discount': '0.00',205 'num_applications': 0,206 'num_orders': 0,207 'redirect_url': '',208 'date_created': None,209 },210 }])211 def test_offer_benefit_view_with_built_in_benefit_type(self):212 range_ = RangeFactory()213 request = RequestFactory().post('/', data={214 'range': range_.pk,215 'type': Benefit.PERCENTAGE,216 'value': 10,217 })218 request.session['offer_wizard'] = {219 'metadata': json.dumps(self.metadata_form_kwargs_session_data),220 'metadata_obj': json.dumps(self.metadata_obj_session_data),221 }222 response = offer_views.OfferBenefitView.as_view()(request)223 self.assertEqual(response.status_code, 302)224 self.assertEqual(response.url, reverse('dashboard:offer-condition'))225 self.assertJSONEqual(request.session['offer_wizard']['metadata'], self.metadata_form_kwargs_session_data)226 self.assertJSONEqual(request.session['offer_wizard']['metadata_obj'], self.metadata_obj_session_data)227 self.assertJSONEqual(request.session['offer_wizard']['benefit'], {228 'data': {229 'range': range_.pk,230 'type': Benefit.PERCENTAGE,231 'value': '10',232 'max_affected_items': None,233 'custom_benefit': '',234 },235 })236 self.assertJSONEqual(request.session['offer_wizard']['benefit_obj'], [{237 'model': 'offer.benefit',238 'pk': None,239 'fields': {240 'range': range_.pk,241 'type': Benefit.PERCENTAGE,242 'value': '10',243 'max_affected_items': None,244 'proxy_class': None,245 },246 }])247 def test_offer_benefit_view_with_custom_benefit_type(self):248 benefit = create_benefit(CustomBenefitModel)249 request = RequestFactory().post('/', data={250 'custom_benefit': benefit.pk,251 })252 request.session['offer_wizard'] = {253 'metadata': json.dumps(self.metadata_form_kwargs_session_data),254 'metadata_obj': json.dumps(self.metadata_obj_session_data),255 }256 response = offer_views.OfferBenefitView.as_view()(request)257 self.assertEqual(response.status_code, 302)258 self.assertEqual(response.url, reverse('dashboard:offer-condition'))259 self.assertJSONEqual(request.session['offer_wizard']['metadata'], self.metadata_form_kwargs_session_data)260 self.assertJSONEqual(request.session['offer_wizard']['metadata_obj'], self.metadata_obj_session_data)261 self.assertJSONEqual(request.session['offer_wizard']['benefit'], {262 'data': {263 'range': None,264 'type': '',265 'value': None,266 'max_affected_items': None,267 'custom_benefit': str(benefit.pk),268 },269 })270 self.assertJSONEqual(request.session['offer_wizard']['benefit_obj'], [{271 'model': 'offer.benefit',272 'pk': benefit.pk,273 'fields': {274 'range': None,275 'type': '',276 'value': None,277 'max_affected_items': None,278 'proxy_class': benefit.proxy_class,279 }280 }])281 def test_offer_condition_view_with_built_in_condition_type(self):282 range_ = RangeFactory()283 request = RequestFactory().post('/', data={284 'range': range_.pk,285 'type': Condition.COUNT,286 'value': 10,287 })288 request.session['offer_wizard'] = {289 'metadata': json.dumps(self.metadata_form_kwargs_session_data),290 'metadata_obj': json.dumps(self.metadata_obj_session_data),291 'benefit': json.dumps(self.benefit_form_kwargs_session_data),292 'benefit_obj': json.dumps(self.benefit_obj_session_data),293 }294 response = offer_views.OfferConditionView.as_view()(request)295 self.assertEqual(response.status_code, 302)296 self.assertEqual(response.url, reverse('dashboard:offer-restrictions'))297 self.assertJSONEqual(request.session['offer_wizard']['metadata'], self.metadata_form_kwargs_session_data)298 self.assertJSONEqual(request.session['offer_wizard']['metadata_obj'], self.metadata_obj_session_data)299 self.assertJSONEqual(request.session['offer_wizard']['benefit'], self.benefit_form_kwargs_session_data)300 self.assertJSONEqual(request.session['offer_wizard']['benefit_obj'], self.benefit_obj_session_data)301 self.assertJSONEqual(request.session['offer_wizard']['condition'], {302 'data': {303 'range': range_.pk,304 'type': Condition.COUNT,305 'value': '10',306 'custom_condition': '',307 },308 })309 self.assertJSONEqual(request.session['offer_wizard']['condition_obj'], [{310 'model': 'offer.condition',311 'pk': None,312 'fields': {313 'range': range_.pk,314 'type': Condition.COUNT,315 'value': '10',316 'proxy_class': None,317 },318 }])319 def test_offer_condition_view_with_custom_condition_type(self):320 condition = create_condition(CustomConditionModel)321 request = RequestFactory().post('/', data={322 'custom_condition': condition.pk,323 })324 request.session['offer_wizard'] = {325 'metadata': json.dumps(self.metadata_form_kwargs_session_data),326 'metadata_obj': json.dumps(self.metadata_obj_session_data),327 'benefit': json.dumps(self.benefit_form_kwargs_session_data),328 'benefit_obj': json.dumps(self.benefit_obj_session_data),329 }330 response = offer_views.OfferConditionView.as_view()(request)331 self.assertEqual(response.status_code, 302)332 self.assertEqual(response.url, reverse('dashboard:offer-restrictions'))333 self.assertJSONEqual(request.session['offer_wizard']['metadata'], self.metadata_form_kwargs_session_data)334 self.assertJSONEqual(request.session['offer_wizard']['metadata_obj'], self.metadata_obj_session_data)335 self.assertJSONEqual(request.session['offer_wizard']['benefit'], self.benefit_form_kwargs_session_data)336 self.assertJSONEqual(request.session['offer_wizard']['benefit_obj'], self.benefit_obj_session_data)337 self.assertJSONEqual(request.session['offer_wizard']['condition'], {338 'data': {339 'range': None,340 'type': '',341 'value': None,342 'custom_condition': str(condition.pk),343 },344 })345 self.assertJSONEqual(request.session['offer_wizard']['condition_obj'], [{346 'model': 'offer.condition',347 'pk': condition.pk,348 'fields': {349 'range': None,350 'type': '',351 'value': None,352 'proxy_class': condition.proxy_class,353 }354 }])355 def test_offer_restrictions_view(self):356 request = RequestFactory().post('/', data={357 'priority': 0,358 })359 request.session['offer_wizard'] = {360 'metadata': json.dumps(self.metadata_form_kwargs_session_data),361 'metadata_obj': json.dumps(self.metadata_obj_session_data),362 'benefit': json.dumps(self.benefit_form_kwargs_session_data),363 'benefit_obj': json.dumps(self.benefit_obj_session_data),364 'condition': json.dumps(self.condition_form_kwargs_session_data),365 'condition_obj': json.dumps(self.condition_obj_session_data),366 }367 response = offer_views.OfferRestrictionsView.as_view()(request)368 offer = ConditionalOffer.objects.get()369 self.assertEqual(response.status_code, 302)370 self.assertEqual(response.url, reverse('dashboard:offer-detail', kwargs={'pk': offer.pk}))371 self.assertEqual([(m.level_tag, str(m.message)) for m in get_messages(request)][0],372 ('success', "Offer '%s' created!" % offer.name))373 self.assertEqual(request.session['offer_wizard'], {})374@freeze_time('2021-04-23 14:00:00')375class TestUpdateOfferWizardStepView(TestCase):376 def setUp(self):377 self.offer = ConditionalOfferFactory()378 self.metadata_form_kwargs_key = 'metadata%s' % self.offer.pk379 self.metadata_obj_key = 'metadata%s_obj' % self.offer.pk380 self.benefit_form_kwargs_key = 'benefit%s' % self.offer.pk381 self.benefit_obj_key = 'benefit%s_obj' % self.offer.pk382 self.condition_form_kwargs_key = 'condition%s' % self.offer.pk383 self.condition_obj_key = 'condition%s_obj' % self.offer.pk384 range_ = RangeFactory()385 self.metadata_form_kwargs_session_data = {386 'data': {387 'name': 'Test offer',388 'slug': self.offer.slug,389 'description': 'Test description',390 'offer_type': ConditionalOffer.VOUCHER,391 'exclusive': True,392 'status': ConditionalOffer.OPEN,393 'condition': self.offer.condition.pk,394 'benefit': self.offer.benefit.pk,395 'priority': 0,396 'start_datetime': None,397 'end_datetime': None,398 'max_global_applications': None,399 'max_user_applications': None,400 'max_basket_applications': None,401 'max_discount': None,402 'total_discount': '0.00',403 'num_applications': 0,404 'num_orders': 0,405 'redirect_url': '',406 'date_created': '2021-04-23T14:00:00Z',407 },408 }409 self.metadata_obj_session_data = [{410 'model': 'offer.conditionaloffer',411 'pk': None,412 'fields': {413 'name': 'Test offer',414 'description': 'Test description',415 'offer_type': ConditionalOffer.VOUCHER,416 },417 }]418 self.benefit_form_kwargs_session_data = {419 'data': {420 'range': range_.pk,421 'type': Benefit.FIXED,422 'value': '2000',423 'max_affected_items': 2,424 'custom_benefit': '',425 },426 }427 self.benefit_obj_session_data = [{428 'model': 'offer.benefit',429 'pk': None,430 'fields': {431 'range': range_.pk,432 'type': Benefit.FIXED,433 'value': '2000',434 'max_affected_items': 2,435 'proxy_class': '',436 },437 }]438 self.condition_form_kwargs_session_data = {439 'data': {440 'range': range_.pk,441 'type': Condition.VALUE,442 'value': '2000',443 'custom_condition': '',444 },445 }446 self.condition_obj_session_data = [{447 'model': 'offer.condition',448 'pk': None,449 'fields': {450 'range': range_.pk,451 'type': Condition.VALUE,452 'value': '2000',453 'proxy_class': '',454 },455 }]456 def test_offer_meta_data_view(self):457 request = RequestFactory().post('/', data={458 'name': 'Test offer',459 'description': 'Test description',460 'offer_type': ConditionalOffer.VOUCHER,461 })462 response = offer_views.OfferMetaDataView.as_view(update=True)(request, pk=self.offer.pk)463 self.assertEqual(response.status_code, 302)464 self.assertEqual(response.url, reverse('dashboard:offer-benefit', kwargs={'pk': self.offer.pk}))465 self.assertJSONEqual(request.session['offer_wizard'][self.metadata_form_kwargs_key], {466 'data': {467 'name': 'Test offer',468 'description': 'Test description',469 'offer_type': ConditionalOffer.VOUCHER,470 },471 })472 self.assertJSONEqual(request.session['offer_wizard'][self.metadata_obj_key], [{473 'model': 'offer.conditionaloffer',474 'pk': self.offer.pk,475 'fields': {476 'name': 'Test offer',477 'slug': self.offer.slug,478 'description': 'Test description',479 'offer_type': ConditionalOffer.VOUCHER,480 'exclusive': True,481 'status': ConditionalOffer.OPEN,482 'condition': self.offer.condition.pk,483 'benefit': self.offer.benefit.pk,484 'priority': 0,485 'start_datetime': None,486 'end_datetime': None,487 'max_global_applications': None,488 'max_user_applications': None,489 'max_basket_applications': None,490 'max_discount': None,491 'total_discount': '0.00',492 'num_applications': 0,493 'num_orders': 0,494 'redirect_url': '',495 'date_created': '2021-04-23T14:00:00Z',496 },497 }])498 def test_offer_benefit_view_with_built_in_benefit_type(self):499 range_ = RangeFactory()500 request = RequestFactory().post('/', data={501 'range': range_.pk,502 'type': Benefit.FIXED,503 'value': 2000,504 })505 request.session['offer_wizard'] = {506 self.metadata_form_kwargs_key: json.dumps(self.metadata_form_kwargs_session_data),507 self.metadata_obj_key: json.dumps(self.metadata_obj_session_data),508 }509 response = offer_views.OfferBenefitView.as_view(update=True)(request, pk=self.offer.pk)510 self.assertEqual(response.status_code, 302)511 self.assertEqual(response.url, reverse('dashboard:offer-condition', kwargs={'pk': self.offer.pk}))512 self.assertJSONEqual(request.session['offer_wizard'][self.metadata_form_kwargs_key],513 self.metadata_form_kwargs_session_data)514 self.assertJSONEqual(request.session['offer_wizard'][self.metadata_obj_key], self.metadata_obj_session_data)515 self.assertJSONEqual(request.session['offer_wizard'][self.benefit_form_kwargs_key], {516 'data': {517 'range': range_.pk,518 'type': Benefit.FIXED,519 'value': '2000',520 'max_affected_items': None,521 'custom_benefit': '',522 },523 })524 self.assertJSONEqual(request.session['offer_wizard'][self.benefit_obj_key], [{525 'model': 'offer.benefit',526 'pk': self.offer.benefit.pk,527 'fields': {528 'range': range_.pk,529 'type': Benefit.FIXED,530 'value': '2000',531 'max_affected_items': None,532 'proxy_class': '',533 },534 }])535 def test_offer_benefit_view_with_custom_benefit_type(self):536 benefit = create_benefit(CustomBenefitModel)537 request = RequestFactory().post('/', data={538 'custom_benefit': benefit.pk,539 })540 request.session['offer_wizard'] = {541 self.metadata_form_kwargs_key: json.dumps(self.metadata_form_kwargs_session_data),542 self.metadata_obj_key: json.dumps(self.metadata_obj_session_data),543 }544 response = offer_views.OfferBenefitView.as_view(update=True)(request, pk=self.offer.pk)545 self.assertEqual(response.status_code, 302)546 self.assertEqual(response.url, reverse('dashboard:offer-condition', kwargs={'pk': self.offer.pk}))547 self.assertJSONEqual(request.session['offer_wizard'][self.metadata_form_kwargs_key],548 self.metadata_form_kwargs_session_data)549 self.assertJSONEqual(request.session['offer_wizard'][self.metadata_obj_key], self.metadata_obj_session_data)550 self.assertJSONEqual(request.session['offer_wizard'][self.benefit_form_kwargs_key], {551 'data': {552 'range': None,553 'type': '',554 'value': None,555 'max_affected_items': None,556 'custom_benefit': str(benefit.pk),557 },558 })559 self.assertJSONEqual(request.session['offer_wizard'][self.benefit_obj_key], [{560 'model': 'offer.benefit',561 'pk': benefit.pk,562 'fields': {563 'range': None,564 'type': '',565 'value': None,566 'max_affected_items': None,567 'proxy_class': benefit.proxy_class,568 }569 }])570 def test_offer_condition_view_with_built_in_condition_type(self):571 range_ = RangeFactory()572 request = RequestFactory().post('/', data={573 'range': range_.pk,574 'type': Condition.VALUE,575 'value': 2000,576 })577 request.session['offer_wizard'] = {578 self.metadata_form_kwargs_key: json.dumps(self.metadata_form_kwargs_session_data),579 self.metadata_obj_key: json.dumps(self.metadata_obj_session_data),580 self.benefit_form_kwargs_key: json.dumps(self.benefit_form_kwargs_session_data),581 self.benefit_obj_key: json.dumps(self.benefit_obj_session_data),582 }583 response = offer_views.OfferConditionView.as_view(update=True)(request, pk=self.offer.pk)584 self.assertEqual(response.status_code, 302)585 self.assertEqual(response.url, reverse('dashboard:offer-restrictions', kwargs={'pk': self.offer.pk}))586 self.assertJSONEqual(request.session['offer_wizard'][self.metadata_form_kwargs_key],587 self.metadata_form_kwargs_session_data)588 self.assertJSONEqual(request.session['offer_wizard'][self.metadata_obj_key], self.metadata_obj_session_data)589 self.assertJSONEqual(request.session['offer_wizard'][self.benefit_form_kwargs_key],590 self.benefit_form_kwargs_session_data)591 self.assertJSONEqual(request.session['offer_wizard'][self.benefit_obj_key], self.benefit_obj_session_data)592 self.assertJSONEqual(request.session['offer_wizard'][self.condition_form_kwargs_key], {593 'data': {594 'range': range_.pk,595 'type': Condition.VALUE,596 'value': '2000',597 'custom_condition': '',598 },599 })600 self.assertJSONEqual(request.session['offer_wizard'][self.condition_obj_key], [{601 'model': 'offer.condition',602 'pk': self.offer.condition.pk,603 'fields': {604 'range': range_.pk,605 'type': Condition.VALUE,606 'value': '2000',607 'proxy_class': '',608 },609 }])610 def test_offer_condition_view_with_custom_condition_type(self):611 condition = create_condition(CustomConditionModel)612 request = RequestFactory().post('/', data={613 'custom_condition': condition.pk,614 })615 request.session['offer_wizard'] = {616 self.metadata_form_kwargs_key: json.dumps(self.metadata_form_kwargs_session_data),617 self.metadata_obj_key: json.dumps(self.metadata_obj_session_data),618 self.benefit_form_kwargs_key: json.dumps(self.benefit_form_kwargs_session_data),619 self.benefit_obj_key: json.dumps(self.benefit_obj_session_data),620 }621 response = offer_views.OfferConditionView.as_view(update=True)(request, pk=self.offer.pk)622 self.assertEqual(response.status_code, 302)623 self.assertEqual(response.url, reverse('dashboard:offer-restrictions', kwargs={'pk': self.offer.pk}))624 self.assertJSONEqual(request.session['offer_wizard'][self.metadata_form_kwargs_key],625 self.metadata_form_kwargs_session_data)626 self.assertJSONEqual(request.session['offer_wizard'][self.metadata_obj_key], self.metadata_obj_session_data)627 self.assertJSONEqual(request.session['offer_wizard'][self.benefit_form_kwargs_key],628 self.benefit_form_kwargs_session_data)629 self.assertJSONEqual(request.session['offer_wizard'][self.benefit_obj_key], self.benefit_obj_session_data)630 self.assertJSONEqual(request.session['offer_wizard'][self.condition_form_kwargs_key], {631 'data': {632 'range': None,633 'type': '',634 'value': None,635 'custom_condition': str(condition.pk),636 },637 })638 self.assertJSONEqual(request.session['offer_wizard'][self.condition_obj_key], [{639 'model': 'offer.condition',640 'pk': condition.pk,641 'fields': {642 'range': None,643 'type': '',644 'value': None,645 'proxy_class': condition.proxy_class,646 }647 }])648 def test_offer_restrictions_view(self):649 request = RequestFactory().post('/', data={650 'priority': 0,651 })652 request.session['offer_wizard'] = {...
test_related.py
Source:test_related.py
...56 self.assertEqual(response.status_code, 403)57 self.client.login(username="Superuser001", password="superuser001")58 response = self.client.get(reverse("grp_related_lookup"))59 self.assertEqual(response.status_code, 200)60 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": None, "label": ""}])61 # ok62 response = self.client.get("%s?object_id=1&app_label=%s&model_name=%s" % (reverse("grp_related_lookup"), "grappelli", "category"))63 self.assertEqual(response.status_code, 200)64 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "1", "label": "Category No 0 (1)"}])65 # wrong object_id66 response = self.client.get("%s?object_id=10000&app_label=%s&model_name=%s" % (reverse("grp_related_lookup"), "grappelli", "category"))67 self.assertEqual(response.status_code, 200)68 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "10000", "label": "?"}])69 # filtered queryset (single filter) fails70 response = self.client.get("%s?object_id=1&app_label=%s&model_name=%s&query_string=id__gte=99" % (reverse("grp_related_lookup"), "grappelli", "category"))71 self.assertEqual(response.status_code, 200)72 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "1", "label": "?"}])73 # filtered queryset (single filter) works74 response = self.client.get("%s?object_id=100&app_label=%s&model_name=%s&query_string=id__gte=99" % (reverse("grp_related_lookup"), "grappelli", "category"))75 self.assertEqual(response.status_code, 200)76 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "100", "label": "Category No 99 (100)"}])77 # filtered queryset (multiple filters) fails78 response = self.client.get("%s?object_id=1&app_label=%s&model_name=%s&query_string=name__icontains=99:id__gte=99" % (reverse("grp_related_lookup"), "grappelli", "category"))79 self.assertEqual(response.status_code, 200)80 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "1", "label": "?"}])81 # filtered queryset (multiple filters) works82 response = self.client.get("%s?object_id=100&app_label=%s&model_name=%s&query_string=name__icontains=99:id__gte=99" % (reverse("grp_related_lookup"), "grappelli", "category"))83 self.assertEqual(response.status_code, 200)84 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "100", "label": "Category No 99 (100)"}])85 # custom queryset (Superuser)86 response = self.client.get("%s?object_id=1&app_label=%s&model_name=%s" % (reverse("grp_related_lookup"), "grappelli", "entry"))87 self.assertEqual(response.status_code, 200)88 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "1", "label": "Entry Superuser"}])89 response = self.client.get("%s?object_id=2&app_label=%s&model_name=%s" % (reverse("grp_related_lookup"), "grappelli", "entry"))90 self.assertEqual(response.status_code, 200)91 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "2", "label": "Entry Editor"}])92 # custom queryset (Editor)93 # FIXME: this should fail, because the custom admin queryset94 # limits the entry to the logged in user (but we currently do not make use95 # of custom admin querysets)96 self.client.login(username="Editor001", password="editor001")97 response = self.client.get("%s?object_id=1&app_label=%s&model_name=%s" % (reverse("grp_related_lookup"), "grappelli", "entry"))98 self.assertEqual(response.status_code, 200)99 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "1", "label": "Entry Superuser"}])100 # wrong app_label/model_name101 response = self.client.get("%s?object_id=1&app_label=false&model_name=false" % (reverse("grp_related_lookup")))102 self.assertEqual(response.status_code, 200)103 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": None, "label": ""}])104 response = self.client.get("%s?object_id=&app_label=false&model_name=false" % (reverse("grp_related_lookup")))105 self.assertEqual(response.status_code, 200)106 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": None, "label": ""}])107 def test_m2m_lookup(self):108 """109 Test M2M lookup110 """111 self.client.login(username="User001", password="user001")112 response = self.client.get(reverse("grp_related_lookup"))113 self.assertEqual(response.status_code, 403)114 self.client.login(username="Superuser001", password="superuser001")115 response = self.client.get(reverse("grp_related_lookup"))116 self.assertEqual(response.status_code, 200)117 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": None, "label": ""}])118 # ok (single)119 response = self.client.get("%s?object_id=1&app_label=%s&model_name=%s" % (reverse("grp_m2m_lookup"), "grappelli", "category"))120 self.assertEqual(response.status_code, 200)121 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "1", "label": "Category No 0 (1)"}])122 # wrong object_id (single)123 response = self.client.get("%s?object_id=10000&app_label=%s&model_name=%s" % (reverse("grp_m2m_lookup"), "grappelli", "category"))124 self.assertEqual(response.status_code, 200)125 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "10000", "label": "?"}])126 # ok (multiple)127 response = self.client.get("%s?object_id=1,2,3&app_label=%s&model_name=%s" % (reverse("grp_m2m_lookup"), "grappelli", "category"))128 self.assertEqual(response.status_code, 200)129 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "1", "label": "Category No 0 (1)"}, {"value": "2", "label": "Category No 1 (2)"}, {"value": "3", "label": "Category No 2 (3)"}])130 # wrong object_id (multiple)131 response = self.client.get("%s?object_id=1,10000,3&app_label=%s&model_name=%s" % (reverse("grp_m2m_lookup"), "grappelli", "category"))132 self.assertEqual(response.status_code, 200)133 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "1", "label": "Category No 0 (1)"}, {"value": "10000", "label": "?"}, {"value": "3", "label": "Category No 2 (3)"}])134 # filtered queryset (single filter) fails135 response = self.client.get("%s?object_id=1,2,3&app_label=%s&model_name=%s&query_string=id__gte=99" % (reverse("grp_m2m_lookup"), "grappelli", "category"))136 self.assertEqual(response.status_code, 200)137 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "1", "label": "?"}, {"value": "2", "label": "?"}, {"value": "3", "label": "?"}])138 # filtered queryset (single filter) works139 response = self.client.get("%s?object_id=1,2,3&app_label=%s&model_name=%s&query_string=id__lte=3" % (reverse("grp_m2m_lookup"), "grappelli", "category"))140 self.assertEqual(response.status_code, 200)141 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "1", "label": "Category No 0 (1)"}, {"value": "2", "label": "Category No 1 (2)"}, {"value": "3", "label": "Category No 2 (3)"}])142 # filtered queryset (multiple filters) fails143 response = self.client.get("%s?object_id=1,2,3&app_label=%s&model_name=%s&query_string=name__icontains=99:id__gte=99" % (reverse("grp_m2m_lookup"), "grappelli", "category"))144 self.assertEqual(response.status_code, 200)145 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "1", "label": "?"}, {"value": "2", "label": "?"}, {"value": "3", "label": "?"}])146 # filtered queryset (multiple filters) works147 response = self.client.get("%s?object_id=1,2,3&app_label=%s&model_name=%s&query_string=name__icontains=Category:id__lte=3" % (reverse("grp_m2m_lookup"), "grappelli", "category"))148 self.assertEqual(response.status_code, 200)149 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": "1", "label": "Category No 0 (1)"}, {"value": "2", "label": "Category No 1 (2)"}, {"value": "3", "label": "Category No 2 (3)"}])150 def test_autocomplete_lookup(self):151 """152 Test autocomplete lookup153 """154 self.client.login(username="User001", password="user001")155 response = self.client.get(reverse("grp_related_lookup"))156 self.assertEqual(response.status_code, 403)157 self.client.login(username="Superuser001", password="superuser001")158 response = self.client.get(reverse("grp_related_lookup"))159 self.assertEqual(response.status_code, 200)160 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": None, "label": ""}])161 # term not found162 response = self.client.get("%s?term=XXXXXXXXXX&app_label=%s&model_name=%s" % (reverse("grp_autocomplete_lookup"), "grappelli", "category"))163 self.assertEqual(response.status_code, 200)164 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": None, "label": "0 results"}])165 # ok (99 finds the id and the title, therefore 2 results)166 response = self.client.get("%s?term=Category No 99&app_label=%s&model_name=%s" % (reverse("grp_autocomplete_lookup"), "grappelli", "category"))167 self.assertEqual(response.status_code, 200)168 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": 99, "label": "Category No 98 (99)"}, {"value": 100, "label": "Category No 99 (100)"}])169 # filtered queryset (single filter)170 response = self.client.get("%s?term=Category&app_label=%s&model_name=%s&query_string=id__gte=99" % (reverse("grp_autocomplete_lookup"), "grappelli", "category"))171 self.assertEqual(response.status_code, 200)172 self.assertJSONEqual(response.content.decode('utf-8'), [{"value": 99, "label": "Category No 98 (99)"}, {"value": 100, "label": "Category No 99 (100)"}])173 # filtered queryset (multiple filters)174 response = self.client.get("%s?term=Category&app_label=%s&model_name=%s&query_string=name__icontains=99:id__gte=99" % (reverse("grp_autocomplete_lookup"), "grappelli", "category"))175 self.assertEqual(response.status_code, 200)...
test_serialisers.py
Source:test_serialisers.py
...82 self.assertEquals(serialisers.int_or_float("Not a number"), "-")83 def testSerialiseIngredient(self):84 ingredient = models.Ingredient.objects.all()[0]85 js = serialisers.serialize_ingredient(ingredient, 200) 86 self.assertJSONEqual(json.dumps(js), ingredient1_json)87 88 def testSerialiseProduct(self):89 product = models.Product.objects.all()[0]90 js = serialisers.serialize_product(product) 91 self.assertJSONEqual(json.dumps(js), product1_json)92 def testSerialiseProductAPIV3(self):93 product = models.Product.objects.all()[0]94 js = serialisers.serialize_product_apiv3(product) 95 self.assertJSONEqual(json.dumps(js), product1_apiv3_json)96 def testSerialiseProductAPIV3WithCopayments(self):97 product = models.Product.objects.all()[2]98 js = serialisers.serialize_product_apiv3(product) 99 copayments = [{'formulary': 'Formulary1', 'copayment': 44.61999999999999}]100 self.assertEquals(js["copayments"], copayments)101 def testSerialiseProducts(self):102 products = models.Product.objects.all()103 js = serialisers.serialize_products(products) 104 self.assertEquals(len(js), 3)105 self.assertJSONEqual(json.dumps(js[0]), product1_json)106 def testSerialiseProductLite(self):107 product = models.Product.objects.all()[0]108 js = serialisers.serialize_product_lite(product) 109 self.assertJSONEqual(json.dumps(js), product1_lite_json)110 def testSerialiseProductsLite(self):111 products = models.Product.objects.all()112 self.assertEquals(products.count(), 3)113 js = serialisers.serialize_products_lite(products) 114 self.assertEquals(len(js), 3)...
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!!