Fakultas Ilmu Komputer UI

Commit 405f0582 authored by M. Abdurrahman's avatar M. Abdurrahman
Browse files

[GREEN] add tests for informasi_fasilitas views for fasilitas

parent f2b280b5
Pipeline #42176 passed with stages
in 4 minutes and 49 seconds
......@@ -215,3 +215,159 @@ class InformasiFasilitasViewTest(TestCase):
response = client.get(reverse('add-lokasi'))
self.assertEqual(response.status_code, 405)
def test_can_get_list_fasilitas(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
lokasi=Lokasi(
name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image=image
)
lokasi.save()
response = Client().get(reverse('list-fasilitas', kwargs={'nama_lokasi':'Mall'}))
self.assertEqual(response.status_code, 200)
def test_cannot_post_list_fasilitas(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
lokasi=Lokasi(
name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image=image
)
lokasi.save()
response = Client().post(reverse('list-fasilitas', kwargs={'nama_lokasi':'Mall'}))
self.assertEqual(response.status_code, 405)
def test_can_get_detail_fasilitas(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
user=User(
username='user@gmail.com',
last_name='name',
email='user@gmail.com',
password='hahagotim'
)
user.save()
lokasi=Lokasi(
name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image=image
)
lokasi.save()
fasilitas=Fasilitas(
lokasi=lokasi,
user=user,
deskripsi="penjelasan panjang",
like=0,
dislike=0,
rating=5,
tag={KURSI_RODA, RUNNING_TEXT},
image=image
)
fasilitas.save()
id = fasilitas.id
response = Client().get(reverse('detail-fasilitas', kwargs={'nama_lokasi':'Mall', 'id':id}))
self.assertEqual(response.status_code, 200)
def test_cannot_post_lokasi_details(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
user=User(
username='user@gmail.com',
last_name='name',
email='user@gmail.com',
password='hahagotim'
)
user.save()
lokasi=Lokasi(
name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image=image
)
lokasi.save()
fasilitas=Fasilitas(
lokasi=lokasi,
user=user,
deskripsi="penjelasan panjang",
like=0,
dislike=0,
rating=5,
tag={KURSI_RODA, RUNNING_TEXT},
image=image
)
fasilitas.save()
id = fasilitas.id
response = Client().post(reverse('detail-fasilitas', kwargs={'nama_lokasi':'Mall', 'id':id}))
self.assertEqual(response.status_code, 405)
#=======
def test_can_post_add_fasilitas(self):
email='user@gmail.com'
password='hahagotim'
Client().post('/api/register/',
{'name':'name',
'email':email,
'phone_number':000000000,
'password':password})
token_response = Client().post('/api-token-auth/',
{'username' : email, 'password' : password})
content = json.loads(token_response.content.decode('utf-8'))
token = content['token']
client = Client(HTTP_AUTHORIZATION='token '+token)
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
lokasi=Lokasi(
name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image=image
)
lokasi.save()
response = client.post(reverse('add-fasilitas', kwargs={'nama_lokasi':'Mall'}),
{'deskripsi' : 'penjelasan fasilitas',
'rating' : 2})
self.assertEqual(response.status_code, 201)
def test_cannot_get_add_fasilitas(self):
email='user@gmail.com'
password='hahagotim'
Client().post('/api/register/',
{'name':'name',
'email':email,
'phone_number':000000000,
'password':password})
token_response = Client().post('/api-token-auth/',
{'username' : email, 'password' : password})
content = json.loads(token_response.content.decode('utf-8'))
token = content['token']
client = Client(HTTP_AUTHORIZATION='token '+token)
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
lokasi=Lokasi(
name='Mall',
latitude=0.0,
longitude=0.0,
alamat='Jl. Raya Bogor no.1, Jakarta',
no_telp='081212123131',
image=image
)
lokasi.save()
response = client.get(reverse('add-fasilitas', kwargs={'nama_lokasi':'Mall'}))
self.assertEqual(response.status_code, 405)
\ No newline at end of file
......@@ -102,11 +102,9 @@ def add_fasilitas(request, nama_lokasi):
lokasi = Lokasi.objects.get(name=nama_lokasi)
user = User.objects.get(email=str(request.user))
deskripsi = request.POST['deskripsi']
image = request.POST['image']
fasilitas = Fasilitas.objects.create(lokasi=lokasi,
user=user,
deskripsi=deskripsi,
image=image)
deskripsi=deskripsi)
return JsonResponse({'response' : 'fasilitas added', 'id':fasilitas.id}, status = 201)
else:
return JsonResponse({'response' : request_error_message("post")}, status = 400)
......
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