Esempio n. 1
0
    def test_invalid_configuration(self):
        with self.assertRaises(postgresql_manager.InvalidConfiguration):
            postgresql_manager.DocManager('url')

        self.ospath.isfile.return_value = False

        with self.assertRaises(postgresql_manager.InvalidConfiguration):
            postgresql_manager.DocManager('url', mongoUrl='murl')

        self.psql_module.connect.assert_called_with('url')
        self.mongoclient.assert_called_with('murl')
        self.ospath.isfile.assert_called_with('mappings.json')
Esempio n. 2
0
    def test_valid_configuration(self):
        pconn = MagicMock()
        self.psql_module.connect.return_value = pconn
        cursor = MagicMock()
        pconn.cursor.return_value.__enter__.return_value = cursor

        self.ospath.isfile.return_value = True

        docmgr = postgresql_manager.DocManager('url', mongoUrl='murl')

        self.psql_module.connect.assert_called_with('url')
        self.mongoclient.assert_called_with('murl')
        self.ospath.isfile.assert_called_with('mappings.json')
        self.validate_mapping.assert_called_with(MAPPING)

        self.assertEqual(docmgr.mappings, MAPPING)

        cursor.execute.assert_has_calls([
            call('DROP TABLE col'),
            call(
                'CREATE TABLE col  (_creationdate TIMESTAMP,_id INT CONSTRAINT COL_PK PRIMARY KEY,field1 TEXT ) '
            ),
            call(
                'CREATE TABLE col_field2  (_creationdate TIMESTAMP,_id INT CONSTRAINT COL_FIELD2_PK PRIMARY KEY,id_col INT ,subfield1 TEXT ) '
            ),
            call(
                'CREATE INDEX idx_col__creation_date ON col (_creationdate DESC)'
            )
        ],
                                        any_order=True)

        pconn.commit.assert_called()
Esempio n. 3
0
    def test_valid_configuration(self):
        pconn = MagicMock()
        self.psql_module.connect.return_value = pconn
        cursor = MagicMock()
        pconn.cursor.return_value.__enter__.return_value = cursor

        self.ospath.isfile.return_value = True

        docmgr = postgresql_manager.DocManager('url', mongoUrl='murl')

        self.psql_module.connect.assert_called_with('url')
        pconn.set_session.assert_called_with(deferrable=True)
        self.mongoclient.assert_called_with('murl')
        self.ospath.isfile.assert_called_with('mappings.json')
        self.validate_mapping.assert_called_with(MAPPING)

        self.assertEqual(docmgr.mappings, MAPPING)

        pconn.set_session.assert_called_with(deferrable=True)
        cursor.execute.assert_has_calls([
            call('DROP TABLE IF EXISTS col CASCADE'),
            call(
                'CREATE TABLE col  (_creationdate TIMESTAMP,_id INT CONSTRAINT COL_PK PRIMARY KEY,field1 TEXT ) '
            ),
            call(
                'CREATE TABLE col_field2  (_creationdate TIMESTAMP,_id SERIAL CONSTRAINT COL_FIELD2_PK PRIMARY KEY,id_col INT ,subfield1 TEXT ) '
            ),
            call(
                'CREATE TABLE col_field2_subfield2  (_creationdate TIMESTAMP,_id SERIAL CONSTRAINT COL_FIELD2_SUBFIELD2_PK PRIMARY KEY,id_col_field2 SERIAL ,scalar INT ) '
            ),
            call(
                'CREATE INDEX idx_col__creation_date ON col (_creationdate DESC)'
            ),
            call(
                'ALTER TABLE col_field2 ADD CONSTRAINT col_field2_id_col_fk FOREIGN KEY (id_col) REFERENCES col(_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED'
            )
        ],
                                        any_order=True)

        pconn.commit.assert_called()
Esempio n. 4
0
    def setUp(self):
        super(TestManager, self).setUp()

        self.mconn = MagicMock()
        self.mdb = MagicMock()
        self.mcol = MagicMock()

        self.mongoclient.return_value = self.mconn
        self.mconn.__getitem__.return_value = self.mdb
        self.mdb.__getitem__.return_value = self.mcol

        self.pconn = MagicMock()
        self.psql_module.connect.return_value = self.pconn
        self.cursor = MagicMock()
        self.cursor.__enter__.return_value = self.cursor
        self.pconn.cursor.return_value = self.cursor

        self.ospath.isfile.return_value = True

        self.docmgr = postgresql_manager.DocManager('url',
                                                    mongoUrl='murl',
                                                    chunk_size=2)