Example #1
0
 def test_unique_constraint_raises_integrity_error(self):
     name_ = 'a'
     word_list = WordList(name=name_,
                          teacher_id=self.test_teacher.teacher_id,
                          document_data={})
     other_word_list = WordList(name=name_,
                                teacher_id=self.test_teacher.teacher_id,
                                document_data={'a': 1})
     self.session.add_all((word_list, other_word_list))
     self.assertRaises(IntegrityError, self.session.commit)
Example #2
0
 def test_foreign_key_constraint(self):
     does_not_exist = self.test_teacher.teacher_id + 1
     name_ = 'x'
     document = {}
     self.session.add(
         WordList(teacher_id=does_not_exist,
                  name=name_,
                  document_data=document))
     self.assertRaises(IntegrityError, self.session.commit)
Example #3
0
 def test_selection_timestamp_is_nullable(self):
     teacher_id = self.test_teacher.teacher_id
     name_ = 'x'
     document = {}
     self.session.add(
         WordList(teacher_id=teacher_id, name=name_,
                  document_data=document))
     self.session.commit()
     retrieved = self.session.query(WordList).first()
     self.assertIsNone(retrieved.selection_timestamp)
Example #4
0
    def test_test_document_can_contain_int_str_list_dict_None(self):
        teacher_id = self.test_teacher.teacher_id
        name_ = 'x'
        document = {'a': None, 'b': 1, 'c': 'a string', 'd': [], 'e': {}}
        self.session.add(
            WordList(teacher_id=teacher_id, name=name_,
                     document_data=document))
        self.session.commit()

        retrieved = self.session.query(WordList).first()
        self.assertEqual(retrieved.document_data, document)
Example #5
0
    def test_unique_constraint_on_teacher_id_and_name(self):
        other_teacher = Teacher(email='other_teacher', password='******')
        self.session.add(other_teacher)
        self.session.commit()

        document = {}

        name_ = 'a'
        other_name = 'b'

        word_list = WordList(name=name_,
                             teacher_id=self.test_teacher.teacher_id,
                             document_data=document)
        different_by_name = WordList(name=other_name,
                                     teacher_id=self.test_teacher.teacher_id,
                                     document_data=document)
        different_by_user = WordList(name=name_,
                                     teacher_id=other_teacher.teacher_id,
                                     document_data=document)
        self.session.add_all((word_list, different_by_name, different_by_user))
        self.assertIsNone(self.session.commit())
Example #6
0
 def test_init(self):
     teacher_id = 1
     name_ = 'x'
     document = {}
     now = datetime.now()
     word_list = WordList(teacher_id=teacher_id,
                          name=name_,
                          document_data=document,
                          selection_timestamp=now)
     self.assertEqual(word_list.teacher_id, teacher_id)
     self.assertEqual(word_list.name, name_)
     self.assertEqual(word_list.document_data, document)
     self.assertEqual(word_list.selection_timestamp, now)
Example #7
0
    def test_foreign_key_on_delete(self):
        teacher_id = self.test_teacher.teacher_id
        name_ = 'x'
        document = {}
        self.session.add(
            WordList(teacher_id=teacher_id, name=name_,
                     document_data=document))
        self.session.commit()

        self.session.delete(self.test_teacher)
        self.session.commit()

        retrieved = self.session.query(WordList).all()
        self.assertEqual(retrieved, [])
Example #8
0
 def test_commit(self):
     teacher_id = self.test_teacher.teacher_id
     name_ = 'x'
     document = {}
     now = datetime.now()
     self.session.add(
         WordList(teacher_id=teacher_id,
                  name=name_,
                  document_data=document,
                  selection_timestamp=now))
     self.session.commit()
     retrieved = self.session.query(WordList).first()
     self.assertEqual(retrieved.teacher_id, teacher_id)
     self.assertEqual(retrieved.name, name_)
     self.assertEqual(retrieved.document_data, document)
     self.assertEqual(retrieved.selection_timestamp, now)
     self.assertIsInstance(retrieved.teacher_id, int)
Example #9
0
    def test_init_and_commit_this_is_a_bad_test_it_tests_many_things(self):
        uncountable_nouns = [{
            'noun': noun.id,
            'definite': bool(index % 2)
        } for index, noun in enumerate(self.uncountable_nouns)]

        word_list_document_data = {
            'verbs': [{
                'verb': self.go.id,
                'particle': self.away.id,
                'preposition': None,
                'objects': 0
            }, {
                'verb': self.play.id,
                'particle': None,
                'preposition': self.away.id,
                'objects': 1
            }],
            'countable_nouns': [noun.id for noun in self.countable_nouns],
            'uncountable_nouns':
            uncountable_nouns,
            'static_nouns': [noun.id for noun in self.static_nouns]
        }
        word_list_name = 'list_name'

        self.session.add(self.test_teacher)
        self.session.commit()

        word_list = WordList(teacher_id=self.test_teacher.teacher_id,
                             name=word_list_name,
                             document_data=word_list_document_data)

        self.session.add(word_list)
        self.session.commit()

        filter_ = WordList.teacher_id == self.test_teacher.teacher_id and WordList.name == word_list_name
        retrieved = self.session.query(WordList).filter(filter_)[
            0]  # type: WordList

        self.assertEqual(retrieved.document_data, word_list_document_data)
        self.assertEqual(retrieved.teacher_id, self.test_teacher.teacher_id)
        self.assertEqual(retrieved.name, word_list_name)
        self.assertIsInstance(retrieved.teacher_id, int)