Skip to content

Commit

Permalink
basic github-actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
aaxelb committed Nov 29, 2023
1 parent 27df64b commit 61e7fce
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length = 107
per-file-ignores =
# E501 line too long (fine in migrations)
addon_service/migrations/*.py: E501
58 changes: 58 additions & 0 deletions .github/workflows/run_gravyvalet_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: run_gravyvalet_tests

on:
push:
pull_request:
workflow_dispatch:

jobs:
run_tests:
strategy:
fail-fast: false
matrix: # use to test upgrades before upgrading
python-version: ['3.12']
postgres-version: ['15']
runs-on: ubuntu-latest
services:
postgres:
image: postgres:${{ matrix.postgres-version }}
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4

- name: install non-py dependencies
run: sudo apt-get update && sudo apt-get install -y libpq-dev

- name: set up python${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
requirements/requirements.txt
requirements/dev-requirements.txt
- name: install py dependencies
run: pip install -r requirements/dev-requirements.txt

- name: does it plac8 flake8?
run: flake8 .

- name: run tests
run: python3 manage.py test
env:
DEBUG: 1
POSTGRES_HOST: postgres
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
SECRET_KEY: oh-so-secret
7 changes: 5 additions & 2 deletions addon_service/authorized_storage_account/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.contrib.postgres.fields import ArrayField
# from django.contrib.postgres.fields import ArrayField
from django.db import models

from addon_service.common.base_model import AddonsServiceBaseModel
Expand All @@ -9,7 +9,10 @@ class AuthorizedStorageAccount(AddonsServiceBaseModel):
# TODO: capability_set = ArrayField(models.CharField(max_length=128), default=list, blank=True)
default_root_folder = models.CharField(blank=True)

external_storage_service = models.ForeignKey('addon_service.ExternalStorageService', on_delete=models.CASCADE)
external_storage_service = models.ForeignKey(
'addon_service.ExternalStorageService',
on_delete=models.CASCADE,
)
external_account = models.ForeignKey('addon_service.ExternalAccount', on_delete=models.CASCADE)

class Meta:
Expand Down
5 changes: 4 additions & 1 deletion addon_service/configured_storage_addon/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ class ConfiguredStorageAddon(AddonsServiceBaseModel):

root_folder = models.CharField()

authorized_storage_account = models.ForeignKey('addon_service.AuthorizedStorageAccount', on_delete=models.CASCADE)
authorized_storage_account = models.ForeignKey(
'addon_service.AuthorizedStorageAccount',
on_delete=models.CASCADE,
)
internal_resource = models.ForeignKey(
'addon_service.InternalResource',
on_delete=models.CASCADE,
Expand Down
3 changes: 2 additions & 1 deletion addon_service/external_credentials/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from addon_service.common.base_model import AddonsServiceBaseModel


class ExternalCredentials(AddonsServiceBaseModel):

#TODO: Settle on encryption solution
# TODO: Settle on encryption solution
oauth_key = models.CharField(blank=True, null=True)

# For OAuth1, this is usually the "oauth_token_secret"
Expand Down
2 changes: 1 addition & 1 deletion addon_service/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
from addon_service.internal_user.models import InternalUser


class UserFactory(DjangoModelFactory):
class InternalUserFactory(DjangoModelFactory):
class Meta:
model = InternalUser
6 changes: 3 additions & 3 deletions addon_service/tests/test_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.test import TestCase
from .factories import UserFactory
from .factories import InternalUserFactory


class TestTestCase(TestCase):
Expand All @@ -9,6 +9,6 @@ def test_tests(self):

def test_model(self):
"""Simple base test to test test models"""
user = UserFactory(user_guid="hurts")
user = InternalUserFactory(user_uri='http://osf.example/hurts')
user.save()
assert user.user_guid == "hurts"
assert user.user_uri == 'http://osf.example/hurts'
12 changes: 6 additions & 6 deletions addon_service/tests/test_serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from addon_service.tests.factories import UserFactory
from addon_service.tests.factories import InternalUserFactory
from django.test import TestCase
from addon_service.internal_user.serializers import UserSerializer
from addon_service.internal_user.serializers import InternalUserSerializer
from addon_service.internal_user.models import InternalUser

from rest_framework import viewsets
Expand All @@ -10,11 +10,11 @@

class TestViewSet(viewsets.ModelViewSet):
queryset = InternalUser.objects.all()
serializer_class = UserSerializer
serializer_class = InternalUserSerializer


def render_test_data(instance):
serializer = UserSerializer(instance=instance)
serializer = InternalUserSerializer(instance=instance)
renderer = JSONRenderer()
renderer_context = {"view": TestViewSet()}
data = renderer.render(serializer.data, renderer_context=renderer_context)
Expand All @@ -25,6 +25,6 @@ class TestBaseSerializer(TestCase):
"""Simple base test to test serializer models"""

def test_serializer(self):
user = UserFactory(user_guid="hurts1")
user = InternalUserFactory(user_uri="http://osf.example/hurts1")
data = render_test_data(user)
assert data["data"]["attributes"]["user_guid"] == "hurts1"
assert data["data"]["attributes"]["user_uri"] == "http://osf.example/hurts1"

0 comments on commit 61e7fce

Please sign in to comment.