Skip to content

Commit

Permalink
Fix tests and refactor source code
Browse files Browse the repository at this point in the history
Signed-off-by: Anja Strunk <[email protected]>
  • Loading branch information
anjastrunk committed Aug 13, 2024
1 parent edf3801 commit 33e6193
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 41 deletions.
12 changes: 6 additions & 6 deletions generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@

import json
import sys
from datetime import datetime, timezone
from typing import List

import click
import openstack as os
import yaml
from openstack.connection import Connection

from typing import List
from datetime import datetime, timezone
import generator.common.const as const
import generator.common.json_ld as json_ld
from generator.common import credentials, crypto
from generator.common.config import Config
from generator.discovery.csp_generator import CspGenerator
from generator.discovery.gxdch_services import ComplianceService, NotaryService
from generator.discovery.openstack.openstack_discovery import \
OpenstackDiscovery
from generator.discovery.gxdch_services import NotaryService, ComplianceService
from generator.discovery.csp_generator import CspGenerator
from generator.common import crypto, credentials
from openstack.connection import Connection

SHAPES_FILE_FORMAT = "turtle"
DATA_FILE_FORMAT = "json-ld"
Expand Down
4 changes: 3 additions & 1 deletion generator/common/credentials.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
from typing import List

from generator.common import const, crypto
import json


def convert_to_vp(creds: List[dict]) -> str:
vp = dict()
Expand Down
5 changes: 3 additions & 2 deletions generator/common/crypto.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from datetime import datetime, timezone
from hashlib import sha256
from jwcrypto.jws import JWS, JWK

from jwcrypto.common import json_encode
from jwcrypto.jws import JWK, JWS
from pyld import jsonld
from datetime import timezone, datetime

"""
Methods to handle cryptography. Most source code is taken from Gaia-X Example
Expand Down
3 changes: 2 additions & 1 deletion generator/discovery/csp_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import generator.common.const as const
from generator.common import crypto
from generator.common.config import Config
from generator.discovery.gxdch_services import NotaryService, ComplianceService, RegistryService
from generator.discovery.gxdch_services import (ComplianceService,
NotaryService, RegistryService)


class CspGenerator:
Expand Down
3 changes: 1 addition & 2 deletions generator/discovery/gxdch_services.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json

import requests

import generator.common.const as const


Expand Down
6 changes: 2 additions & 4 deletions generator/discovery/openstack/openstack_discovery.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
""""General openstack discovery class.
"""

from hashlib import sha256

import requests
from openstack.connection import Connection
from requests.exceptions import HTTPError
Expand All @@ -13,10 +15,6 @@
ServerFlavorDiscovery
from generator.discovery.openstack.vm_images_discovery import VmImageDiscovery

from hashlib import sha256

from generator.discovery.gxdch_services import ComplianceService, NotaryService


class OpenstackDiscovery:
"""Abstraction for openStack cloud with all its services."""
Expand Down
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ click
linkml
requests
jwcrypto
pyld
10 changes: 9 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ attrs==23.2.0
# jsonschema
# referencing
cachetools==5.3.3
# via google-auth
# via
# google-auth
# pyld
certifi==2024.2.2
# via
# kubernetes
Expand Down Expand Up @@ -64,6 +66,8 @@ exceptiongroup==1.2.0
# via pytest
fqdn==1.5.1
# via jsonschema
frozendict==2.4.4
# via pyld
google-auth==2.29.0
# via kubernetes
graphviz==0.20.3
Expand Down Expand Up @@ -137,6 +141,8 @@ linkml-runtime==1.7.5
# via
# linkml
# linkml-dataops
lxml==5.3.0
# via pyld
markupsafe==2.1.5
# via jinja2
netifaces==0.11.0
Expand Down Expand Up @@ -193,6 +199,8 @@ pyjsg==0.11.10
# linkml
# pyshexc
# shexjsg
pyld==2.0.4
# via -r requirements.in
pyparsing==3.1.2
# via rdflib
pyshex==0.8.1
Expand Down
16 changes: 9 additions & 7 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import json
import unittest
from unittest.mock import MagicMock, patch

import yaml
from click.testing import CliRunner
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import ec, rsa
from cryptography.hazmat.primitives.serialization import Encoding
from jwcrypto.jwt import JWK

from generator import cli
from generator.common import const, crypto, config
from generator.common import config, const, crypto
from generator.common.gx_schema import (DataAccountExport, TermsAndConditions,
VirtualMachineServiceOffering)
from tests.common import MockConnection, get_absolute_path
from cryptography.hazmat.primitives.asymmetric import ec, rsa
from jwcrypto.jwt import JWK
from cryptography.hazmat.primitives.serialization import Encoding
from cryptography.hazmat.primitives import hashes, serialization
from generator.common.gx_schema import VirtualMachineServiceOffering, DataAccountExport, TermsAndConditions


class CliTestCase(unittest.TestCase):

Expand Down
23 changes: 9 additions & 14 deletions tests/test_csp_generator.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
from unittest.mock import patch
import unittest
from generator.discovery.csp_generator import CspGenerator
import json
import unittest
from unittest.mock import MagicMock, patch
import yaml
from click.testing import CliRunner
from unittest.mock import patch

from generator import cli
from generator.common import const, crypto, config
from tests.common import MockConnection, get_absolute_path
from cryptography.hazmat.primitives.asymmetric import ec, rsa
import yaml
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric import rsa
from jwcrypto.jwt import JWK
from cryptography.hazmat.primitives.serialization import Encoding
from cryptography.hazmat.primitives import hashes, serialization
from generator.common.gx_schema import VirtualMachineServiceOffering, DataAccountExport, TermsAndConditions

from generator.common import config, const
from generator.discovery.csp_generator import CspGenerator
from tests.common import get_absolute_path


class CspPGeneratorTestCase(unittest.TestCase):
@patch("generator.discovery.gxdch_services.ComplianceService.request_compliance_vc")
Expand Down
7 changes: 4 additions & 3 deletions tests/test_gxdch_services.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import unittest

from generator.discovery.gxdch_services import NotaryService, ComplianceService, RegistryService
from unittest.mock import patch
import uuid
from unittest.mock import patch

from generator.discovery.gxdch_services import (ComplianceService,
NotaryService, RegistryService)


class GxdchTestCase(unittest.TestCase):
Expand Down

0 comments on commit 33e6193

Please sign in to comment.