def test_multiple_surveys_for_user(self): user = UserFactory() teamtemp1 = TeamTemperatureFactory(creator=user) teamtemp2 = TeamTemperatureFactory(creator=user) self.assertNotEqual(teamtemp1.id, teamtemp2.id) self.assertEqual(teamtemp1.creator.id, teamtemp2.creator.id) self.assertEqual(user.team_temperatures.count(), 2)
def test_multiple_responses_for_user_and_survey(self): user = UserFactory() teamtemp1 = TeamTemperatureFactory() teamtemp2 = TeamTemperatureFactory() _ = TemperatureResponseFactory(request=teamtemp1, responder=user) _ = TemperatureResponseFactory(request=teamtemp2, responder=user) self.assertEqual(user.temperature_responses.count(), 2) self.assertEqual(teamtemp1.temperature_responses.count(), 1) self.assertEqual(teamtemp2.temperature_responses.count(), 1)
def test_stats_count(self): team_temp = TeamTemperatureFactory() self.assertEqual(team_temp.stats()['count'], 0) TeamResponseFactory(request=team_temp) self.assertEqual(team_temp.stats()['count'], 1) TeamResponseFactory(request=team_temp) TeamResponseFactory(request=team_temp) self.assertEqual(team_temp.stats()['count'], 3)
def test_stats_word(self): team_temp = TeamTemperatureFactory() self.assertEqual(len(team_temp.stats()['words']), 0) TeamResponseFactory(request=team_temp, word='first') self.assertEqual(len(team_temp.stats()['words']), 1) TeamResponseFactory(request=team_temp, word='second') TeamResponseFactory(request=team_temp, word='third') self.assertEqual(len(team_temp.stats()['words']), 3)
def test_team_temperature(self): teamtemp = TeamTemperatureFactory() self.assertTrue(len(teamtemp.id) > 0) self.assertIsNotNone(teamtemp.creation_date) self.assertIsNotNone(teamtemp.modified_date) self.assertEqual(teamtemp.survey_type, 'TEAMTEMP') self.assertRegexpMatches(str(teamtemp), "%s: %s %s " % ( teamtemp.id, teamtemp.creator.id, re.escape(str(teamtemp.creation_date)))) stats, query_set = teamtemp.stats() self.assertEqual(stats['count'], 0) self.assertIsNone(stats['average']['score__avg']) self.assertEqual(stats['words'].count(), 0) self.assertEqual(query_set.count(), 0)
def test_stats_average(self): team_temp = TeamTemperatureFactory() self.assertIsNone(team_temp.stats()['average']['score__avg']) TeamResponseFactory(request=team_temp, score=5) self.assertEqual(team_temp.stats()['average']['score__avg'], 5.0) TeamResponseFactory(request=team_temp, score=7) TeamResponseFactory(request=team_temp, score=6) self.assertEqual(team_temp.stats()['average']['score__avg'], 6.0)
def test_multiple_surveys_for_user(self): teamtemp = TeamTemperatureFactory() team1 = TeamFactory(request=teamtemp) team2 = TeamFactory(request=teamtemp) self.assertNotEqual(team1.team_name, team2.team_name) self.assertEqual(team1.request.id, team2.request.id) self.assertEqual(teamtemp.teams.count(), 2)
def test_get_temperature_view(self): team_temp = TeamTemperatureFactory() response = self.client.get(reverse('temp', args=[str(team_temp.id)])) self.assertTemplateUsed(response, 'form.html') self.assertContains(response, 'Submit your temperature')
def test_existing_survey_settings_form(self): survey = TeamTemperatureFactory() form_data = { 'request': survey, 'team_name': 'test', } form = AddTeamForm(data=form_data) self.assertTrue(form.is_valid())
def test_multiple_response_histories(self): teamtemp = TeamTemperatureFactory() team = TeamFactory(request=teamtemp) _ = TeamResponseHistoryFactory(request=teamtemp, team_name=team.team_name) _ = TeamResponseHistoryFactory(request=teamtemp, team_name=team.team_name) self.assertEqual(teamtemp.team_response_histories.count(), 2)
def setUp(self): self.teamtemp = TeamTemperatureFactory() self.team = TeamFactory(request=self.teamtemp) self.response = TemperatureResponseFactory( request=self.teamtemp, team_name=self.team.team_name) TeamResponseHistoryFactory(request=self.teamtemp, team_name=self.team.team_name) TeamResponseHistoryFactory(request=self.teamtemp, team_name='Average')
def test_results_redirects_if_not_authenticated(self): team_temp = TeamTemperatureFactory() response = self.client.get( reverse('result', kwargs={'pk': team_temp.id})) self.assertRedirects( response, 'http://testserver/accounts/login/?next=/admin/{}/'.format( team_temp.id))
def test_score_must_be_whole_number(self): team_temp = TeamTemperatureFactory() response = self.client.post(reverse('temp', args=[str(team_temp.id)]), data={ 'score': 9.1, 'word': 'word' }) self.assertTemplateUsed(response, 'form.html') self.assertContains(response, "Enter a whole number.")
def test_post_invalid_temperature_view(self): team_temp = TeamTemperatureFactory() response = self.client.post(reverse('temp', args=[str(team_temp.id)]), data={'score': 2}) self.assertTemplateUsed(response, 'form.html') # self.failIf(response.context_data['form'].is_valid()) self.assertFormError(response, 'form', 'word', 'This field is required.')
def test_score_must_be_less_than_ten(self): team_temp = TeamTemperatureFactory() response = self.client.post(reverse('temp', args=[str(team_temp.id)]), data={ 'score': 11, 'word': 'word' }) self.assertTemplateUsed(response, 'form.html') self.assertContains(response, "Ensure this value is less than or equal to 10.")
def test_other_users_can_not_admin_team_temp(self): team_temp = TeamTemperatureFactory( creator=User.objects.create_user('another_user')) self.assertTrue( self.client.login(username=self.user.username, password='******')) response = self.client.get( reverse('result', kwargs={'pk': team_temp.id})) self.assertContains(response, '403 Forbidden', status_code=403)
def test_word_has_no_special_chars(self): team_temp = TeamTemperatureFactory() response = self.client.post(reverse('temp', args=[str(team_temp.id)]), data={ 'score': 10, 'word': '*' }) self.assertTemplateUsed(response, 'form.html') self.assertContains( response, "please enter a single word with alphanumeric characters only.")
def test_existing_survey_settings_form(self): survey = TeamTemperatureFactory() form_data = { 'id': survey.id, 'creator': survey.creator, 'password': survey.password, 'archive_schedule': survey.archive_schedule, 'survey_type': survey.survey_type, 'default_tz': survey.default_tz, 'max_word_count': survey.max_word_count } form = SurveySettingsForm(data=form_data) self.assertTrue(form.is_valid())
def test_post_valid_temperature_view(self): team_temp = TeamTemperatureFactory() response = self.client.post(reverse('temp', args=[str(team_temp.id)]), data={ 'score': 2, 'word': 'word' }) self.assertTemplateUsed(response, 'form.html') self.assertContains( response, "Thank you for submitting your answers. " "You can amend them now or later if you need to")
def test_creator_can_admin_team_temp(self): team_temp = TeamTemperatureFactory(creator=self.user) self.assertTrue( self.client.login(username=self.user.username, password='******')) response = self.client.get( reverse('result', kwargs={'pk': team_temp.id})) self.assertTemplateUsed(response, 'results.html') self.assertContains(response, 'Submissions: 0') self.assertContains(response, 'Let your team know about this survey')
def setUp(self): self.survey = TeamTemperatureFactory() self.response = TemperatureResponseFactory(request=self.survey) self.form_data = { 'response_id': self.response.id, 'survey_type_title': 'test', 'temp_question_title': 'test', 'word_question_title': 'test', 'team_name': self.response.team_name, 'pretty_team_name': self.response.pretty_team_name(), 'id': self.survey.id, 'word': self.response.word, 'score': self.response.score, }
def test_multiple_responses_for_a_survey(self): teamtemp = TeamTemperatureFactory() response1 = TemperatureResponseFactory(request=teamtemp) response2 = TemperatureResponseFactory(request=teamtemp) response3 = TemperatureResponseFactory(request=teamtemp, word=response2.word) self.assertEqual(teamtemp.temperature_responses.count(), 3) stats, query_set = teamtemp.stats() self.assertEqual(stats['count'], 3) self.assertEqual( stats['average']['score__avg'], old_div(float(response1.score + response2.score + response3.score), 3)) words = [[x['word']] * x['id__count'] for x in stats['words']] flat_words = sorted(itertools.chain(*words)) self.assertEqual( flat_words, sorted([response1.word, response2.word, response3.word])) self.assertEqual(query_set.count(), 3)
def test_get_temperature_with_previous_response_view( self, mock_session_id): responding_user = UserFactory(id=utils.random_string(8)) mock_session_id.return_value = responding_user.id team_temp = TeamTemperatureFactory() existing_response = TeamResponseFactory(request=team_temp, responder=responding_user) response = self.client.get(reverse('temp', args=[str(team_temp.id)])) self.assertTemplateUsed(response, 'form.html') self.assertContains(response, 'Submit your temperature') self.assertContains(response, existing_response.id)
def test_invalid_max_word_count(self): with self.assertRaises(RuntimeError): TeamTemperatureFactory(max_word_count=0) with self.assertRaises(RuntimeError): TeamTemperatureFactory(max_word_count=11)
def test_duplicate_teamtemp_ids(self): with self.assertRaises(RuntimeError): TeamTemperatureFactory(id='bob') TeamTemperatureFactory(id='bob')
def setUp(self): self.teamtemp = TeamTemperatureFactory() self.team = TeamFactory(request=self.teamtemp)
def test_uniq_teamtemp_ids(self): self.assertNotEqual( TeamTemperatureFactory().id, TeamTemperatureFactory().id)
def test_customer_feedback(self): teamtemp = TeamTemperatureFactory(survey_type='CUSTOMERFEEDBACK') self.assertTrue(len(teamtemp.id) > 0) self.assertIsNotNone(teamtemp.creation_date) self.assertIsNotNone(teamtemp.modified_date) self.assertEqual(teamtemp.survey_type, 'CUSTOMERFEEDBACK')
def test_empty_add_team_form(self): survey = TeamTemperatureFactory() form = AddTeamForm(data={'request': survey}) self.assertFalse(form.is_valid())
def test_duplicate_team_names(self): teamtemp = TeamTemperatureFactory() with self.assertRaises(RuntimeError): TeamFactory(team_name='bob', request=teamtemp) TeamFactory(team_name='bob', request=teamtemp)