Fakultas Ilmu Komputer UI

Commit 7cdfd70f authored by PRIMO GIANCARLO UNEPUTTY's avatar PRIMO GIANCARLO UNEPUTTY
Browse files

test: Add tests for delete Investasi

parent a49f119f
......@@ -101,7 +101,25 @@ class InvestasiTest(TestCase):
self.assertNotEqual(response.status_code, 200)
def test_update_investasi(self):
def test_update_investasi_of_different_user(self):
investasi = Investasi(investor=self.user, pengadaan=self.pengadaan, nominal=1)
investasi.save()
user = UserAccount(email='a@a.id', first_name='a', last_name='a', role='investor')
user.set_password('a')
user.save()
token = self._get_token(user.email, 'a')
response = self.client.put(
'/api/investasi/{}'.format(investasi.pk),
{**self.investasi_data, "nominal": 13000},
content_type="application/json",
HTTP_AUTHORIZATION="JWT {}".format(token)
)
self.assertNotEqual(response.status_code, 200)
def test_update_investasi_success(self):
investasi = Investasi(investor=self.user, pengadaan=self.pengadaan, nominal=1)
investasi.save()
......@@ -116,6 +134,34 @@ class InvestasiTest(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()['nominal'], 13000)
def test_delete_investasi_sedang_dijual(self):
investasi = Investasi(
investor=self.user, pengadaan=self.pengadaan, nominal=1, status_investasi='DJL'
)
investasi.save()
token = self._get_token(self.user_email, self.user_pass)
response = self.client.delete(
'/api/investasi/{}'.format(investasi.pk),
content_type="application/json",
HTTP_AUTHORIZATION="JWT {}".format(token)
)
self.assertNotEqual(response.status_code, 204)
def test_delete_investasi_success(self):
investasi = Investasi(investor=self.user, pengadaan=self.pengadaan, nominal=1)
investasi.save()
token = self._get_token(self.user_email, self.user_pass)
response = self.client.delete(
'/api/investasi/{}'.format(investasi.pk),
content_type="application/json",
HTTP_AUTHORIZATION="JWT {}".format(token)
)
self.assertEqual(response.status_code, 204)
def test_jual_investasi_of_different_user(self):
investasi = Investasi(
investor=self.user, pengadaan=self.pengadaan, nominal=1, status_investasi='DMK'
......
#pylint: disable=too-many-ancestors
from rest_framework.exceptions import ValidationError
from rest_framework import generics
from rest_framework import permissions
from rest_framework.exceptions import ValidationError
from djangorestframework_camel_case.render import (CamelCaseJSONRenderer,
CamelCaseBrowsableAPIRenderer)
from djangorestframework_camel_case.parser import (CamelCaseJSONParser,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment