def test_create_location(self): Project.create(name='tomate', description='tomatensalat', url='hallo') response = self.client.post('/tomate/locations/', {'title':'funfunfun', 'description':'nochmehrfun', 'lat':'0.0', 'lng':'0.0'}, **{'Authorization':'Bearer '+self.login.token()}) self.assertEqual(response.status_code, 201) location = Location.objects.get(title='funfunfun') self.assertEqual(location.title, 'funfunfun') self.assertEqual(location.description, 'nochmehrfun')
def test_update_project(self): Project.create(name='tomate', description='sdfgh sdfgjk', url='hallo') response = self.client.put('/tomate/', '{"description":"tomatensalat"}', **{'Authorization':'Bearer '+self.login.token()}) self.assertEqual(response.status_code, 200) project = Project.objects.get(name='tomate') self.assertEqual(project.description, 'tomatensalat') self.assertEqual(project.url, 'hallo')
def test_delete_location(self): project = Project.create(name='tomate', description='tomatensalat', url='hallo') Location.create(title='funfunfun', lat=0.0, lng=0.0, description='nochmehrfun', project=project) response = self.client.delete('/tomate/funfunfun/', **{'Authorization':'Bearer '+self.login.token()}) self.assertEqual(response.status_code, 200) location = Location.objects.filter(title='funfunfun') self.assertEqual(len(location), 0)
def test_update_location(self): project = Project.create(name='tomate', description='tomatensalat', url='hallo') Location.create(title='funfunfun', lat=0.0, lng=0.0, description='nochmehrfun', project=project) response = self.client.put('/tomate/funfunfun/', '{"description":"wenigerfunohhhh"}', **{'Authorization':'Bearer '+self.login.token()}) self.assertEqual(response.status_code, 200) location = Location.objects.get(title='funfunfun') self.assertEqual(location.description, 'wenigerfunohhhh')
def test_get_location(self): project = Project.create(name='tomate', description='tomatensalat', url='hallo') Location.create(title='funfunfun', lat=0.0, lng=0.0, description='nochmehrfun', project=project) response = self.client.get('/tomate/funfunfun/', **{'Authorization':'Bearer '+self.login.token()}) self.assertEqual(response.status_code, 200) data = response.content.decode('utf-8') self.assertJSONEqual(data, {'title':'funfunfun', 'description':'nochmehrfun', 'lat':0.0, 'lng':0.0})
def post(self, request): response = HttpResponse("", content_type='application/json; charset=utf-8') name = request.POST.get('name','') description = request.POST.get('description','') url = request.POST.get('url','') img = request.POST.get('img', '') if Project.create(name, description, url, img) != None: response.status_code = 201 else: response.status_code = 400 return response
def test_delete_project(self): Project.create(name='tomate', description='sdfgh sdfgjk', url='hallo') response = self.client.delete('/tomate/', **{'Authorization':'Bearer '+self.login.token()}) self.assertEqual(response.status_code, 200) project = Project.objects.filter(name='tomate') self.assertEqual(len(project), 0)
def test_get_project(self): Project.create(name='tomate', description='tomatensalat', url='hallo') response = self.client.get('/tomate/', **{'Authorization':'Bearer '+self.login.token()}) self.assertEqual(response.status_code, 200) data = response.content.decode('utf-8') self.assertJSONEqual(data, {'name':'tomate', 'description':'tomatensalat'})
def test_valid_location(self): Project.create(name='tomate', description='tomatensalat', url='hallo') response = self.client.post('/tomate/locations/', {'title':'', 'description':'', 'lat':'', 'lng':''}, **{'Authorization':'Bearer '+self.login.token()}) self.assertEqual(response.status_code, 400) data = response.content.decode('utf-8') self.assertJSONEqual(data, {'title':['This field cannot be blank.'], 'lat':['\'\' value must be a float.'], 'lng':['\'\' value must be a float.']})