def testDeleteRemovesObject(self): institution = generate_objects.valid_institution(); institution.save() institution_id = institution.id view = DeleteInstitutionView() view.post(None, institution_id) self.assertEqual(0, Institution.objects.filter(id=institution_id).count(), "Didn't delete institution")
def testReturnsInstitutionInformation(self): view = UpdateInstitutionView(); institution = generate_objects.valid_institution() request = self.factory.post('/data/institution/' + str(institution.id) + '/update/', data = {'name' : 'Updated Name'}) response = json.loads(view.post(request, institution.id).content) institution.refresh_from_db() self.assertEqual(response['name'], institution.name, "Didn't return the updated name of the institution") self.assertEqual(int(response['id']), institution.id, "Didn't return the ID of the updated institution")
def testInstitutionUpdates(self): institution = generate_objects.valid_institution() view = UpdateInstitutionView() request = self.factory.post('/data/institution/' + str(institution.id) + '/update/', data = {'name' : 'Updated Name'}) view.post(request, institution.id) institution.refresh_from_db() self.assertEqual('Updated Name', institution.name, "Did not update the name of the institution")
def testInstitutionDoesntExist(self): institution = generate_objects.valid_institution() institution.save() institution_id = institution.id institution.delete() with self.assertRaises(Http404): view = DeleteInstitutionView() view.post(None, institution_id)
def testCreateTeam(self): institution = generate_objects.valid_institution() teams_count = Team.objects.all().count() view = CreateTeamView() request = self.factory.post('/data/team/create/', data={ 'name' : 'TeamName', 'speaker1' : 'Alice', 'speaker2' : 'Jennie', 'institution' : institution.id }) view.post(request) self.assertEqual(teams_count+1, Team.objects.all().count(), "Didn't create a new team")
def testCreateTeamJSONResponse(self): institution = generate_objects.valid_institution() view = CreateTeamView() request = self.factory.post('/data/team/create/', data={ 'name' : 'TeamName', 'speaker1' : 'Alice', 'speaker2' : 'Jennie', 'institution' : institution.id }) response = json.loads(view.post(request).content) self.assertIsNotNone(response['name'], "No team name returned by create team function") self.assertIsNotNone(response['id'], "No team ID returned by create team function") self.assertIsNotNone(response['speaker1'], "No speaker1 returned by create team function") self.assertIsNotNone(response['name'], "No speaker2 returned by create team function")
def testTeamCreatesDatabaseObjects(self): institution = generate_objects.valid_institution() view = CreateTeamView() request = self.factory.post('/data/team/create/', data={ 'name' : 'TeamName', 'speaker1' : 'Alice', 'speaker2' : 'Jennie', 'institution' : institution.id }) response = json.loads(view.post(request).content) team = Team.objects.get(id=response['id']) self.assertEqual(response['name'], team.name, "Team name didn't match created team") for speaker in team.speakers: self.assertTrue(speaker == response['speaker1'] or speaker == response['speaker2'], "Speaker name didn't match created speaker")