Commit 7d6e9e65 authored by Marc Matt's avatar Marc Matt
Browse files

added test for correct default value and dockerfile

parent d8ff9796
FROM openjdk:8u171
LABEL info.datescientists.data.schema.repo="1.0.0"
LABEL info.datescientists.data.schema.release_date="2018-08-23"
MAINTAINER Marc Matt
# Clone GitHub Repository
RUN apt-get update
RUN apt-get install git
RUN apt-get -y install maven
RUN git clone -b master https://github.com/schema-repo/schema-repo.git /schema-repo/
RUN useradd -ms /bin/bash schema_repo
RUN cp -R /schema-repo/* /home/schema_repo/
RUN chown schema_repo:schema_repo -R /home/schema_repo/
ENV JAVA_OPTS="--add-modules=java.xml.bind strongbox"
ENV JAVA_FLAGS="-Djdk.net.URLClassPath.disableClassPathURLCheck=true"
RUN mvn install -f /home/schema_repo/
# USER schema_repo
CMD /home/schema_repo/run.sh "file-system"
\ No newline at end of file
......@@ -95,7 +95,7 @@ class AvroGenerator(object):
file.write(str(schema))
file.close()
except BaseException:
raise "schema could not be written to file"
raise Exception("schema could not be written to file")
def generate_all_schemas(self, path_to_all_schemas='./schemas'):
"""
......@@ -209,3 +209,27 @@ class AvroGenerator(object):
for file in os.listdir(directory):
self.put_schema_to_registry(schema_name=file.decode('utf-8'), schema_repo_url=schema_repo_url,
path_to_all_schemas=path_to_all_schemas)
def check_correct_default_value(self, schema):
"""
function checks, if default value is correctly defined, if one is there.
:param schema: dict of avro schema
:return: tuple of boolean and string message
"""
fields = schema['fields']
b_res = True
msg = ''
for field in fields:
print(field)
if 'default' in field:
if field['default'] == 'null':
b_res = True
msg = ''
else:
b_res = False
print('Default: ' + field['default'])
msg = field['default']
return b_res, msg
avro-python3==1.8.2
fastavro==0.21.4
simplejson==3.16.0
pandas==0.23.4
jupyter
requests==2.19.1
\ No newline at end of file
requests==2.19.1
pytest
\ No newline at end of file
import unittest
from includes.avro_generator import AvroGenerator
class TestAvro(unittest.TestCase):
def test_check_correct_default_value(self):
ag = AvroGenerator()
schema = {
'fields': [
{
'name': 'test',
'type': 'string',
'default': 'int'
}
]
}
res, msg = ag.check_correct_default_value(schema)
self.assertEquals(False, res)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment