Exemple #1
0
    def test_create_survey_responses_throws_exception_when_user_answers_same_survey_twice(
            self):
        survey = Survey()
        survey.available_places = 10
        survey.save()

        survey_response.create(survey.id, 1234)

        with self.assertRaises(ValueError) as user_error:
            survey_response.create(survey.id, 1234)

        self.assertEqual('User 1234 has already completed survey',
                         str(user_error.exception))
Exemple #2
0
    def test_create_survey_responses_checks_for_duplicate_user_when_user_id_is_string(
            self):
        survey = Survey()
        survey.available_places = 10
        survey.save()

        survey_response.create(survey.id, 1234)

        with self.assertRaises(ValueError) as user_error:
            survey_response.create(survey.id, "1234")

        self.assertEqual('User 1234 has already completed survey',
                         str(user_error.exception))
Exemple #3
0
    def test_create_survey_response_throws_exception_when_reached_max_responses(
            self):
        survey = Survey()
        survey.available_places = 2
        survey.save()

        survey_response.create(survey.id, 1234)
        survey_response.create(survey.id, 5678)

        with self.assertRaises(ValueError) as max_responses_error:
            survey_response.create(survey.id, 91011)

        self.assertEqual(
            'The maximum number (2) of survey responses has been reached',
            str(max_responses_error.exception))
Exemple #4
0
def create(name, available_places, user):
    survey = Survey()

    survey.name = name
    survey.available_places = available_places
    survey.user = user

    survey.save()
Exemple #5
0
def create(survey_id, user_id):
    survey = Survey.objects(id=survey_id).first()
    validate(survey, user_id)

    survey_response = SurveyResponse()
    survey_response.user = user_id

    survey.responses.append(survey_response)

    survey.save()
Exemple #6
0
    def test_create_survey_response_sets_user_id(self):
        survey = Survey()
        survey.available_places = 1
        survey.save()

        survey_response.create(survey.id, 1234)

        result = Survey.objects().first()

        self.assertEqual(1234, result.responses[0].user)
Exemple #7
0
    def test_create_survey_response_is_inserted_into_the_database(self):
        survey = Survey()
        survey.available_places = 1
        survey.save()

        survey_response.create(survey.id, 1234)

        result = Survey.objects().first()

        self.assertEqual(1, len(result.responses))
Exemple #8
0
    def test_create_survey_response_sets_created_at(self):
        survey = Survey()
        survey.available_places = 1
        survey.save()

        survey_response.create(survey.id, 1234)

        result = Survey.objects().first()

        self.assertEqual(datetime.datetime,
                         type(result.responses[0].created_at))
Exemple #9
0
    def test_list_surveys_returns_all_surveys(self):
        first_survey = Survey()
        first_survey.name = 'First Survey'

        second_survey = Survey()
        second_survey.name = 'Second Survey'

        Survey.objects.insert([first_survey, second_survey])

        result = survey.list_surveys()

        self.assertEqual(2, len(result))

        self.assertEqual('First Survey', result[0].name)
        self.assertEqual('Second Survey', result[1].name)
Exemple #10
0
 def tearDown(self):
     Survey.objects().delete()
Exemple #11
0
    def test_create_survey_sets_available_places(self):
        survey.create('test_survey', 12, 63)

        saved_survey = Survey.objects().first()

        self.assertEqual(12, saved_survey.available_places)
Exemple #12
0
    def test_create_survey_sets_survey_name(self):
        survey.create('test_survey', 12, 63)

        saved_survey = Survey.objects().first()

        self.assertEqual('test_survey', saved_survey.name)
Exemple #13
0
    def test_create_survey_saves_document_to_database(self):
        survey.create('test_survey', 12, '63')

        result = Survey.objects()

        self.assertEqual(1, len(result))