예제 #1
0
파일: tests.py 프로젝트: rahulnij/ohmgear
 def test_create_error(self):
     new_user = User(email='*****@*****.**', password='******')
     new_user.save()
     biz_card = BusinessCard(user_id=new_user)
     biz_card.save()
     with self.assertRaises(ValueError):
         new_contact = Contacts(businesscard_id=biz_card,
                                user_id=new_user.id)
         new_contact.save()
예제 #2
0
파일: tests.py 프로젝트: rahulnij/ohmgear
class TestContactMedia(TestCase):

    def setUp(self):
        self.user = User(
            email="*****@*****.**",
            password="******"
        )
        self.user.save()
        self.biz_card = BusinessCard(user_id=self.user)
        self.biz_card.save()
        self.contact = Contacts(businesscard_id=self.biz_card,
                                user_id=self.user)
        self.contact.save()
예제 #3
0
파일: tests.py 프로젝트: rahulnij/ohmgear
class TestContactModel(TestCase):

    def setUp(self):
        self.user = User(
            email="*****@*****.**",
            password="******"
        )
        self.user.save()
        self.biz_card = BusinessCard(user_id=self.user)
        self.biz_card.save()
        self.contact = Contacts(businesscard_id=self.biz_card,
                                user_id=self.user)
        self.contact.save()

    def test_user_create(self):
        self.assertIsInstance(self.user, User)

    def test_contact_create(self):
        self.assertIsInstance(self.biz_card, BusinessCard)
        contact = Contacts(businesscard_id=self.biz_card)
        # contact.save()
        self.assertIsInstance(contact, Contacts)

    def test_contact_media_create(self):
        contact_media = ContactMedia(user_id=self.user,
                                     contact_id=self.contact,
                                     img_url=create_image_file()
                                     )
        contact_media.save()
        self.assertIsInstance(contact_media, ContactMedia)
        self.assertRegexpMatches(
            contact_media.img_url.url,
            re.compile(r'.*bcards_gallery/*test.*\.png'))

    def test_contact_profile_create(self):
        request = HttpRequest()
        request.user = self.user
        contact_view_set = storeContactsViewSet()
        request.data = {}
        request.data['contact_profile_image'] = create_image_file()
        request.data['contact_id'] = self.contact.id
        request.data['user_id'] = self.contact.id
        response = contact_view_set.upload_contact_profile(request)
        self.assertEqual(response.status_code, 200)

    def test_invalidcontact_profile_create(self):
        request = HttpRequest()
        request.user = self.user
        contact_view_set = storeContactsViewSet()
        request.data = {}
        request.data['contact_profile_image'] = create_image_file()
        request.data['contact_id'] = 5000
        response = contact_view_set.upload_contact_profile(request)
        self.assertEqual(response.status_code, 400, "Invalid Contact id")

    def test_create_error(self):
        new_user = User(email='*****@*****.**', password='******')
        new_user.save()
        biz_card = BusinessCard(user_id=new_user)
        biz_card.save()
        with self.assertRaises(ValueError):
            new_contact = Contacts(businesscard_id=biz_card,
                                   user_id=new_user.id)
            new_contact.save()

    def tearDown(self):
        self.user.delete()
        self.biz_card.delete()
        self.contact.delete()