Esempio n. 1
0
 def setUp(self) -> None:
     self.enterprise_tier = self.create_enterprise_tier()
     self.user = CustomUserFactory(account_tier=self.enterprise_tier)
     self.user_image = UserImageFactory(user=self.user)
     self.permission = HasGenerateLinkPermission()
     self.request = RequestFactory()
     self.request.user = self.user
     self.view = APIView.as_view()
Esempio n. 2
0
 def setUp(self) -> None:
     self.user = CustomUserFactory()
     self.user_image = UserImageFactory(user=self.user)
     self.serializer = TemporaryImageLinkSerializer
     self.data = {'user_image': self.user_image.pk, 'time_expiration': 1234}
     self.request = RequestFactory()
     self.request.user = self.user
Esempio n. 3
0
 def setUp(self) -> None:
     self.basic_tier = self.create_basic_tier()
     self.user = CustomUserFactory(account_tier=self.basic_tier)
     self.url = reverse('detail', args=(self.user.pk, ))
     self.user_image_1 = UserImageFactory(user=self.user,
                                          image__filename='test_1.jpg')
     self.user_image_2 = UserImageFactory(user=self.user,
                                          image__filename='test_2.jpg')
Esempio n. 4
0
 def test_generate_thumbnails(self):
     file_name = 'test_img.jpg'
     # instance is created signal is executed
     user = CustomUserFactory(account_tier=self.create_premium_tier())
     user_image = UserImageFactory(image__witdh=1600, image__height=800, image__filename=file_name, user=user)
     base_dir = os.path.dirname(user_image.image.path)
     for thumbnail in user.account_tier.thumbnails.all():
         file_path = os.path.join(base_dir, thumbnail.thumbnail_prefix + file_name)
         self.assertTrue(os.path.exists(file_path))
Esempio n. 5
0
class HasGenerateLinkPermissionTest(ViewTestMixin, PrepareAccountTierMixin, TestCase):
    def setUp(self) -> None:
        self.enterprise_tier = self.create_enterprise_tier()
        self.user = CustomUserFactory(account_tier=self.enterprise_tier)
        self.user_image = UserImageFactory(user=self.user)
        self.permission = HasGenerateLinkPermission()
        self.request = RequestFactory()
        self.request.user = self.user
        self.view = APIView.as_view()

    def test_has_permission_true(self):
        self.assertTrue(self.permission.has_permission(self.request, self.view))

    def test_has_permission_false(self):
        self.premium_tier = self.create_premium_tier()
        self.user.account_tier = self.premium_tier
        self.user.save()
        self.assertFalse(self.permission.has_permission(self.request, self.view))
Esempio n. 6
0
 def setUp(self) -> None:
     self.user = CustomUserFactory()
     self.image_1 = UserImageFactory()
     self.image_2 = UserImageFactory(user=self.user)
     self.image_3 = UserImageFactory()
     self.request = RequestFactory()
     self.request.user = self.user
     self.queryset = UserImage.objects.all()
     self.user_filtered_primary_key = UserFilteredPrimaryKeyRelatedField(
         queryset=self.queryset)
     self.context = {'request': self.request}
     self.temporary_image_serializer = TemporaryImageLinkSerializer
Esempio n. 7
0
 def setUp(self) -> None:
     self.user_1 = CustomUserFactory()
     self.user_2 = CustomUserFactory()
Esempio n. 8
0
 def test_login_true(self):
     user = CustomUserFactory()
     view_test_mixin = ViewTestMixin()
     view_test_mixin.client = self.client
     view_test_mixin.assertTrue = self.assertTrue
     self.assertIsNone(view_test_mixin.login(user))
Esempio n. 9
0
 def test_user_not_owner(self):
     user = CustomUserFactory()
     self.login(user)
     resp = self.client.get(self.url)
     self.assertEqual(resp.status_code, 403)