Пример #1
0
 def test_list_users(self):
     UserFactory.create_batch(size=10)
     self.client.force_authenticate(self.user)
     response = self.client.get("/api/v1/users/", format="json")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     data = response.json()
     self.assertEqual(1, data["count"])
Пример #2
0
class RestorePasswordAPITests(APITestCase):
    def setUp(self):
        self.user = UserFactory()

    def test_request_restore_code(self):
        self.assertIsNone(self.user.restore_password_code)
        data = {"email": self.user.email}
        response = self.client.post("/api/v1/request_restore_code/",
                                    data=data,
                                    format="json")
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        user = User.objects.get(pk=self.user.pk)
        self.assertIsNotNone(user.restore_password_code)

    def test_restore_password(self):
        self.user.send_restore_code()
        data = {
            "password": "******",
            "repeat_password": "******",
            "restore_password_code": self.user.restore_password_code,
        }
        response = self.client.post("/api/v1/restore_password/",
                                    data=data,
                                    format="json")
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        user = User.objects.get(pk=self.user.pk)
        self.assertTrue(user.check_password(data["password"]))
Пример #3
0
 def test_followed_is_draft(self):
     user = UserFactory()
     CampaignFactory.create_batch(is_draft=True, size=10)
     campaign = CampaignFactory(is_draft=False)
     user.follow(campaign)
     self.client.force_authenticate(user)
     response = self.client.get("/api/v1/campaigns/?is_draft=False",
                                format="json")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     data = response.json()
     self.assertEqual(1, data["count"])
Пример #4
0
 def test_followed_by_filter(self):
     user = UserFactory()
     CampaignFactory.create_batch(size=10)
     campaign = CampaignFactory()
     user.follow(campaign)
     self.client.force_authenticate(user)
     response = self.client.get("/api/v1/campaigns/?followed_by={}".format(
         user.pk),
                                format="json")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     data = response.json()
     self.assertEqual(1, data["count"])
Пример #5
0
class VerifyEmailAPITests(APITestCase):
    def setUp(self):
        self.user = UserFactory()

    def test_request_restore_code(self):
        self.user.is_email_verified = False
        self.user.save()
        self.assertFalse(self.user.is_email_verified)
        data = {"verification_code": self.user.verification_code}
        response = self.client.post("/api/v1/verify_email/",
                                    data=data,
                                    format="json")
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        user = User.objects.get(pk=self.user.pk)
        self.assertTrue(user.is_email_verified)
Пример #6
0
 def test_not_allow_edit_campaign(self):
     campaign = CampaignFactory(user=self.user)
     self.client.force_authenticate(UserFactory())
     data = {"title": "new title"}
     response = self.client.patch("/api/v1/campaigns/{}/".format(
         campaign.pk),
                                  format="json",
                                  data=data)
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Пример #7
0
 def test_follow_campaign(self):
     campaign = CampaignFactory()
     user = UserFactory()
     self.client.force_authenticate(user)
     response = self.client.post("/api/v1/campaigns/{}/follow/".format(
         campaign.pk),
                                 format="json")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     user = User.objects.get(pk=user.pk)
     self.assertEqual(1, user.following.all().count())
Пример #8
0
 def test_purchase_amount_limit(self):
     campaign = CampaignFactory(is_draft=False, funds=100000)
     token = campaign.token
     purchase = Purchase(token=token,
                         amount=token.amount + 1,
                         user=UserFactory())
     try:
         purchase.save()
         raised_exception = False
     except IntegrityError:
         raised_exception = True
     self.assertTrue(raised_exception)
Пример #9
0
 def test_purchase(self):
     campaign = CampaignFactory(is_draft=False, funds=100000)
     token = campaign.token
     purchase = Purchase(token=token,
                         amount=token.amount / 2,
                         user=UserFactory())
     try:
         purchase.save()
         raised_exception = False
     except IntegrityError:
         raised_exception = True
     self.assertFalse(raised_exception)
     self.assertAlmostEqual(purchase.total,
                            token.unit_price * purchase.amount)
Пример #10
0
 def setUp(self):
     self.user = UserFactory()