Exemplo n.º 1
0
    def test_new_empty_config(self):
        """ Should make a new empty config """
        # set up
        mock_rowcount = PropertyMock(return_value=0)
        type(self.mock_get_cur.return_value).rowcount = mock_rowcount
        self.mock_get_cur.return_value.fetchone.return_value = (1,)

        # run SUT
        new_config_id = new_config()

        # confirm appropriate sql was executed for an empty config
        self.mock_get_cur.return_value.execute.assert_called_once_with(
            "INSERT INTO config (key_value_pairs) VALUES (%s) RETURNING config_id",
            ('',),
        )

        # confirm we have a reasonable id
        self.assertEqual(type(new_config_id), type(0))
Exemplo n.º 2
0
    def test_new_config_based_on_old_config(self):
        """ Should make a new config based on an old one """
        # set up
        get_config_patcher = patch(
            'factories.get_config',
            return_value = {
                'config_id': 101,
                'key_value_pairs': "mockKey=mockVal",
            }
        )
        mock_get_config = get_config_patcher.start()

        # run SUT
        new_config_id = new_config(101)

        # confirm correct sql was executed once
        self.mock_get_cur.return_value.execute.assert_called_once_with(
            "INSERT INTO config (key_value_pairs) VALUES (%s) RETURNING config_id",
            ('mockKey=mockVal',)
        )

        # confirm that we got config 101
        mock_get_config.assert_called_once_with(101)