Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vpet98 committed Jun 12, 2024
1 parent bb3a1e8 commit a46154b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 62 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/publish-container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Create and publish a Docker image

on:
push:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
SHORT_SHA: ${{ github.sha::8 }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set outputs
id: sha_short
run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)"

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix=sha-,suffix=,format=short
type=ref,event=branch
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: ./Dockerfile

- name: Post build info
run: echo "Docker image published successfully to GHCR with tags: ${{ steps.meta.outputs.tags }}"
81 changes: 19 additions & 62 deletions board/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .models import Fdsn_registry, Consistency, Eida_routing, Datacenter, Datacite, Stationxml


class TestModelTests(TestCase):
class TestModelConsistency(TestCase):
def test_page_works(self):
"""
test that a page of an fdsn network works
Expand All @@ -32,80 +32,37 @@ def test_stationxml_doi_match_true(self):
"""
xml_doi_match is True if doi in Stationxml and Network tables match
"""
net = Network(code='TN', startdate="2024-01-01", doi="some_doi")
net = Fdsn_registry(netcode='TN', startdate="2024-01-01", doi="some_doi")
net.save()
Stationxml(network=net, doi="some_doi").save()
testnet = Test(test_time=timezone.now(), network=net, xml_doi_match=net.doi==Stationxml.objects.filter(network__code=net.code)[0].doi)
dc = Datacenter(name='DC')
dc.save()
xml = Stationxml(datacenter=dc, netcode='TN', startdate="2024-01-01", doi="some_doi")
xml.save()
testnet = Consistency(test_time=timezone.now(), fdsn_net=net, xml_net=xml, xml_doi_match=net.doi==Stationxml.objects.filter(netcode=net.netcode, startdate=net.startdate).first().doi)
self.assertIs(testnet.xml_doi_match, True)

def test_stationxml_doi_match_false(self):
"""
xml_doi_match is False if doi in Stationxml and Network tables do not match
"""
net = Network(code='TN', startdate="2024-01-01", doi="some_doi")
net = Fdsn_registry(netcode='TN', startdate="2024-01-01", doi="some_doi")
net.save()
Stationxml(network=net, doi="some_other_doi").save()
testnet = Test(test_time=timezone.now(), network=net, xml_doi_match=net.doi==Stationxml.objects.filter(network__code=net.code)[0].doi)
dc = Datacenter(name='DC')
dc.save()
xml = Stationxml(datacenter=dc, netcode='TN', startdate="2024-01-01", doi="some_other_doi")
xml.save()
testnet = Consistency(test_time=timezone.now(), fdsn_net=net, xml_net=xml, xml_doi_match=net.doi==Stationxml.objects.filter(netcode=net.netcode, startdate=net.startdate).first().doi)
self.assertIs(testnet.xml_doi_match, False)

def test_stationxml_doi_match_nonexistent(self):
"""
xml_doi_match is False if doi in Stationxml does not exist
"""
net = Network(code='TN', startdate="2024-01-01", doi="some_doi")
net = Fdsn_registry(netcode='TN', startdate="2024-01-01", doi="some_doi")
net.save()
Stationxml(network=net).save()
testnet = Test(test_time=timezone.now(), network=net, xml_doi_match=net.doi==Stationxml.objects.filter(network__code=net.code)[0].doi)
dc = Datacenter(name='DC')
dc.save()
xml = Stationxml(datacenter=dc, netcode='TN', startdate="2024-01-01")
xml.save()
testnet = Consistency(test_time=timezone.now(), fdsn_net=net, xml_net=xml, xml_doi_match=net.doi==Stationxml.objects.filter(netcode=net.netcode, startdate=net.startdate).first().doi)
self.assertIs(testnet.xml_doi_match, False)

def test_stationxml_restriction_match_true_with_license(self):
"""
xml_restriction_match is True if network has license and restriction status in xml is open/partial
"""
net = Network(code='TN', startdate="2024-01-01")
net.save()
Datacite(network=net, licenses="some_license1, some_license2").save()
Stationxml(network=net, restriction="open").save()
lic = True if Datacite.objects.filter(network__code=net.code)[0].licenses else False
restr = Stationxml.objects.filter(network__code=net.code)[0].restriction
testnet = Test(test_time=timezone.now(), network=net, xml_restriction_match=lic==(restr in ["open", "partial"]))
self.assertIs(testnet.xml_restriction_match, True)

def test_stationxml_restriction_match_true_without_license(self):
"""
xml_restriction_match is True if network does not have license and restriction status in xml is anything but open/partial
"""
net = Network(code='TN', startdate="2024-01-01")
net.save()
Datacite(network=net).save()
Stationxml(network=net, restriction="restricted").save()
lic = True if Datacite.objects.filter(network__code=net.code)[0].licenses else False
restr = Stationxml.objects.filter(network__code=net.code)[0].restriction
testnet = Test(test_time=timezone.now(), network=net, xml_restriction_match=lic==(restr in ["open", "partial"]))
self.assertIs(testnet.xml_restriction_match, True)

def test_stationxml_restriction_match_false_without_license(self):
"""
xml_restriction_match is False if network does not have license and restriction status in xml is open/partial
"""
net = Network(code='TN', startdate="2024-01-01")
net.save()
Datacite(network=net).save()
Stationxml(network=net, restriction="open").save()
lic = True if Datacite.objects.filter(network__code=net.code)[0].licenses else False
restr = Stationxml.objects.filter(network__code=net.code)[0].restriction
testnet = Test(test_time=timezone.now(), network=net, xml_restriction_match=lic==(restr in ["open", "partial"]))
self.assertIs(testnet.xml_restriction_match, False)

def test_stationxml_restriction_match_false_with_license(self):
"""
xml_restriction_match is False if network has license and restriction status in xml is anything but open/partial
"""
net = Network(code='TN', startdate="2024-01-01")
net.save()
Datacite(network=net, licenses="some_license1, some_license2").save()
Stationxml(network=net, restriction="restricted").save()
lic = True if Datacite.objects.filter(network__code=net.code)[0].licenses else False
restr = Stationxml.objects.filter(network__code=net.code)[0].restriction
testnet = Test(test_time=timezone.now(), network=net, xml_restriction_match=lic==(restr in ["open", "partial"]))
self.assertIs(testnet.xml_restriction_match, False)

0 comments on commit a46154b

Please sign in to comment.