Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package
name: Python lint

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

jobs:
build:
Expand All @@ -20,15 +21,15 @@ jobs:
# python-version: [2.7, 3.5, 3.6, 3.7, 3.8, pypy2, pypy3]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install virtualenv
run: |
python -m pip install --upgrade pip
pip install virtualenv
- name: Run lint with pre-commit hooks
run: |
make check
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install virtualenv
run: |
python -m pip install --upgrade pip
pip install virtualenv
- name: Run lint
run: |
make check
33 changes: 17 additions & 16 deletions .github/workflows/pythonpublish.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

Expand All @@ -13,19 +14,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
38 changes: 38 additions & 0 deletions .github/workflows/pythontests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python tests

on:
push:
branches: [master]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7]
# Eventually, when running tests this should be done for all versions
# python-version: [2.7, 3.5, 3.6, 3.7, 3.8, pypy2, pypy3]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox
- name: Run tests
env:
SF_USERNAME: ${{ secrets.SF_USERNAME }}
SF_PASSWORD: ${{ secrets.SF_PASSWORD }}
SF_SECTOKEN: ${{ secrets.SF_SECTOKEN }}
SF_HOSTNAME: ${{ secrets.SF_HOSTNAME }}
run: |
make test
1 change: 1 addition & 0 deletions pyforce/xmlclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ def post(self, conn=None, alwaysReturnList=False):
self.serverUrl,
data=envelope,
headers=headers,
timeout=10,
)
except requests.exceptions.ConnectionError as ex:
attempt += 1
Expand Down
50 changes: 29 additions & 21 deletions tests/benchmark_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

BENCHMARK_REPS = 1

SERVER_URL = "https://test.salesforce.com/services/Soap/u/20.0"
DEFAULT_HOSTNAME = "test.salesforce.com"


def benchmark(func):
Expand All @@ -33,50 +33,53 @@ def benchmarked_func(self):
class TestUtils(unittest.TestCase):

def setUp(self):
self.svc = svc = pyforce.PythonClient(serverUrl=SERVER_URL)
svc.login(os.getenv('SF_USERNAME'), os.getenv('SF_PASSWORD'))
hostname = os.getenv('SF_HOSTNAME', DEFAULT_HOSTNAME)
server_url = "https://{}/services/Soap/u/20.0".format(hostname)
self.svc = pyforce.PythonClient(serverUrl=server_url)
password = os.getenv('SF_PASSWORD') + os.getenv('SF_SECTOKEN', '')
self.svc.login(os.getenv('SF_USERNAME'), password)
self._todelete = list()

def tearDown(self):
svc = self.svc
ids = self._todelete
if ids:
while len(ids) > 200:
svc.delete(ids[:200])
self.svc.delete(ids[:200])
ids = ids[200:]
if ids:
svc.delete(ids)
self.svc.delete(ids)
self._todelete = list()

@benchmark
def testDescribeSObjects(self):
svc = self.svc
globalres = svc.describeGlobal()
globalres = self.svc.describeGlobal()
types = globalres['types']
res = svc.describeSObjects(types[0])
res = self.svc.describeSObjects(types[0])
self.assertEqual(type(res), list)
self.assertEqual(len(res), 1)
res = svc.describeSObjects(types[:100])
res = self.svc.describeSObjects(types[:100])
self.assertEqual(len(types[:100]), len(res))

@benchmark
def testCreate(self):
svc = self.svc
data = dict(type='Contact',
LastName='Doe',
FirstName='John',
Phone='123-456-7890',
Email='john@doe.com',
Birthdate=datetime.date(1970, 1, 4)
)
res = svc.create([data])
res = self.svc.create([data])
self.assertTrue(type(res) in (list, tuple))
self.assertTrue(len(res) == 1)
self.assertTrue(res[0]['success'])
id = res[0]['id']
self._todelete.append(id)
contacts = svc.retrieve('LastName, FirstName, Phone, Email, Birthdate',
'Contact', [id])
contacts = self.svc.retrieve(
'LastName, FirstName, Phone, Email, Birthdate',
'Contact',
[id],
)
self.assertEqual(len(contacts), 1)
contact = contacts[0]
for k in ['LastName', 'FirstName', 'Phone', 'Email', 'Birthdate']:
Expand All @@ -85,15 +88,14 @@ def testCreate(self):

@benchmark
def testQuery(self):
svc = self.svc
data = dict(type='Contact',
LastName='Doe',
FirstName='John',
Phone='123-456-7890',
Email='john@doe.com',
Birthdate=datetime.date(1970, 1, 4)
)
res = svc.create([data])
res = self.svc.create([data])
self._todelete.append(res[0]['id'])
data2 = dict(type='Contact',
LastName='Doe',
Expand All @@ -102,16 +104,22 @@ def testQuery(self):
Email='jane@doe.com',
Birthdate=datetime.date(1972, 10, 15)
)
res = svc.create([data2])
res = self.svc.create([data2])
janeid = res[0]['id']
self._todelete.append(janeid)
res = svc.query('LastName, FirstName, Phone, Email, Birthdate',
'Contact', "LastName = 'Doe'")
res = self.svc.query(
'LastName, FirstName, Phone, Email, Birthdate',
'Contact',
"LastName = 'Doe'",
)
self.assertEqual(len(res), 2)
self.assertEqual(res['size'], 2)
self.assertEqual(res.size, 2)
res = svc.query('Id, LastName, FirstName, Phone, Email, Birthdate',
'Contact', "LastName = 'Doe' and FirstName = 'Jane'")
res = self.svc.query(
'Id, LastName, FirstName, Phone, Email, Birthdate',
'Contact',
"LastName = 'Doe' and FirstName = 'Jane'",
)
self.assertEqual(len(res), 1)
self.assertEqual(res[0]['Id'], janeid)
self.tearDown()
Expand Down
Loading