From 2f64e5dc45947aba531924449bc41e4985876b08 Mon Sep 17 00:00:00 2001 From: Matt Prahl Date: Thu, 8 Sep 2016 16:37:19 -0400 Subject: [PATCH 1/3] Add test configuration --- config.py | 5 +++++ tests/__init__.py | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/config.py b/config.py index 72d4eb46..049df5ef 100644 --- a/config.py +++ b/config.py @@ -51,6 +51,11 @@ class DevConfiguration(BaseConfiguration): LOG_BACKEND = 'console' HOST = '0.0.0.0' +class TestConfiguration(BaseConfiguration): + LOG_BACKEND = 'console' + SQLALCHEMY_DATABASE_URI = 'sqlite:///:memory:' + DEBUG = True + class ProdConfiguration(BaseConfiguration): pass diff --git a/tests/__init__.py b/tests/__init__.py index e69de29b..a76b1f39 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -0,0 +1,27 @@ +# Copyright (c) 2016 Red Hat, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# Written by Matt Prahl Date: Thu, 8 Sep 2016 16:41:32 -0400 Subject: [PATCH 2/3] Add function to create dummy data for unit tests --- tests/__init__.py | 145 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/tests/__init__.py b/tests/__init__.py index a76b1f39..2a1e3f26 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -25,3 +25,148 @@ from rida.models import ModuleBuild, ComponentBuild app.config.from_object('config.TestConfiguration') + +def init_data(): + db.session.remove() + db.drop_all() + db.create_all() + for index in range(10): + build_one = ModuleBuild() + build_one.name = 'nginx' + build_one.version = '1' + build_one.release = 2 + build_one.state = 3 + build_one.modulemd = '' # Skipping since no tests rely on it + build_one.koji_tag = 'module-nginx-1.2' + build_one.scmurl = ('git://pkgs.domain.local/modules/nginx?' + '#ba95886c7a443b36a9ce31abda1f9bef22f2f8c9') + build_one.batch = 2 + # https://www.youtube.com/watch?v=iQGwrK_yDEg + build_one.owner = 'Moe Szyslak' + build_one.time_submitted = \ + datetime(2016, 9, 3, 11, 23, 20) + timedelta(minutes=(index * 10)) + build_one.time_modified = \ + datetime(2016, 9, 3, 11, 25, 32) + timedelta(minutes=(index * 10)) + build_one.time_completed = \ + datetime(2016, 9, 3, 11, 25, 32) + timedelta(minutes=(index * 10)) + + component_one_build_one = ComponentBuild() + component_one_build_one.package = 'nginx' + component_one_build_one.scmurl = \ + ('git://pkgs.domain.local/rpms/nginx?' + '#ga95886c8a443b36a9ce31abda1f9bed22f2f8c3') + component_one_build_one.format = 'rpms' + component_one_build_one.task_id = 12312345 + index + component_one_build_one.state = 1 + component_one_build_one.nvr = 'nginx-1.10.1-2.module_nginx_1_2' + component_one_build_one.batch = 1 + component_one_build_one.module_id = 1 + index * 3 + + component_two_build_one = ComponentBuild() + component_two_build_one.package = 'module-build-macros' + component_two_build_one.scmurl = \ + ('/tmp/rida-build-macrosWZUPeK/SRPMS/' + 'module-build-macros-0.1-1.module_nginx_1_2.src.rpm') + component_two_build_one.format = 'rpms' + component_two_build_one.task_id = 12312321 + index + component_two_build_one.state = 1 + component_two_build_one.nvr = \ + 'module-build-macros-01-1.module_nginx_1_2' + component_two_build_one.batch = 2 + component_two_build_one.module_id = 1 + index * 3 + + build_two = ModuleBuild() + build_two.name = 'postgressql' + build_two.version = '1' + build_two.release = 2 + build_two.state = 3 + build_two.modulemd = '' # Skipping since no tests rely on it + build_two.koji_tag = 'module-postgressql-1.2' + build_two.scmurl = ('git://pkgs.domain.local/modules/postgressql?' + '#aa95886c7a443b36a9ce31abda1f9bef22f2f8c9') + build_two.batch = 2 + build_two.owner = 'some_user' + build_two.time_submitted = \ + datetime(2016, 9, 3, 12, 25, 33) + timedelta(minutes=(index * 10)) + build_two.time_modified = \ + datetime(2016, 9, 3, 12, 27, 19) + timedelta(minutes=(index * 10)) + build_two.time_completed = \ + datetime(2016, 9, 3, 11, 27, 19) + timedelta(minutes=(index * 10)) + + component_one_build_two = ComponentBuild() + component_one_build_two.package = 'postgresql' + component_one_build_two.scmurl = \ + ('git://pkgs.domain.local/rpms/postgresql?' + '#dc95586c4a443b26a9ce38abda1f9bed22f2f8c3') + component_one_build_two.format = 'rpms' + component_one_build_two.task_id = 2433433 + index + component_one_build_two.state = 1 + component_one_build_two.nvr = 'postgresql-9.5.3-4.module_postgresql_1_2' + component_one_build_two.batch = 2 + component_one_build_two.module_id = 2 + index * 3 + + component_two_build_two = ComponentBuild() + component_two_build_two.package = 'module-build-macros' + component_two_build_two.scmurl = \ + ('/tmp/rida-build-macrosWZUPeK/SRPMS/' + 'module-build-macros-0.1-1.module_postgresql_1_2.src.rpm') + component_two_build_two.format = 'rpms' + component_two_build_two.task_id = 47383993 + index + component_two_build_two.state = 1 + component_two_build_two.nvr = \ + 'module-build-macros-01-1.module_postgresql_1_2' + component_two_build_two.batch = 1 + component_two_build_two.module_id = 2 + index * 3 + + build_three = ModuleBuild() + build_three.name = 'testmodule' + build_three.version = '4.3.43' + build_three.release = 6 + build_three.state = 1 + build_three.modulemd = '' # Skipping because no tests rely on it + build_three.koji_tag = None + build_three.scmurl = ('git://pkgs.domain.local/modules/testmodule?' + '#ca95886c7a443b36a9ce31abda1f9bef22f2f8c9') + build_three.batch = 0 + build_three.owner = 'some_other_user' + build_three.time_submitted = \ + datetime(2016, 9, 3, 12, 28, 33) + timedelta(minutes=(index * 10)) + build_three.time_modified = \ + datetime(2016, 9, 3, 12, 28, 40) + timedelta(minutes=(index * 10)) + build_three.time_completed = None + + component_one_build_three = ComponentBuild() + component_one_build_three.package = 'rubygem-rails' + component_one_build_three.scmurl = \ + ('git://pkgs.domain.local/rpms/rubygem-rails?' + '#dd55886c4a443b26a9ce38abda1f9bed22f2f8c3') + component_one_build_three.format = 'rpms' + component_one_build_three.task_id = 2433433 + index + component_one_build_three.state = 3 + component_one_build_three.nvr = 'postgresql-9.5.3-4.module_postgresql_1_2' + component_one_build_three.batch = 2 + component_one_build_three.module_id = 3 + index * 3 + + component_two_build_three = ComponentBuild() + component_two_build_three.package = 'module-build-macros' + component_two_build_three.scmurl = \ + ('/tmp/rida-build-macrosWZUPeK/SRPMS/' + 'module-build-macros-0.1-1.module_testmodule_1_2.src.rpm') + component_two_build_three.format = 'rpms' + component_two_build_three.task_id = 47383993 + index + component_two_build_three.state = 1 + component_two_build_three.nvr = \ + 'module-build-macros-01-1.module_postgresql_1_2' + component_two_build_three.batch = 1 + component_two_build_three.module_id = 3 + index * 3 + + db.session.add(build_one) + db.session.add(component_one_build_one) + db.session.add(component_two_build_one) + db.session.add(component_one_build_two) + db.session.add(component_two_build_two) + db.session.add(component_one_build_three) + db.session.add(component_two_build_three) + db.session.add(build_two) + db.session.add(build_three) + db.session.commit() From fbc5deaa5653aa7cd0e315d1ab865173ef04bcf7 Mon Sep 17 00:00:00 2001 From: Matt Prahl Date: Thu, 8 Sep 2016 16:41:53 -0400 Subject: [PATCH 3/3] Add unit tests for the API routes --- tests/test_views/fakemodule.yaml | 32 ++++ tests/test_views/test_views.py | 241 +++++++++++++++++++++++++++++++ 2 files changed, 273 insertions(+) create mode 100644 tests/test_views/fakemodule.yaml create mode 100644 tests/test_views/test_views.py diff --git a/tests/test_views/fakemodule.yaml b/tests/test_views/fakemodule.yaml new file mode 100644 index 00000000..477306cf --- /dev/null +++ b/tests/test_views/fakemodule.yaml @@ -0,0 +1,32 @@ +document: modulemd +version: 0 +data: + name: fakemodule + version: 4.3.44 + release: 5 + summary: A fake module containing the bash shell + description: > + A fake module used for testing + license: + module: + - MIT + content: [] + xmd: ~ + dependencies: + buildrequires: + base_runtime: 1.0-0 + references: + community: https://fedoraproject.org/wiki/Modularity + tracker: https://taiga.fedorainfracloud.org/project/modularity + profiles: + default: + rpms: + - bash + components: + rpms: + api: + - bash + packages: + bash: + rationale: It's here to test the whole thing! + commit: 70fa7516b83768595a4f3280ae890a7ac957e0c7 diff --git a/tests/test_views/test_views.py b/tests/test_views/test_views.py new file mode 100644 index 00000000..580bcca1 --- /dev/null +++ b/tests/test_views/test_views.py @@ -0,0 +1,241 @@ +# Copyright (c) 2016 Red Hat, Inc. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# +# Written by Matt Prahl