Esempio n. 1
0
    def test_new_env_based_on_old_env(self):
        """ Should make a new env based on an old one """
        # set up
        get_env_patcher = patch(
            'factories.get_env',
            return_value = {
                'environment_id': 101,
                'settings': "mockKey=mockVal",
                'infrastructure_backend': 'mock_backend',
            }
        )
        mock_get_env = get_env_patcher.start()

        # run SUT
        new_env_id = new_env(57)

        # confirm correct sql was executed once
        self.mock_get_cur.return_value.execute.assert_called_once_with(
            "INSERT INTO environment\n" + \
            "(settings, infrastructure_backend, environment_name)\n" + \
            "VALUES (%s, %s, %s)\n" + \
            "RETURNING environment_id",
            ('mockKey=mockVal', 'mock_backend', 'qa-sandbox'),
        )

        # confirm that we got environment 57
        mock_get_env.assert_called_once_with(57)
Esempio n. 2
0
    def test_new_empty_env(self):
        """ Should make a new environment """
        # 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_env_id = new_env()

        # confirm correct sql
        self.mock_get_cur.return_value.execute.assert_called_once_with(
            "INSERT INTO environment\n" + \
            "(settings, infrastructure_backend, environment_name)\n" + \
            "VALUES (%s, %s, %s)\n" + \
            "RETURNING environment_id",
            ('', 'mockdib', 'qa-sandbox'),
        )

        # confirm that we got a reasonable id
        self.assertEqual(type(new_env_id), type(0))