Fakultas Ilmu Komputer UI

Commit 503ec723 authored by addffa's avatar addffa
Browse files

[RED] membuat test delete data source mutation

parent 6f594867
...@@ -45,18 +45,18 @@ class MustahikModelTestCase(TestCase): ...@@ -45,18 +45,18 @@ class MustahikModelTestCase(TestCase):
) )
institusi_detail = DataSourceInstitusi.objects.create( institusi_detail = DataSourceInstitusi.objects.create(
pic_ktp = '12345678901234', pic_ktp='12345678901234',
pic_name = 'instisusi', pic_name='instisusi',
pic_phone = '123456789012', pic_phone='123456789012',
pic_position = 'Head', pic_position='Head',
name = 'Institusi Bandung', name='Institusi Bandung',
province = 'Jawa Barat', province='Jawa Barat',
sub_district = 'Bogor', sub_district='Bogor',
village = 'Desa', village='Desa',
rt = '001', rt='001',
rw = '001', rw='001',
address = 'Jalan suatu desa no 1', address='Jalan suatu desa no 1',
data_source = data_source_institusi, data_source=data_source_institusi,
) )
data_source_warga = DataSource.objects.create( data_source_warga = DataSource.objects.create(
...@@ -64,17 +64,17 @@ class MustahikModelTestCase(TestCase): ...@@ -64,17 +64,17 @@ class MustahikModelTestCase(TestCase):
) )
warga_detail = DataSourceWarga.objects.create( warga_detail = DataSourceWarga.objects.create(
pic_ktp = '12345678901111', pic_ktp='12345678901111',
pic_name = 'wargai', pic_name='wargai',
pic_phone = '123456789012', pic_phone='123456789012',
pic_position = 'Ketua RT', pic_position='Ketua RT',
province = 'Test Barat', province='Test Barat',
regency = 'Kabupaten test', regency='Kabupaten test',
sub_district = 'Testmatan', sub_district='Testmatan',
village = 'Desa tes', village='Desa tes',
rt = '001', rt='001',
rw = '002', rw='002',
data_source = data_source_warga data_source=data_source_warga
) )
def test_mustahik_creation(self): def test_mustahik_creation(self):
...@@ -91,7 +91,7 @@ class MustahikModelTestCase(TestCase): ...@@ -91,7 +91,7 @@ class MustahikModelTestCase(TestCase):
def test_data_source_warga_creation(self): def test_data_source_warga_creation(self):
data_source_warga = DataSourceWarga.objects.get(pic_ktp='12345678901111') data_source_warga = DataSourceWarga.objects.get(pic_ktp='12345678901111')
self.assertTrue(isinstance(data_source_warga, DataSourceWarga)) self.assertTrue(isinstance(data_source_warga, DataSourceWarga))
def test_data_source_institusi_creation(self): def test_data_source_institusi_creation(self):
data_source_institusi = DataSourceInstitusi.objects.get(pic_ktp='12345678901234') data_source_institusi = DataSourceInstitusi.objects.get(pic_ktp='12345678901234')
self.assertTrue(isinstance(data_source_institusi, DataSourceInstitusi)) self.assertTrue(isinstance(data_source_institusi, DataSourceInstitusi))
...@@ -128,7 +128,6 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -128,7 +128,6 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
data_source=data_source_warga data_source=data_source_warga
) )
def test_about_query(self): def test_about_query(self):
response = self.query('{ about }') response = self.query('{ about }')
self.assertResponseNoErrors(response) self.assertResponseNoErrors(response)
...@@ -466,9 +465,9 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -466,9 +465,9 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
} }
''', ''',
op_name='dataSourceQuery', op_name='dataSourceQuery',
variables={'id1': warga_detail.data_source.pk, variables={'id1': warga_detail.data_source.pk,
'id2': pekerja_detail.data_source.pk, 'id2': pekerja_detail.data_source.pk,
'id3': institusi_detail.data_source.pk} 'id3': institusi_detail.data_source.pk}
) )
self.assertResponseNoErrors(response) self.assertResponseNoErrors(response)
...@@ -481,7 +480,6 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -481,7 +480,6 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
self.assertEqual(content['data']['q3']['id'], str(institusi_detail.data_source.pk)) self.assertEqual(content['data']['q3']['id'], str(institusi_detail.data_source.pk))
self.assertEqual(content['data']['q3']['detail']['__typename'], 'DataSourceInstitusiType') self.assertEqual(content['data']['q3']['detail']['__typename'], 'DataSourceInstitusiType')
def test_data_source_mutation_can_add_new_data_source(self): def test_data_source_mutation_can_add_new_data_source(self):
existing_data_source_ammount = DataSource.objects.count() existing_data_source_ammount = DataSource.objects.count()
response = self.query( response = self.query(
...@@ -496,18 +494,18 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -496,18 +494,18 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
''', ''',
op_name='dataSourceMutation', op_name='dataSourceMutation',
input_data={ input_data={
'category':'WARGA', 'category': 'WARGA',
} }
) )
#This validates the status code and if you get errors # This validates the status code and if you get errors
self.assertResponseNoErrors(response) self.assertResponseNoErrors(response)
#Validate content # Validate content
content = json.loads(response.content) content = json.loads(response.content)
self.assertEqual(content['data']['dataSourceMutation']['dataSource']['category'], "WARGA") self.assertEqual(content['data']['dataSourceMutation']['dataSource']['category'], "WARGA")
#Validate successful save to db # Validate successful save to db
new_ammount = existing_data_source_ammount + 1 new_ammount = existing_data_source_ammount + 1
self.assertEqual(DataSource.objects.count(), new_ammount) self.assertEqual(DataSource.objects.count(), new_ammount)
...@@ -548,7 +546,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -548,7 +546,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
"village": "Desa dusun", "village": "Desa dusun",
"rt": "001", "rt": "001",
"rw": "002", "rw": "002",
"dataSource":data_source_warga.pk "dataSource": data_source_warga.pk
} }
) )
# This validates the status code and if you get errors # This validates the status code and if you get errors
...@@ -557,7 +555,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -557,7 +555,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
# Validate content # Validate content
content = json.loads(response.content) content = json.loads(response.content)
self.assertEqual(content['data']['dataSourceWargaMutation'] self.assertEqual(content['data']['dataSourceWargaMutation']
['dataSourceWarga']['picKtp'], pic_ktp) ['dataSourceWarga']['picKtp'], pic_ktp)
# Validate successful save to db # Validate successful save to db
new_ammount = old_ammount + 1 new_ammount = old_ammount + 1
...@@ -573,17 +571,17 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -573,17 +571,17 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
) )
warga_detail = DataSourceWarga.objects.create( warga_detail = DataSourceWarga.objects.create(
pic_ktp = pic_ktp, pic_ktp=pic_ktp,
pic_name = 'wargai', pic_name='wargai',
pic_phone = '123456789012', pic_phone='123456789012',
pic_position = 'Ketua RT', pic_position='Ketua RT',
province = 'Test Barat', province='Test Barat',
regency = 'Kabupaten test', regency='Kabupaten test',
sub_district = 'Testmatan', sub_district='Testmatan',
village = 'Desa tes', village='Desa tes',
rt = '001', rt='001',
rw = '002', rw='002',
data_source = data_source_warga data_source=data_source_warga
) )
response = self.query( response = self.query(
...@@ -608,12 +606,12 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -608,12 +606,12 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
"village": "Desa dusun", "village": "Desa dusun",
"rt": "001", "rt": "001",
"rw": "002", "rw": "002",
"dataSource":data_source_warga.pk, "dataSource": data_source_warga.pk,
"id": warga_detail.pk "id": warga_detail.pk
} }
) )
#Validate success update data source warga # Validate success update data source warga
source = DataSourceWarga.objects.get(pic_ktp=pic_ktp) source = DataSourceWarga.objects.get(pic_ktp=pic_ktp)
self.assertEqual(source.pic_name, new_pic_name) self.assertEqual(source.pic_name, new_pic_name)
...@@ -624,7 +622,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -624,7 +622,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
data_source_pekerja = DataSource.objects.create( data_source_pekerja = DataSource.objects.create(
category=DataSource.Category.PEKERJA category=DataSource.Category.PEKERJA
) )
response = self.query( response = self.query(
''' '''
mutation dataSourcePekerjaMutation($input: DataSourcePekerjaMutationInput!){ mutation dataSourcePekerjaMutation($input: DataSourcePekerjaMutationInput!){
...@@ -660,7 +658,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -660,7 +658,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
# Validate content # Validate content
content = json.loads(response.content) content = json.loads(response.content)
self.assertEqual(content['data']['dataSourcePekerjaMutation'] self.assertEqual(content['data']['dataSourcePekerjaMutation']
['dataSourcePekerja']['picKtp'], pic_ktp) ['dataSourcePekerja']['picKtp'], pic_ktp)
# Validate successful save to db # Validate successful save to db
new_ammount = old_ammount + 1 new_ammount = old_ammount + 1
...@@ -668,7 +666,6 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -668,7 +666,6 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
source = DataSourcePekerja.objects.get(pic_ktp=pic_ktp) source = DataSourcePekerja.objects.get(pic_ktp=pic_ktp)
self.assertEqual(source.pic_name, pic_name) self.assertEqual(source.pic_name, pic_name)
def test_data_source_pekerja_mutation_can_update_data_source_pekerja(self): def test_data_source_pekerja_mutation_can_update_data_source_pekerja(self):
pic_ktp = "123456789012" pic_ktp = "123456789012"
new_pic_name = "Aryo" new_pic_name = "Aryo"
...@@ -677,12 +674,12 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -677,12 +674,12 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
category=DataSource.Category.PEKERJA category=DataSource.Category.PEKERJA
) )
source_pekerja = DataSourcePekerja.objects.create( source_pekerja = DataSourcePekerja.objects.create(
pic_name = 'wargai', pic_name='wargai',
pic_ktp = pic_ktp, pic_ktp=pic_ktp,
pic_phone = '123456789012', pic_phone='123456789012',
pic_position = 'Ketua RT', pic_position='Ketua RT',
profession = 'tester', profession='tester',
location = 'jl tester', location='jl tester',
data_source=data_source_pekerja, data_source=data_source_pekerja,
) )
...@@ -696,7 +693,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -696,7 +693,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
} }
} }
''', ''',
op_name = "dataSourcePekerjaMutation", op_name="dataSourcePekerjaMutation",
input_data={ input_data={
"picName": new_pic_name, "picName": new_pic_name,
"picKtp": pic_ktp, "picKtp": pic_ktp,
...@@ -709,7 +706,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -709,7 +706,7 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
} }
) )
#Validate successful update to data source pekerja # Validate successful update to data source pekerja
source = DataSourcePekerja.objects.get(pic_ktp=pic_ktp) source = DataSourcePekerja.objects.get(pic_ktp=pic_ktp)
self.assertEqual(source.pic_name, new_pic_name) self.assertEqual(source.pic_name, new_pic_name)
...@@ -755,18 +752,17 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -755,18 +752,17 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
# This validates the status code and if you get errors # This validates the status code and if you get errors
self.assertResponseNoErrors(response) self.assertResponseNoErrors(response)
#Validate content # Validate content
content = json.loads(response.content) content = json.loads(response.content)
self.assertEqual(content['data']['dataSourceInstitusiMutation'] self.assertEqual(content['data']['dataSourceInstitusiMutation']
['dataSourceInstitusi']['picKtp'], pic_ktp) ['dataSourceInstitusi']['picKtp'], pic_ktp)
#Validate success save to db # Validate success save to db
new_ammount = old_ammount + 1 new_ammount = old_ammount + 1
self.assertEqual(DataSourceInstitusi.objects.count(), new_ammount) self.assertEqual(DataSourceInstitusi.objects.count(), new_ammount)
source = DataSourceInstitusi.objects.get(pic_ktp=pic_ktp) source = DataSourceInstitusi.objects.get(pic_ktp=pic_ktp)
self.assertEqual(source.pic_name, pic_name) self.assertEqual(source.pic_name, pic_name)
def test_data_source_institusi_mutation_can_update_data_source_institusi(self): def test_data_source_institusi_mutation_can_update_data_source_institusi(self):
pic_ktp = '12345678901234' pic_ktp = '12345678901234'
new_pic_name = 'Rofi Arief' new_pic_name = 'Rofi Arief'
...@@ -776,18 +772,18 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -776,18 +772,18 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
) )
source_institusi = DataSourceInstitusi.objects.create( source_institusi = DataSourceInstitusi.objects.create(
pic_ktp = pic_ktp, pic_ktp=pic_ktp,
pic_name = 'Rofi', pic_name='Rofi',
pic_phone = '123456789012', pic_phone='123456789012',
pic_position = 'Head', pic_position='Head',
name = 'Institusi Bandung', name='Institusi Bandung',
province = 'Jawa Barat', province='Jawa Barat',
sub_district = 'Bogor', sub_district='Bogor',
village = 'Desa', village='Desa',
rt = '001', rt='001',
rw = '001', rw='001',
address = 'Jalan suatu desa no 1', address='Jalan suatu desa no 1',
data_source = data_source_institusi, data_source=data_source_institusi,
) )
response = self.query( response = self.query(
...@@ -803,8 +799,8 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -803,8 +799,8 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
} }
} }
''', ''',
op_name = 'dataSourceInstitusiMutation', op_name='dataSourceInstitusiMutation',
input_data = { input_data={
"picKtp": pic_ktp, "picKtp": pic_ktp,
"picName": new_pic_name, "picName": new_pic_name,
"picPhone": "123456789012", "picPhone": "123456789012",
...@@ -821,6 +817,25 @@ class MustahikGraphQLTestCase(GraphQLTestCase): ...@@ -821,6 +817,25 @@ class MustahikGraphQLTestCase(GraphQLTestCase):
} }
) )
#Validate success update data source institusi # Validate success update data source institusi
source = DataSourceInstitusi.objects.get(pic_ktp=pic_ktp) source = DataSourceInstitusi.objects.get(pic_ktp=pic_ktp)
self.assertEqual(source.pic_name, new_pic_name) self.assertEqual(source.pic_name, new_pic_name)
def test_delete_datasource_mutations_can_delete_datasource(self):
count = DataSource.objects.count()
datasource = DataSource.objects.all()[0]
response = self.query(
'''
mutation deleteDataSource($id: ID) {
deleteDataSource(id: $id) {
deleted
}
}
''',
op_name='deleteDataSource',
variables={'id': datasource.pk}
)
self.assertResponseNoErrors(response)
content = json.loads(response.content)
self.assertTrue(content['data']['deleteDataSource']['deleted'])
self.assertEquals(DataSource.objects.count(), count-1)
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