Renaming infra/build/functions files (#4031)

Renamed main.py to sync.py
and test_sync.py to sync_test.py

Co-authored-by: Kabeer Seth <kabeerseth@google.com>
This commit is contained in:
kabeer27 2020-06-29 01:10:47 +00:00 committed by GitHub
parent eaae983c73
commit d15dc2a88f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 11 deletions

View File

@ -20,7 +20,19 @@ jobs:
python-version: 3.7
- name: Install dependencies
run: pip install -r infra/ci/requirements.txt
run:
pip install -r infra/ci/requirements.txt
pip install -r infra/build/functions/requirements.txt
- uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
with:
version: '298.0.0'
- run:
gcloud components install beta cloud-datastore-emulator &&
gcloud info
- name: Run infra tests
run: python infra/presubmit.py infra-tests

View File

@ -23,13 +23,15 @@ import threading
from google.cloud import ndb
from main import sync_projects
from main import get_projects
from main import get_access_token
from main import Project
from sync import sync_projects
from sync import get_projects
from sync import get_access_token
from sync import Project
_EMULATOR_TIMEOUT = 20
_DATASTORE_READY_INDICATOR = b'is now running'
_DATASTORE_EMULATOR_PORT = 8432
_TEST_PROJECT_ID = 'test-project'
def start_datastore_emulator():
@ -41,8 +43,8 @@ def start_datastore_emulator():
'datastore',
'start',
'--consistency=1.0',
'--host-port=localhost:' + str(os.environ.get('DATASTORE_EMULATOR_PORT')),
'--project=' + os.environ.get('DATASTORE_PROJECT_ID'),
'--host-port=localhost:' + str(_DATASTORE_EMULATOR_PORT),
'--project=' + _TEST_PROJECT_ID,
'--no-store-on-disk',
],
stdout=subprocess.PIPE,
@ -102,6 +104,16 @@ class Repository:
class TestDataSync(unittest.TestCase):
"""Unit tests for sync."""
@classmethod
def setUpClass(cls):
ds_emulator = start_datastore_emulator()
_wait_for_emulator_ready(ds_emulator, 'datastore',
_DATASTORE_READY_INDICATOR)
os.environ['DATASTORE_EMULATOR_HOST'] = 'localhost:' + str(
_DATASTORE_EMULATOR_PORT)
os.environ['GOOGLE_CLOUD_PROJECT'] = _TEST_PROJECT_ID
os.environ['DATASTORE_DATASET'] = _TEST_PROJECT_ID
def test_sync_projects(self):
"""Testing sync_projects()."""
client = ndb.Client()
@ -116,6 +128,8 @@ class TestDataSync(unittest.TestCase):
projects_query = Project.query()
self.assertEqual(projects, {project.name for project in projects_query})
# Todo: Clean datastore in case of new tests relating to same entities.
def test_get_projects(self):
"""Testing get_projects()."""
@ -175,10 +189,12 @@ class TestDataSync(unittest.TestCase):
with client.context():
self.assertRaises(RuntimeError, get_access_token)
@classmethod
def tearDownClass(cls):
# TODO: replace this with a cleaner way of killing the process
os.system('pkill -f datastore')
if __name__ == '__main__':
DS_EMULATOR = start_datastore_emulator()
_wait_for_emulator_ready(DS_EMULATOR, 'datastore', _DATASTORE_READY_INDICATOR)
unittest.main(exit=False)
# TODO: replace this with a cleaner way of killing the process
os.system('pkill -f datastore')