def test_handle_survey_data(self):
        bs = seed_models.BuildingSnapshot.objects.create()
        canon = seed_models.CanonicalBuilding.objects.create()
        bs.canonical_building = canon
        bs.save()

        survey = Survey.objects.create()
        SurveyBuilding.objects.create(survey=survey, canonical_building=canon)
        # Previously answered question
        q1 = SurveyQuestion.objects.create(question='What?')
        q1.survey = survey
        q1.save()

        # Unanswered question.
        q2 = SurveyQuestion.objects.create(question='Where?')
        q2.survey = survey
        q1.save()

        # Pre-existing answer that we'll update.
        a1 = SurveyAnswer.objects.create(
            canonical_building=canon, question=q1, answer='Yes'
        )

        fake_payload = {
            'id': survey.pk,
            'completion_time': 2342,
            'comment': 'Found a double database machine in your pool',
            'date_collected': '2014-07-23',
            'question_responses': {
                q1.pk: {'id': a1.pk, 'answer': 'Double database'},
                q2.pk: {'id': None, 'answer': 'True'},

            }
        }

        self.assertEqual(SurveyAnswer.objects.count(), 1)

        new_bs = seed_models._handle_survey_data(bs, fake_payload)

        # Make sure that our Answers are set.
        self.assertEqual(SurveyAnswer.objects.count(), 2)
        first_ans = SurveyAnswer.objects.filter(question=q1).first()
        second_ans = SurveyAnswer.objects.filter(question=q2).first()
        self.assertEqual(first_ans.answer, 'Double database')
        self.assertEqual(second_ans.answer, 'True')

        # Make sure we're linked back with our canonical building
        self.assertEqual(new_bs.canonical_building.survey_answers.count(), 2)
Gradation encoding function
dataset/ETHPy150Open buildingenergy/buildingenergy-platform/seed/tests/test_models.py/TestTimeSeriesMeterFunctions.test_handle_survey_data--crossover with--dataset/ETHPy150Open mikrosimage/ColorPipe-tools/utils/colorspaces.py/AbstractColorspace.encode_gradation