From 252f279101b0573ee9bde52dcca60016b92ab476 Mon Sep 17 00:00:00 2001 From: Loek van Gent Date: Thu, 9 Jun 2022 12:49:00 +0200 Subject: [PATCH] Try workflow --- .github/workflows/django.yml | 71 ++++++++++++++++++++++++++++++++++ .travis.yml | 2 +- bluebottle/settings/github.py | 18 +++++++++ bluebottle/settings/testing.py | 2 +- bluebottle/test/test_runner.py | 62 ----------------------------- 5 files changed, 91 insertions(+), 64 deletions(-) create mode 100644 .github/workflows/django.yml create mode 100644 bluebottle/settings/github.py delete mode 100644 bluebottle/test/test_runner.py diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml new file mode 100644 index 0000000000..0464daa1db --- /dev/null +++ b/.github/workflows/django.yml @@ -0,0 +1,71 @@ +name: Django CI + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + test: + runs-on: ubuntu-latest + services: + db: + image: postgis/postgis:11-2.5 + env: + POSTGRES_USER: bb + POSTGRES_PASSWORD: bb + POSTGRES_DB: test_bluebottle_test + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + elasticsearch: + image: docker.elastic.co/elasticsearch/elasticsearch:6.8.23 + env: + discovery.type: single-node + options: >- + --health-cmd "curl http://localhost:9200/_cluster/health" + --health-interval 10s + --health-timeout 5s + --health-retries 10 + ports: + - 9200:9200 + redis: + image: redis + ports: + - 6379:6379 + celery: + image: celery + strategy: + matrix: + python-version: [3.7] + + steps: + - uses: actions/checkout@v3 + - name: Install packages + run: sudo apt-get install -y libxmlsec1 libxmlsec1-dev libgdal-dev openjdk-8-jdk-headless + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Test data + run: | + psql -h localhost -U bb test_bluebottle_test < testdata.sql + env: + PGPASSWORD: bb + - name: Setup Locale + run: | + export LC_ALL="en_US.UTF-8" + export LC_CTYPE="en_US.UTF-8" + sudo dpkg-reconfigure locales + - uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ hashFiles('setup.py') }}-${{ hashFiles('setup.py') }} + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -e .[test] --trusted-host github.com + - name: Run Tests + run: | + python -m coverage run --parallel-mode --source=bluebottle manage.py test --parallel=8 --keepdb --settings bluebottle.settings.github diff --git a/.travis.yml b/.travis.yml index c9118ddf68..795eb054a6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,7 +41,7 @@ install: before_script: - flake8 . script: - - python -m coverage run --parallel-mode --source=bluebottle manage.py test --keepdb + - python -m coverage run --parallel-mode --source=bluebottle manage.py test --parallel=8 --keepdb notifications: slack: secure: TOveMBh9HePYKWuGTrWF+hTXzxGZvbVsa3KU0sB1yv6qkcixb5/ggvmkTeRddYEd/zyWyMenicFsrXVBgsP0SmbNgke6kq5+EN0U5oJWse998lvCVCpwmJQMdwDHvYsOtbFEOppQrbRK4vmH8qibx3x2YVg+u+61ePHvWYF9z6U= diff --git a/bluebottle/settings/github.py b/bluebottle/settings/github.py new file mode 100644 index 0000000000..f5db63b5b8 --- /dev/null +++ b/bluebottle/settings/github.py @@ -0,0 +1,18 @@ +# flake8: noqa + +from .testing import * + +DATABASES = { + 'default': { + "ENGINE": "bluebottle.clients.postgresql_backend", + 'HOST': 'localhost', + 'PORT': '5432', + 'NAME': 'bluebottle_test', + 'USER': 'bb', + 'PASSWORD': 'bb' + } +} + +PASSWORD_HASHERS = ['django.contrib.auth.hashers.MD5PasswordHasher'] + +DEBUG = False diff --git a/bluebottle/settings/testing.py b/bluebottle/settings/testing.py index d7e9907b68..44bb2a4210 100644 --- a/bluebottle/settings/testing.py +++ b/bluebottle/settings/testing.py @@ -145,7 +145,7 @@ } -TEST_RUNNER = 'bluebottle.test.test_runner.MultiTenantRunner' +TEST_RUNNER = 'django_slowtests.testrunner.DiscoverSlowestTestsRunner' NUM_SLOW_TESTS = 50 DEBUG = False diff --git a/bluebottle/test/test_runner.py b/bluebottle/test/test_runner.py deleted file mode 100644 index 555407fe06..0000000000 --- a/bluebottle/test/test_runner.py +++ /dev/null @@ -1,62 +0,0 @@ -import locale -from builtins import range - -from django.db import connection, IntegrityError -from django_slowtests.testrunner import DiscoverSlowestTestsRunner -from djmoney.contrib.exchange.models import Rate, ExchangeBackend -from tenant_schemas.utils import get_tenant_model - -from bluebottle.test.utils import InitProjectDataMixin - - -class MultiTenantRunner(DiscoverSlowestTestsRunner, InitProjectDataMixin): - def setup_databases(self, *args, **kwargs): - parallel = self.parallel - self.parallel = 0 - result = super(MultiTenantRunner, self).setup_databases(**kwargs) - self.parallel = parallel - # Set local explicitely so test also run on OSX - locale.setlocale(locale.LC_ALL, 'en_GB.UTF-8') - - connection.set_schema_to_public() - - tenant2, _created = get_tenant_model().objects.get_or_create( - domain_url='testserver2', - name='Test Too', - schema_name='test2', - client_name='test2') - - connection.set_tenant(tenant2) - self.init_projects() - - connection.set_schema_to_public() - - tenant, _created = get_tenant_model().objects.get_or_create( - domain_url='testserver', - name='Test', - schema_name='test', - client_name='test') - - connection.set_tenant(tenant) - self.init_projects() - - try: - backend, _created = ExchangeBackend.objects.get_or_create(base_currency='USD') - Rate.objects.update_or_create(backend=backend, currency='USD', defaults={'value': 1}) - Rate.objects.update_or_create(backend=backend, currency='EUR', defaults={'value': 1.5}) - Rate.objects.update_or_create(backend=backend, currency='XOF', defaults={'value': 1000}) - Rate.objects.update_or_create(backend=backend, currency='NGN', defaults={'value': 500}) - Rate.objects.update_or_create(backend=backend, currency='UGX', defaults={'value': 5000}) - Rate.objects.update_or_create(backend=backend, currency='KES', defaults={'value': 100}) - except IntegrityError: - pass - - if parallel > 1: - for index in range(parallel): - connection.creation.clone_test_db( - number=index + 1, - verbosity=self.verbosity, - keepdb=self.keepdb, - ) - - return result