How to use is_pinned method in hypothesis

Best Python code snippet using hypothesis

tests.py

Source:tests.py Github

copy

Full Screen

1from django.forms.models import inlineformset_factory2from django.test import TestCase3from factory import DjangoModelFactory, SubFactory, Sequence4from pari.faces.admin import FaceAdmin, FaceImageInline5from pari.faces.forms import FaceImageInlineFormset, FaceForm6from pari.faces.models import FaceImage, Face, District, get_pinned_faces, get_pinned_face_images, \7 get_face_images_by_district_first_letter8from pari.album.tests import ImageCollectionImageFactory9class DistrictFactory(DjangoModelFactory):10 FACTORY_FOR = District11 district = Sequence(lambda n: 'A-{0}'.format(n))12class FaceFactory(DjangoModelFactory):13 FACTORY_FOR = Face14 district = SubFactory(DistrictFactory)15class FaceImageFactory(DjangoModelFactory):16 FACTORY_FOR = FaceImage17 title = 'face image'18 face = SubFactory(FaceFactory)19 description = 'description 1'20 image_collection_image = SubFactory(ImageCollectionImageFactory)21class FaceAdminTest(TestCase):22 def setUp(self):23 self.faceImage = FaceImageFactory()24 self.face = self.faceImage.face25 def setup_formset(self, data, face):26 FaceImageFactoryFormset = inlineformset_factory(Face, FaceImage, formset=FaceImageInlineFormset,27 fields=('image_file', 'is_pinned', 'title', 'description',28 '_order'))29 return FaceImageFactoryFormset(data, prefix='form', instance=face)30 def test_admin_includes_zip_import(self):31 self.assertIn("zip_import", FaceAdmin.fieldsets[0][1]['fields'])32 def test_admin_includes_district(self):33 self.assertIn("district", FaceAdmin.fieldsets[0][1]['fields'])34 def test_admin_includes_faceimage_inline(self):35 self.assertIn(FaceImageInline, FaceAdmin.inlines)36 def test_face_is_invalid_if_image_is_not_uploaded(self):37 data = {38 'form-TOTAL_FORMS': u'1',39 'form-INITIAL_FORMS': u'0',40 'form-MAX_NUM_FORMS': u'',41 'form-0-_order': u'1',42 'form-0-title': u'Image 1',43 'form-0-description': u'Description',44 }45 formset = self.setup_formset(data, self.face)46 self.assertFalse(formset.is_valid())47 keys = [key for errors in formset.errors for key in errors.keys()]48 self.assertTrue(any(keys))49 self.assertIn('image_file', keys)50 def test_face_is_invalid_if_description_is_not_specified(self):51 data = {52 'form-TOTAL_FORMS': u'1',53 'form-INITIAL_FORMS': u'0',54 'form-MAX_NUM_FORMS': u'',55 'form-0-_order': u'1',56 'form-0-title': u'Image 1',57 'form-0-image_file': u'image.jpg'58 }59 formset = self.setup_formset(data, self.face)60 self.assertFalse(formset.is_valid())61 keys = [key for error in formset.errors for key in error.keys()]62 self.assertTrue(any(keys))63 self.assertIn('description', keys)64 def test_face_is_invalid_if_district_is_not_specified(self):65 self.face.district = DistrictFactory(district='')66 face_form = FaceForm(instance=self.face)67 self.assertFalse(face_form.is_valid())68 def test_face_is_valid_if_atleast_one_image_is_uploaded(self):69 data = {70 'form-TOTAL_FORMS': u'1',71 'form-INITIAL_FORMS': u'0',72 'form-MAX_NUM_FORMS': u'',73 'form-0-_order': u'1',74 'form-0-image_file': u'image.jpg',75 'form-0-title': u'Image 1',76 'form-0-description': u'description',77 }78 formset = self.setup_formset(data, self.face)79 self.assertTrue(formset.is_valid())80class FaceTest(TestCase):81 def setUp(self):82 self.face_image = FaceImageFactory()83 self.face = self.face_image.face84 def test_first_letter_of_face(self):85 face = FaceFactory(district=DistrictFactory(district="district"))86 self.assertEquals("d", face.first_letter_of_district())87 def create_face(self, is_pinned=False):88 face = FaceFactory()89 face.is_pinned = is_pinned90 face.save()91 return face92 def create_face_image(self, is_pinned=False):93 face_image = FaceImageFactory()94 face_image.is_pinned = is_pinned95 face_image.save()96 return face_image97 def test_get_pinned_faces(self):98 face1 = self.create_face(is_pinned=True)99 self.create_face(is_pinned=True)100 self.create_face(is_pinned=False)101 self.assertEqual(2, len(get_pinned_faces(face1.first_letter_of_district())))102 def test_get_pinned_face_images(self):103 face_image1 = self.create_face_image(is_pinned=True)104 face_image2 = self.create_face_image(is_pinned=True)105 face_image3 = self.create_face_image(is_pinned=False)106 face = face_image1.face107 face.images.add(face_image2)108 face.images.add(face_image3)109 self.assertEqual(2, len(get_pinned_face_images(face_image2.face)))110 def test_get_face_images_by_district_first_letter(self):111 face_image1 = self.create_face_image()112 face_image2 = self.create_face_image()113 face = face_image1.face114 face.district = DistrictFactory(district='Test District')115 face.images.add(face_image2)116 face.save()...

Full Screen

Full Screen

toggle_chat_is_pinned.py

Source:toggle_chat_is_pinned.py Github

copy

Full Screen

1from ..utils import Object2class ToggleChatIsPinned(Object):3 """4 Changes the pinned state of a chat. You can pin up to GetOption("pinned_chat_count_max")/GetOption("pinned_archived_chat_count_max") non-secret chats and the same number of secret chats in the main/archive chat list 5 Attributes:6 ID (:obj:`str`): ``ToggleChatIsPinned``7 Args:8 chat_id (:obj:`int`):9 Chat identifier 10 is_pinned (:obj:`bool`):11 New value of is_pinned12 Returns:13 Ok14 Raises:15 :class:`telegram.Error`16 """17 ID = "toggleChatIsPinned"18 def __init__(self, chat_id, is_pinned, extra=None, **kwargs):19 self.extra = extra20 self.chat_id = chat_id # int21 self.is_pinned = is_pinned # bool22 @staticmethod23 def read(q: dict, *args) -> "ToggleChatIsPinned":24 chat_id = q.get('chat_id')25 is_pinned = q.get('is_pinned')...

Full Screen

Full Screen

update_chat_is_pinned.py

Source:update_chat_is_pinned.py Github

copy

Full Screen

1from ..utils import Object2class UpdateChatIsPinned(Object):3 """4 A chat was pinned or unpinned 5 Attributes:6 ID (:obj:`str`): ``UpdateChatIsPinned``7 Args:8 chat_id (:obj:`int`):9 Chat identifier 10 is_pinned (:obj:`bool`):11 New value of is_pinned 12 order (:obj:`int`):13 New value of the chat order14 Returns:15 Update16 Raises:17 :class:`telegram.Error`18 """19 ID = "updateChatIsPinned"20 def __init__(self, chat_id, is_pinned, order, **kwargs):21 22 self.chat_id = chat_id # int23 self.is_pinned = is_pinned # bool24 self.order = order # int25 @staticmethod26 def read(q: dict, *args) -> "UpdateChatIsPinned":27 chat_id = q.get('chat_id')28 is_pinned = q.get('is_pinned')29 order = q.get('order')...

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 hypothesis 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