Exemplo n.º 1
0
 def gengo_authentication(self, cr, uid, context=None):
     '''
     This method tries to open a connection with Gengo. For that, it uses the Public and Private
     keys that are linked to the company (given by Gengo on subscription). It returns a tuple with
      * as first element: a boolean depicting if the authentication was a success or not
      * as second element: the connection, if it was a success, or the error message returned by
         Gengo when the connection failed.
         This error message can either be displayed in the server logs (if the authentication was called
         by the cron) or in a dialog box (if requested by the user), thus it's important to return it
         translated.
     '''
     user = self.pool.get('res.users').browse(cr, 1, uid, context=context)
     if not user.company_id.gengo_public_key or not user.company_id.gengo_private_key:
         return (False, _("Gengo `Public Key` or `Private Key` are missing. Enter your Gengo authentication parameters under `Settings > Companies > Gengo Parameters`."))
     try:
         gengo = Gengo(
             public_key=user.company_id.gengo_public_key.encode('ascii'),
             private_key=user.company_id.gengo_private_key.encode('ascii'),
             sandbox=user.company_id.gengo_sandbox,
         )
         gengo.getAccountStats()
         return (True, gengo)
     except Exception, e:
         _logger.exception('Gengo connection failed')
         return (False, _("Gengo connection failed with this message:\n``%s``") % e)
Exemplo n.º 2
0
 def gengo_authentication(self, cr, uid, context=None):
     '''
     This method tries to open a connection with Gengo. For that, it uses the Public and Private
     keys that are linked to the company (given by Gengo on subscription). It returns a tuple with
      * as first element: a boolean depicting if the authentication was a success or not
      * as second element: the connection, if it was a success, or the error message returned by
         Gengo when the connection failed.
         This error message can either be displayed in the server logs (if the authentication was called
         by the cron) or in a dialog box (if requested by the user), thus it's important to return it
         translated.
     '''
     user = self.pool.get('res.users').browse(cr, 1, uid, context=context)
     if not user.company_id.gengo_public_key or not user.company_id.gengo_private_key:
         return (
             False,
             _("Gengo `Public Key` or `Private Key` are missing. Enter your Gengo authentication parameters under `Settings > Companies > Gengo Parameters`."
               ))
     try:
         gengo = Gengo(
             public_key=user.company_id.gengo_public_key.encode('ascii'),
             private_key=user.company_id.gengo_private_key.encode('ascii'),
             sandbox=user.company_id.gengo_sandbox,
         )
         gengo.getAccountStats()
         return (True, gengo)
     except Exception, e:
         _logger.exception('Gengo connection failed')
         return (False,
                 _("Gengo connection failed with this message:\n``%s``") %
                 e)
Exemplo n.º 3
0
class TestAccountMethods(unittest.TestCase):
    """
    Tests the methods that deal with retrieving basic information about
    the account you're authenticating as. Checks for one property on
    each method.
    """
    def setUp(self):
        self.gengo = Gengo(public_key=API_PUBKEY,
                           private_key=API_PRIVKEY,
                           sandbox=True)

        self.json_mock = mock.Mock()
        self.json_mock.json.return_value = {'opstat': 'ok'}
        self.getMock = RequestsMock(return_value=self.json_mock)
        self.requestsPatch = mock.patch.object(requests, 'get', self.getMock)
        self.requestsPatch.start()

    def tearDown(self):
        self.requestsPatch.stop()

    def test_getAccountStats(self):
        stats = self.gengo.getAccountStats()
        self.assertEqual(stats['opstat'], 'ok')
        self.getMock.assert_path_contains(
            gengo.mockdb.apihash['getAccountStats']['url'])

    def test_getAccountBalance(self):
        balance = self.gengo.getAccountBalance()
        self.assertEqual(balance['opstat'], 'ok')
        self.getMock.assert_path_contains(
            gengo.mockdb.apihash['getAccountBalance']['url'])
Exemplo n.º 4
0
class TestAccountMethods(unittest.TestCase):

    """
    Tests the methods that deal with retrieving basic information about
    the account you're authenticating as. Checks for one property on
    each method.
    """
    def setUp(self):
        self.gengo = Gengo(public_key=API_PUBKEY,
                           private_key=API_PRIVKEY,
                           sandbox=True)

        from gengo import requests
        self.json_mock = mock.Mock()
        self.json_mock.json.return_value = {'opstat': 'ok'}
        self.getMock = RequestsMock(return_value=self.json_mock)
        self.requestsPatch = mock.patch.object(requests, 'get', self.getMock)
        self.requestsPatch.start()

    def tearDown(self):
        self.requestsPatch.stop()

    def test_getAccountStats(self):
        stats = self.gengo.getAccountStats()
        self.assertEqual(stats['opstat'], 'ok')
        self.getMock.assert_path_contains(
            mockdb.apihash['getAccountStats']['url'])

    def test_getAccountBalance(self):
        balance = self.gengo.getAccountBalance()
        self.assertEqual(balance['opstat'], 'ok')
        self.getMock.assert_path_contains(
            mockdb.apihash['getAccountBalance']['url'])
Exemplo n.º 5
0
class TestAccountMethods(unittest.TestCase):
    """
    Tests the methods that deal with retrieving basic information about
    the account you're authenticating as. Checks for one property on
    each method.
    """
    def setUp(self):
        self.gengo = Gengo(public_key=API_PUBKEY, private_key=API_PRIVKEY)
        self.gengo.api_url = 'http://api.staging.gengo.com/%(version)s'

    def test_getAccountStats(self):
        stats = self.gengo.getAccountStats()
        self.assertEqual(stats['opstat'], 'ok')

    def test_getAccountBalance(self):
        balance = self.gengo.getAccountBalance()
        self.assertEqual(balance['opstat'], 'ok')
Exemplo n.º 6
0
class TestAccountMethods(unittest.TestCase):
    """
    Tests the methods that deal with retrieving basic information about
    the account you're authenticating as. Checks for one property on
    each method.
    """
    def setUp(self):
        self.gengo = Gengo(public_key=API_PUBKEY,
                           private_key=API_PRIVKEY,
                           sandbox=True)

    def test_getAccountStats(self):
        stats = self.gengo.getAccountStats()
        self.assertEqual(stats['opstat'], 'ok')

    def test_getAccountBalance(self):
        balance = self.gengo.getAccountBalance()
        self.assertEqual(balance['opstat'], 'ok')
Exemplo n.º 7
0
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# Neither the name of myGengo, Inc. nor the names of its contributors may
# be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from gengo import Gengo

# Get an instance of Gengo to work with...
gengo = Gengo(
    public_key='your_public_key',
    private_key='your_private_key',
    sandbox=False,
)

# Print the account stats...
print gengo.getAccountStats()
Exemplo n.º 8
0
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# Neither the name of Gengo, Inc. nor the names of its contributors may
# be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from gengo import Gengo

# Get an instance of Gengo to work with...
gengo = Gengo(
    public_key='your_public_key',
    private_key='your_private_key',
    sandbox=False,
    debug=True
)

# Print the account stats...
print(gengo.getAccountStats())
Exemplo n.º 9
0
# this list of conditions and the following disclaimer.
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# Neither the name of Gengo, Inc. nor the names of its contributors may
# be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from gengo import Gengo

# Get an instance of Gengo to work with...
gengo = Gengo(public_key='your_public_key',
              private_key='your_private_key',
              sandbox=False,
              debug=True)

# Print the account stats...
print(gengo.getAccountStats())