Пример #1
0
    def test_create_returns_created_status(self):
        create_url = '/definition_templates'
        word = self.definition_template.get_word()
        word_id = word.get_id()
        definition = self.definition_template.get_definition()
        filler_lexical_classes = self.definition_template.get_filler_lexical_classes()
        definition_template_data = {
            'word_id': word_id,
            'definition': definition,
            'filler_lexical_classes': filler_lexical_classes
        }
        response = self.post(create_url, data=definition_template_data)
        self.assertEqual(201, response.status_code)
        definition_template = json.loads(response.data)
        self.assertIsNotNone(definition_template.get('id'))
        self.assertIsNotNone(definition_template.get('date_created'))
        self.assertIsNotNone(definition_template.get('date_modified'))
        self.assertEqual(word.serialized, definition_template.get('word'))
        self.assertEqual(definition, definition_template.get('definition'))
        self.assertEqual(filler_lexical_classes, definition_template.get('filler_lexical_classes'))
        self.assertEqual(True, definition_template.get('is_active'))

        # Make sure the definition_template was actually saved to the database
        saved_definition_template = DefinitionTemplatesService.get_instance().get(int(definition_template.get('id')))
        self.assertEqual(saved_definition_template.get_id(), definition_template.get('id'))
        self.assertEqual(DefinitionTemplate.dump_datetime(saved_definition_template.get_date_created()), definition_template.get('date_created'))
        self.assertEqual(DefinitionTemplate.dump_datetime(saved_definition_template.get_date_modified()), definition_template.get('date_modified'))
        self.assertEqual(saved_definition_template.get_word().get_id(), definition_template.get('word').get('id'))
        self.assertEqual(saved_definition_template.get_definition(), definition_template.get('definition'))
        self.assertEqual(saved_definition_template.get_filler_lexical_classes(), definition_template.get('filler_lexical_classes'))
        self.assertEqual(saved_definition_template.get_is_active(), definition_template.get('is_active'))
Пример #2
0
    def test_delete_deletes_definition_template(self):
        delete_url = '/definition_templates/{}'.format(self.definition_template.get_id())
        self.assertEqual(True, self.definition_template.get_is_active())
        response = self.delete(delete_url)
        self.assertEqual(200, response.status_code)
        definition_template = json.loads(response.data)
        self.assertIsNotNone(definition_template.get('id'))
        self.assertIsNotNone(definition_template.get('date_created'))
        self.assertIsNotNone(definition_template.get('date_modified'))
        self.assertIsNotNone(definition_template.get('word'))
        self.assertIsNotNone(definition_template.get('definition'))
        self.assertIsNotNone(definition_template.get('filler_lexical_classes'))
        self.assertEqual(False, definition_template.get('is_active'))

        # Make sure the definition_template was actually updated in the database
        saved_definition_template = DefinitionTemplatesService.get_instance().get(int(definition_template.get('id')))
        self.assertEqual(saved_definition_template.get_id(), definition_template.get('id'))
        self.assertEqual(DefinitionTemplate.dump_datetime(saved_definition_template.get_date_created()), definition_template.get('date_created'))
        self.assertEqual(DefinitionTemplate.dump_datetime(saved_definition_template.get_date_modified()), definition_template.get('date_modified'))
        self.assertEqual(saved_definition_template.get_word().get_id(), definition_template.get('word').get('id'))
        self.assertEqual(saved_definition_template.get_definition(), definition_template.get('definition'))
        self.assertEqual(saved_definition_template.get_filler_lexical_classes(), definition_template.get('filler_lexical_classes'))
        self.assertEqual(saved_definition_template.get_is_active(), definition_template.get('is_active'))
Пример #3
0
    def test_update_creates_definition_template_and_inactivates_existing_definition_template(self):
        definition_template_id = self.definition_template.get_id()
        update_url = '/definition_templates/{}'.format(definition_template_id)
        self.assertEqual(True, self.definition_template.get_is_active())
        word_id = self.definition_template.get_word().get_id()
        definition = self.definition_template.get_definition()
        filler_lexical_classes = self.definition_template.get_filler_lexical_classes()
        definition_template_data = {
            'word_id': word_id,
            'definition': definition
        }
        response = self.put(update_url, data=definition_template_data)
        self.assertEqual(200, response.status_code)
        definition_template = json.loads(response.data)
        self.assertIsNotNone(definition_template.get('id'))
        self.assertIsNotNone(definition_template.get('date_created'))
        self.assertIsNotNone(definition_template.get('date_modified'))
        self.assertEqual(word_id, definition_template.get('word').get('id'))
        self.assertEqual(definition, definition_template.get('definition'))
        self.assertEqual(filler_lexical_classes, definition_template.get('filler_lexical_classes'))
        self.assertNotEqual(definition_template_id, definition_template.get('id'))
        self.assertIsNotNone(definition_template.get('is_active'))

        # Make sure the definition_template was actually updated in the database
        saved_definition_template = DefinitionTemplatesService.get_instance().get(int(definition_template.get('id')))
        self.assertEqual(saved_definition_template.get_id(), definition_template.get('id'))
        self.assertEqual(DefinitionTemplate.dump_datetime(saved_definition_template.get_date_created()), definition_template.get('date_created'))
        self.assertEqual(DefinitionTemplate.dump_datetime(saved_definition_template.get_date_modified()), definition_template.get('date_modified'))
        self.assertEqual(saved_definition_template.get_word().get_id(), definition_template.get('word').get('id'))
        self.assertEqual(saved_definition_template.get_definition(), definition_template.get('definition'))
        self.assertEqual(saved_definition_template.get_filler_lexical_classes(), definition_template.get('filler_lexical_classes'))
        self.assertEqual(saved_definition_template.get_is_active(), definition_template.get('is_active'))

        # Ensure old definition template was marked inactive
        old_definition_template = DefinitionTemplatesService.get_instance().get(definition_template_id)
        self.assertEqual(False, old_definition_template.get_is_active())