示例#1
0
 def test_post_list(self):
     urls = reverse("post-list")
     response = self.e.get(urls, content_type="application/json")
     writeTest("- Post List: \n")
     if len(response.data) < 3:
         writeTest(str(response.data))
     else:
         writeTest(str(response.data[0:1]))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     logger.info("Post List")
示例#2
0
 def test_usr_list(self):
     urls = reverse("user-list")
     response = self.e.get(urls, content_type="application/json")
     writeTest("- User List: \n")
     if len(response.data) < 1:
         writeTest(str(response.data))
     else:
         writeTest(str(response.data[0:1]))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.status_code, status.HTTP_404_NOT_FOUND)
     logger.info("User List")
示例#3
0
 def test_usr_generic_list(self):
     urls = reverse("user-generic-list")
     self.e.credentials(HTTP_AUTHORIZATION="Bearer " + readme)
     response = self.e.get(urls, content_type="application/json")
     writeTest("- User List Generics : \n")
     writeTest(str(response.data[0:2]))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.data, None)
     logger.info("User List Generics")
示例#4
0
 def test_usr_verify(self):
     urls = reverse("authtoken-verify")
     data = json.dumps({"token": readme})
     response = self.e.post(urls, data, content_type="application/json")
     writeTest("- Verify Token : \n")
     writeTest(str(response.data))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.data, None)
     logger.info("Verify Token")
示例#5
0
 def test_post_detail(self):
     post = Post.objects.last()
     urls = reverse("post-detail", args=[post.public_id])
     response = self.e.get(urls, content_type="application/json")
     writeTest("- Post Detail: \n")
     writeTest(str(response.data))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.status_code, status.HTTP_404_NOT_FOUND)
     logger.info("Post Detail")
示例#6
0
 def test_usr_reset(self):
     user = User.objects.last()
     urls = reverse("user-reset")
     data = json.dumps({"token": user.email})
     response = self.e.post(urls, data, content_type="application/json")
     writeTest("- User Reset : \n")
     writeTest(str(response.data))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.data, None)
     logger.info("User Reset")
示例#7
0
 def test_usr_detail(self):
     user = User.objects.filter(first_name__gt=1).first()
     urls = reverse("user-detail", args=[user.id])
     self.e.credentials(HTTP_AUTHORIZATION="Bearer " + readme)
     response = self.e.get(urls, content_type="application/json")
     writeTest("- User Detail : \n")
     writeTest(str(response.data))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.status_code, status.HTTP_404_NOT_FOUND)
     logger.info("User Detail")
示例#8
0
 def test_post_generics_list(self):
     post = Post.objects.first()
     urls = reverse("post-generics-list")
     urls_prefix = "%s?content=%s" % (urls, post.content[0:5])
     response = self.e.get(urls_prefix, content_type="application/json")
     writeTest("- Post Generics Filter: \n")
     writeTest(str(response.data))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     logger.info("Post List Generics - Filter")
示例#9
0
 def test_post_comments_destroy(self):
     comment = Comment.objects.last()
     urls = reverse('comments-detail', args=[comment.public_id])
     self.e.credentials(HTTP_AUTHORIZATION="Bearer " + readme)
     response = self.e.delete(urls, content_type='application/json')
     writeTest("- Comments has been deleted: \n")
     writeTest(str(response.data))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.status_code, status.HTTP_404_NOT_FOUND)
     logger.info("Comments has been delete")
示例#10
0
 def test_usr_filter_generic_list(self):
     user = User.objects.filter(first_name__gt=1).last()
     urls = reverse("user-generic-list")
     urls_prefix = "%s?first_name=%s" % (urls, user.first_name)
     self.e.credentials(HTTP_AUTHORIZATION="Bearer " + readme)
     response = self.e.get(urls_prefix, content_type="application/json")
     writeTest("- User List Generics Filter : \n")
     writeTest(str(response.data))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.data, None)
     logger.info("User List Generics - Filter")
示例#11
0
 def test_post_update(self):
     post = Post.objects.last()
     urls = reverse("post-update", args=[post.public_id])
     files = File(open("image_test.jpeg", "rb"))
     data = {"content": fake.text(), "photo": files}
     self.e.credentials(HTTP_AUTHORIZATION="Bearer " + readme)
     response = self.e.post(urls, data, follow=True)
     writeTest("- Post Update: \n")
     writeTest(str(response.data))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.status_code, status.HTTP_404_NOT_FOUND)
     logger.info("Post Update")
示例#12
0
    def test_usr_login(self):

        user = User.objects.last()
        urls = reverse("authtoken")
        data = json.dumps({"username": user.username, "password": "******"})
        response = self.e.post(urls, data, content_type="application/json")
        with open("token.txt", "w") as w:
            w.write(response.data.get("token"))
        writeTest("- Token : \n")
        writeTest(str(response.data))
        writeTest("\n")
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertNotEqual(response.data, None)
        logger.info("User Login")
示例#13
0
 def test_usr_create(self):
     urls = reverse("user-list")
     data = json.dumps({
         "username": fake.name(),
         "email": fake.email(),
         "password": "******",
         "confirm_password": "******",
     })
     response = self.e.post(urls, data, content_type="application/json")
     writeTest("- User Create : \n")
     writeTest(str(response.data))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     logger.info(response.data.get("message"))
示例#14
0
 def test_post_create(self):
     urls = reverse("post-list")
     files = File(open("image_test.jpeg", "rb"))
     data = {
         "content": fake.text(),
         "photo": files,
         "author": self.payload.get("user_id"),
     }
     self.e.credentials(HTTP_AUTHORIZATION="Bearer " + readme)
     response = self.e.post(urls, data, follow=True)
     writeTest("- Create Post: \n")
     writeTest("Post has been created")
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     self.assertNotEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     logger.info("Post has been created")
示例#15
0
 def test_post_comments(self):
     urls = reverse("comments-list")
     user = User.objects.last()
     payload = self.payload_client(user)
     encode = self.encode_client(payload)
     decode = self.decode(encode)
     data = json.dumps({
         'comment': fake.text(),
         'author': decode.get("user_id")
     })
     self.e.credentials(HTTP_AUTHORIZATION="Bearer " + encode)
     response = self.e.post(urls, data, content_type='application/json')
     writeTest("- Comments has been created: \n")
     writeTest(str(response.data))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     self.assertNotEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     logger.info("Comments has been created")
示例#16
0
 def test_usr_update(self):
     urls = reverse("user-update")
     files = File(open("image_test.jpeg", "rb"))
     data = {
         "first_name": fake.name(),
         "last_name": fake.name(),
         "avatar": files,
         "phone_numbers": "+628%s" % (random.randint(929349, 999999) * 999),
         "gender": random.randint(0, 1),
         "country": fake.country(),
         "province": fake.state(),
         "city": fake.city(),
         "address": fake.address(),
     }
     self.e.credentials(HTTP_AUTHORIZATION="Bearer " + readme)
     response = self.e.post(urls, data, follow=True)
     writeTest("- Update Accounts : \n")
     writeTest(str(response.data))
     writeTest("\n")
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertNotEqual(response.data, None)
     logger.info("Update Accounts")