コード例 #1
0
 def test_password_score_not_unique(self):
     password = '******'
     score = 100
     first = Student(password=password, email='a', score=score)
     second = Student(password=password, email='b', score=score)
     self.session.add_all([first, second])
     self.assertIsNone(self.session.commit())
コード例 #2
0
 def test_email_unique_constraint_allows_multiple_None_values(self):
     password = '******'
     score = 1
     student = Student(password=password, score=score)
     other_student = Student(password=password, score=score)
     self.session.add_all((student, other_student))
     student_list = self.session.query(Student).all()
     self.assertEqual(len(student_list), 2)
     self.assertNotEqual(student_list[0].student_id, student_list[1].student_id)
コード例 #3
0
    def test_get_json_student(self):
        email = 'email'
        password = '******'
        score = 10

        student = Student(password, email, score)
        self.session.add(student)
        self.session.commit()
        expected = {
            'email': email,
            'score': score,
            'student_id': student.student_id
        }
        self.assertEqual(student.get_json(), expected)
コード例 #4
0
 def test_commit_with_default_email(self):
     student = Student(password='******', score=1)
     self.session.add(student)
     self.session.commit()
     answer = self.session.query(Student).first()
     self.assertEqual(answer, student)
     self.assertIsNone(answer.email)
コード例 #5
0
 def test_commit_with_default_score(self):
     student = Student(password='******', email='email')
     self.session.add(student)
     self.session.commit()
     answer = self.session.query(Student).first()
     self.assertEqual(answer, student)
     self.assertEqual(answer.score, 0)
コード例 #6
0
 def test_commit_all_fields(self):
     student = Student(password='******', email='email', score=0)
     self.session.add(student)
     self.session.commit()
     answer = self.session.query(Student).first()
     self.assertEqual(answer, student)
     self.assertIsInstance(answer.student_id, int)
コード例 #7
0
 def test_init(self):
     email = '*****@*****.**'
     password = '******'
     score = 243758
     student = Student(password=password, email=email, score=score)
     self.assertEqual(student.email, email)
     self.assertEqual(student.password, password)
     self.assertEqual(student.score, score)
コード例 #8
0
 def test_email_nullable(self):
     student = Student(password='******', email=None, score=0)
     self.session.add(student)
     self.assertIsNone(self.session.commit())
コード例 #9
0
 def test_email_unique_constraint(self):
     email = '*****@*****.**'
     student = Student(password='******', email=email, score=1)
     same_student_name = Student(password='******', email=email, score=2)
     self.session.add_all([student, same_student_name])
     self.assertRaises(IntegrityError, self.session.commit)
コード例 #10
0
 def test_init_email_defaults_to_None(self):
     student = Student(password='******')
     self.assertIsNone(student.email)
コード例 #11
0
 def test_init_score_defaults_to_zero(self):
     student = Student(password='******', email='email')
     self.assertEqual(student.score, 0)
コード例 #12
0
 def create_student(self, password: str, email: str = None, score: int = 0) -> dict:
     student = Student(password=password, email=email, score=score)
     return self._commit_and_get_json(student)