Example #1
0
class QiitaBaseTest(TestCase):
    """Tests that the base class functions act correctly"""

    def setUp(self):
        # We need an actual subclass in order to test the equality functions
        self.tester = RawData(1)
        self.portal = qiita_config.portal

    def tearDown(self):
        qiita_config.portal = self.portal

    def test_init_base_error(self):
        """Raises an error when instantiating a base class directly"""
        with self.assertRaises(IncompetentQiitaDeveloperError):
            QiitaObject(1)

    def test_init_error_inexistent(self):
        """Raises an error when instantiating an object that does not exists"""
        with self.assertRaises(QiitaDBUnknownIDError):
            RawData(10)

    def test_check_subclass(self):
        """Nothing happens if check_subclass called from a subclass"""
        self.tester._check_subclass()

    def test_check_subclass_error(self):
        """check_subclass raises an error if called from a base class"""
        # Checked through the __init__ call
        with self.assertRaises(IncompetentQiitaDeveloperError):
            QiitaObject(1)
        with self.assertRaises(IncompetentQiitaDeveloperError):
            QiitaStatusObject(1)

    def test_check_id(self):
        """Correctly checks if an id exists on the database"""
        self.assertTrue(self.tester._check_id(1))
        self.assertFalse(self.tester._check_id(100))

    def test_check_portal(self):
        """Correctly checks if object is accessable in portal given"""
        qiita_config.portal = 'QIITA'
        tester = Analysis(1)
        self.assertTrue(tester._check_portal(1))
        qiita_config.portal = 'EMP'
        self.assertFalse(tester._check_portal(1))

        self.assertTrue(self.tester._check_portal(1))

    def test_equal_self(self):
        """Equality works with the same object"""
        self.assertEqual(self.tester, self.tester)

    def test_equal(self):
        """Equality works with two objects pointing to the same instance"""
        new = RawData(1)
        self.assertEqual(self.tester, new)

    def test_not_equal(self):
        """Not equals works with object of the same type"""
        sp1 = StudyPerson(1)
        sp2 = StudyPerson(2)
        self.assertNotEqual(sp1, sp2)

    def test_not_equal_type(self):
        """Not equals works with object of different type"""
        new = Study(1)
        self.assertNotEqual(self.tester, new)