Пример #1
0
    def test_history_save_no_commit(self):
        """Test that non commited data is not saved to the database."""
        response_history = ResponseHistory("RESPONSE")
        response_history.save()

        DB.session.rollback()
        self.assertFalse(ResponseHistory.query.all())
Пример #2
0
    def test_history_non_string(self):
        """Test that a non string response cannot be commited to history."""
        response_history = ResponseHistory(420)
        response_history.save()

        with self.assertRaises(ProgrammingError):
            DB.session.commit()
Пример #3
0
    def test_history_empty(self):
        """Test that an empty response cannot be commited to history."""
        response_history = ResponseHistory("")
        response_history.save()

        with self.assertRaises(ProgrammingError):
            DB.session.commit()
Пример #4
0
    def test_history_uid_non_int(self):
        """Test that a non int uid response cannot be commited to history."""
        response_history = ResponseHistory("WOW")
        response_history.uid = "Test"
        response_history.save()

        with self.assertRaises(ProgrammingError):
            DB.session.commit()
Пример #5
0
    def test_history_save_commit(self):
        """Test that data is commited and saved to the database."""
        response_history = ResponseHistory("RESPONSE")
        response_history.save()
        DB.session.commit()

        DB.session.rollback()
        self.assertTrue(len(ResponseHistory.query.all()) == 1)
        self.assertTrue(ResponseHistory.query.all()[0].response == "RESPONSE")
Пример #6
0
    def test_history_save_arb_id(self):
        """Test that data is commited and saved to the database even if uid is assigned manually."""
        response_history = ResponseHistory("RESPONSE")
        response_history.uid = 420
        response_history.save()
        DB.session.commit()

        DB.session.rollback()
        self.assertTrue(len(ResponseHistory.query.all()) == 1)
        self.assertTrue(ResponseHistory.query.all()[0].response == "RESPONSE")
        self.assertTrue(ResponseHistory.query.all()[0].uid == 420)
Пример #7
0
    def setUpClass(cls):
        """Add default test responses."""
        KaosTestCase.setUpClass()

        cls.response_data = '{"working": "true"}'
        cls.response = ResponseHistory(cls.response_data)
        cls.response.save()

        DB.session.commit()
Пример #8
0
    def test_history_save_same_id(self):
        """Test that we can't have two records with the same pk."""
        response_history_1 = ResponseHistory("RESPONSE_1")
        response_history_1.save()
        DB.session.commit()

        DB.session.rollback()
        self.assertTrue(len(ResponseHistory.query.all()) == 1)
        self.assertTrue(
            ResponseHistory.query.all()[0].response == "RESPONSE_1")

        response_history_2 = ResponseHistory("RESPONSE_2")
        response_history_2.uid = response_history_1.uid
        del response_history_1
        response_history_2.save()
        with self.assertRaises(IntegrityError):
            DB.session.commit()