From 02d57a061ee48bf4bf659132661c65606dc39bfd Mon Sep 17 00:00:00 2001 From: Pat Riehecky Date: Mar 19 2019 17:49:40 +0000 Subject: Put tests back --- diff --git a/updateinfo/updateinfo_django_app/tests/test_collection.py b/updateinfo/updateinfo_django_app/tests/test_collection.py new file mode 100644 index 0000000..59de631 --- /dev/null +++ b/updateinfo/updateinfo_django_app/tests/test_collection.py @@ -0,0 +1,183 @@ +#pylint: disable=line-too-long + +############################################################ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Version 0.2 by Pat Riehecky for Scientific Linux +# Copyright (2019). Fermi Research Alliance, LLC. +############################################################ + +from __future__ import unicode_literals +from __future__ import absolute_import + +from django.test import TestCase + +############################################################ +# Create your tests here. +############################################################ + +from updateinfo.updateinfo_django_app.models import Collection +from updateinfo.updateinfo_django_app.models import Package + +from updateinfo.collection.tests import CollectionTests as UpdateinfoCollectionTests + +class UpdateinfoCompatCollectionModelTests(TestCase, UpdateinfoCollectionTests): + Collection = Collection + Package = Package + + def test_django_object(self): + '''Make sure we are testing the right one''' + result = False + if self.Collection.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_package(self): + '''Make sure we are testing the right one''' + result = False + if self.Collection.Package.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_package_store(self): + '''Make sure we are testing the right one''' + result = False + if self.Collection.Package.PackageSumStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_package(self): + '''Make sure we are testing the right one''' + result = False + if self.Package.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_package_store(self): + '''Make sure we are testing the right one''' + result = False + if self.Package.PackageSumStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_save(self): + '''Make sure we can save a collection to the database''' + testcoll = self.Collection(release_name='asdf', short_name='asdf') + + testpkg = self.Package() + testpkg.name = 'asdf' + testpkg.version = 'jkl' + testpkg.release = 'gh' + testpkg.arch = 'src' + testcoll.add(testpkg) + + testcoll.save() + + self.assertTrue(True, msg='Cant save') + + def test_django_save_many_to_many(self): + '''Make sure we can save a collection to the database''' + testcoll = self.Collection(release_name='asdf', short_name='asdf') + + testpkg = self.Package() + testpkg.name = 'asdf' + testpkg.version = 'jkl' + testpkg.release = 'gh' + testpkg.arch = 'src' + testpkg.sums['md5'] = 'd41d8cd98f00b204e9800998ecf8427e' + testcoll.add(testpkg) + + testcoll.save() + + testcoll2 = self.Collection(release_name='jkl', short_name='jkl') + testcoll2.add(testpkg) + + testcoll2.save() + + self.assertTrue(True, msg='Many to many not right') + + def test_django_save_many_to_many_newpkg(self): + '''Make sure we can save a collection to the database''' + testcoll = self.Collection(release_name='asdf', short_name='asdf') + + testpkg = self.Package() + testpkg.name = 'asdf' + testpkg.version = 'jkl' + testpkg.release = 'gh' + testpkg.arch = 'src' + testpkg.sums['md5'] = 'd41d8cd98f00b204e9800998ecf8427e' + testcoll.add(testpkg) + + testcoll.save() + + testcoll2 = self.Collection(release_name='jkl', short_name='jkl') + testpkg2 = self.Package() + testpkg2.name = 'asdf' + testpkg2.version = 'jkl' + testpkg2.release = 'gh' + testpkg2.arch = 'src' + testpkg2.sums['md5'] = 'd41d8cd98f00b204e9800998ecf8427e' + testcoll2.add(testpkg2) + + testcoll2.save() + + self.assertTrue(True, msg='Many to many not right') + + def test_django_save_has_data(self): + '''Make sure we can save a collection to the database''' + testcoll = self.Collection(release_name='asdf', short_name='asdf') + + testpkg = self.Package() + testpkg.name = 'asdf' + testpkg.version = 'jkl' + testpkg.release = 'gh' + testpkg.arch = 'src' + testpkg.sums['md5'] = 'd41d8cd98f00b204e9800998ecf8427e' + testcoll.add(testpkg) + + testcoll.save() + + testobj = self.Collection.objects.get(_release_name='asdf', _short_name='asdf') + + result = False + if testobj.xml == 'asdfasdf-jkl-gh.src.rpmd41d8cd98f00b204e9800998ecf8427e': + result = True + + self.assertTrue(result, msg='Did not get the right stuff back') + + def test_django_remove_works(self): + '''Make sure we can save a collection to the database''' + testcoll = self.Collection(release_name='asdf', short_name='asdf') + + testpkg = self.Package() + testpkg.name = 'asdf' + testpkg.version = 'jkl' + testpkg.release = 'gh' + testpkg.arch = 'src' + testpkg.sums['md5'] = 'd41d8cd98f00b204e9800998ecf8427e' + testcoll.add(testpkg) + + testcoll.save() + + testcoll.remove(testpkg) + + testobj = self.Collection.objects.get(_release_name='asdf', _short_name='asdf') + + result = False + if testobj.xml == 'asdf': + result = True + + self.assertTrue(result, msg='Did not get the right stuff back') + diff --git a/updateinfo/updateinfo_django_app/tests/test_helpers.py b/updateinfo/updateinfo_django_app/tests/test_helpers.py new file mode 100644 index 0000000..bc17808 --- /dev/null +++ b/updateinfo/updateinfo_django_app/tests/test_helpers.py @@ -0,0 +1,67 @@ +#pylint: disable=line-too-long + +############################################################ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Version 0.2 by Pat Riehecky for Scientific Linux +# Copyright (2019). Fermi Research Alliance, LLC. +############################################################ + +from __future__ import unicode_literals +from __future__ import absolute_import + +from django.test import TestCase + +############################################################ +# Create your tests here. +############################################################ + +from updateinfo.updateinfo_django_app.models import Package +from updateinfo.updateinfo_django_app.models import Collection +from updateinfo.updateinfo_django_app.models import Reference +from updateinfo.updateinfo_django_app.models import Update + +from updateinfo.helpers.tests import HelperDateTests, HelperFindersTests, HelperRepoTests, HelperSuggestedTests, HelperXMLToolsTests + +class UpdateinfoCompatHelperDateTests(TestCase, HelperDateTests): + Update = Update + Collection = Collection + Reference = Reference + Package = Package + +class UpdateinfoCompatHelperFindersTests(TestCase, HelperFindersTests): + Update = Update + Collection = Collection + Reference = Reference + Package = Package + +class UpdateinfoCompatHelperRepoTests(TestCase, HelperRepoTests): + Update = Update + Collection = Collection + Reference = Reference + Package = Package + +class UpdateinfoCompatHelperSuggestedTests(TestCase, HelperSuggestedTests): + Update = Update + Collection = Collection + Reference = Reference + Package = Package + +class UpdateinfoCompatHelperXMLToolsTests(TestCase, HelperXMLToolsTests): + Update = Update + Collection = Collection + Reference = Reference + Package = Package + diff --git a/updateinfo/updateinfo_django_app/tests/test_packagestore.py b/updateinfo/updateinfo_django_app/tests/test_packagestore.py new file mode 100644 index 0000000..8a50265 --- /dev/null +++ b/updateinfo/updateinfo_django_app/tests/test_packagestore.py @@ -0,0 +1,66 @@ +#pylint: disable=line-too-long + +############################################################ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Version 0.2 by Pat Riehecky for Scientific Linux +# Copyright (2019). Fermi Research Alliance, LLC. +############################################################ + +from __future__ import unicode_literals +from __future__ import absolute_import + +from django.test import TestCase + +############################################################ +# Create your tests here. +############################################################ + +from updateinfo.updateinfo_django_app.models import PackageSumStore + +from updateinfo.package.store.tests import SumPackageModelTests + +class UpdateinfoCompatPackageSumStoreModelTests(TestCase, SumPackageModelTests): + PackageSumStore = PackageSumStore + + def test_django_object(self): + '''Make sure we are testing the right one''' + result = False + if self.PackageSumStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_save(self): + '''Can the object be shoved in the database''' + testsum = self.PackageSumStore() + testsum._package_id = 1 + testsum.md5 = 'asdf' + testsum.save() + + def test_django_save_has_data(self): + '''Can the object be shoved in the database''' + testsum = self.PackageSumStore() + testsum._package_id = 1 + testsum.md5 = 'asdf' + testsum.save() + + testobj = self.PackageSumStore.objects.get(_md5='asdf') + + result = False + if testobj['md5'] == 'asdf': + result = True + + self.assertTrue(result, msg='Could not get store from db') + diff --git a/updateinfo/updateinfo_django_app/tests/test_reference.py b/updateinfo/updateinfo_django_app/tests/test_reference.py new file mode 100644 index 0000000..c7c4188 --- /dev/null +++ b/updateinfo/updateinfo_django_app/tests/test_reference.py @@ -0,0 +1,74 @@ +#pylint: disable=line-too-long + +############################################################ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Version 0.2 by Pat Riehecky for Scientific Linux +# Copyright (2019). Fermi Research Alliance, LLC. +############################################################ + +from __future__ import unicode_literals +from __future__ import absolute_import + +from django.test import TestCase + +############################################################ +# Create your tests here. +############################################################ + +from updateinfo.updateinfo_django_app.models import Reference + +from updateinfo.reference.tests import ReferenceTests as UpdateinfoReferenceTests + +class UpdateinfoCompatReferenceModelTests(TestCase, UpdateinfoReferenceTests): + Reference = Reference + + def test_django_object(self): + '''Make sure we are testing the right one''' + result = False + if self.Reference.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_save(self): + '''Can the object be shoved in the database''' + testref = self.Reference() + testref.reftype = 'bugzilla' + testref.href = 'http://' + testref.refid = '1' + testref.title = 'asdf' + + testref.save() + + def test_django_save_has_data(self): + '''Can the object be shoved in the database''' + testref = self.Reference() + testref.reftype = 'bugzilla' + testref.href = 'http://' + testref.refid = '1' + testref.title = 'asdf' + + testref.save() + + testobj = self.Reference.objects.get(_href='http://') + result = False + if testobj.refid == '1': + if testobj.reftype == 'bugzilla': + if testobj.title == 'Asdf': + if testobj.href == 'http://': + result = True + + self.assertTrue(result, msg='Could not get back out of db') + diff --git a/updateinfo/updateinfo_django_app/tests/test_update.py b/updateinfo/updateinfo_django_app/tests/test_update.py new file mode 100644 index 0000000..59e47ee --- /dev/null +++ b/updateinfo/updateinfo_django_app/tests/test_update.py @@ -0,0 +1,484 @@ +#pylint: disable=line-too-long + +############################################################ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Version 0.2 by Pat Riehecky for Scientific Linux +# Copyright (2019). Fermi Research Alliance, LLC. +############################################################ + +from __future__ import unicode_literals +from __future__ import absolute_import + +from django.test import TestCase +import unittest + +############################################################ +# Testing module: +from updateinfo.updateinfo_django_app.models import Update +############################################################ + +# for Compat Tests +import datetime +from updateinfo.update.tests import UpdateTests as UpdateinfoUpdateTests +from updateinfo.updateinfo_django_app.models import Collection +from updateinfo.updateinfo_django_app.models import CollectionStore +from updateinfo.updateinfo_django_app.models import Reference +from updateinfo.updateinfo_django_app.models import ReferenceStore +from updateinfo.updateinfo_django_app.models import Package + +# for Sample Tests +from updateinfo.updateinfo_django_app.models import Updateinfo +import updateinfo +import os.path + +############################################################ +# Create your tests here. +############################################################ +class UpdateinfoCompatUpdateModelTests(TestCase, UpdateinfoUpdateTests): + Update = Update + Collection = Collection + CollectionStore = CollectionStore + ReferenceStore = ReferenceStore + Package = Package + Reference = Reference + + def test_django_object(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_update_collectionstore(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.CollectionStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_update_collectionstore_collection(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.CollectionStore.Collection.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_update_collectionstore_collection_package(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.CollectionStore.Collection.Package.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_update_collectionstore_collection_package_sum(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.CollectionStore.Collection.Package.PackageSumStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_referencestore(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.ReferenceStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_referencestore_reference(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.ReferenceStore.Reference.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_collectionstore(self): + '''Make sure we are testing the right one''' + result = False + if self.CollectionStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_collectionstore_collection(self): + '''Make sure we are testing the right one''' + result = False + if self.CollectionStore.Collection.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_collectionstore_collection_package(self): + '''Make sure we are testing the right one''' + result = False + if self.CollectionStore.Collection.Package.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_collectionstore_collection_package_sum(self): + '''Make sure we are testing the right one''' + result = False + if self.CollectionStore.Collection.Package.PackageSumStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_collection(self): + '''Make sure we are testing the right one''' + result = False + if self.Collection.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_collection_package(self): + '''Make sure we are testing the right one''' + result = False + if self.Collection.Package.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_collection_package_sum(self): + '''Make sure we are testing the right one''' + result = False + if self.Collection.Package.PackageSumStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_package(self): + '''Make sure we are testing the right one''' + result = False + if self.Package.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_package_sum(self): + '''Make sure we are testing the right one''' + result = False + if self.Package.PackageSumStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_referencestore(self): + '''Make sure we are testing the right one''' + result = False + if self.ReferenceStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_referencestore_reference(self): + '''Make sure we are testing the right one''' + result = False + if self.ReferenceStore.Reference.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_reference(self): + '''Make sure we are testing the right one''' + result = False + if self.Reference.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_save(self): + '''Can the object be shoved in the database''' + testentry = self.Update() + testentry.updateid = '1' + testentry.updatefrom = 'me@example.com' + testentry.updatetype = 'security' + testentry.status = 'stable' + testentry.description = 'I am' + testentry.issued_date = datetime.datetime(2012, 3, 1, 10, 0, 0, 'UTC') + testentry.severity = 'important' + testentry.summary = 'summary' + testentry.title = 'title' + testentry.releasetitle = 'releasetitle' + testentry.update_date = datetime.datetime(2015, 3, 1, 10, 0, 0, 'UTC') + testentry.rights = 'rights' + testentry.solution = 'solution' + testentry.reboot_suggested = True + testentry.relogin_suggested = True + testentry.restart_suggested = True + + testentry.collections.add(self.coll_one_for_test()) + testentry.references.add(self.ref_one_for_test()) + testentry.collections.add(self.coll_two_for_test()) + testentry.references.add(self.ref_two_for_test()) + + testentry.save() + + def test_django_save_has_data(self): + '''Can the object be shoved in the database''' + testentry = self.Update() + testentry.updateid = '1' + testentry.updatefrom = 'me@example.com' + testentry.updatetype = 'security' + testentry.status = 'stable' + testentry.description = 'Testing Me' + testentry.issued_date = datetime.datetime(2012, 3, 7, 10, 0, 0, 'UTC') + testentry.severity = 'important' + testentry.summary = 'summary' + testentry.title = 'title' + testentry.releasetitle = 'releasetitle' + testentry.update_date = datetime.datetime(2015, 5, 1, 10, 0, 0, 'UTC') + testentry.rights = 'rights' + testentry.solution = 'solution' + testentry.reboot_suggested = True + testentry.relogin_suggested = True + testentry.restart_suggested = True + + testentry.collections.add(self.coll_one_for_test()) + testentry.references.add(self.ref_one_for_test()) + testentry.collections.add(self.coll_two_for_test()) + testentry.references.add(self.ref_two_for_test()) + + # this is here to make sure manytomany works as expected + self.ref_two_for_test().save() + + ##XXX FIXME + testentry.save() + + testobj = self.Update.objects.get(_updateid='1') + + result = False + if testobj == testentry: + result = True + + self.assertTrue(result, msg="Data fetched from DB doesn't match what we saved") + + def test_django_has_collections(self): + '''make sure our collections came back out right''' + testentry = self.Update() + testentry.updateid = '1' + testentry.updatefrom = 'me@example.com' + testentry.updatetype = 'security' + testentry.status = 'stable' + testentry.description = 'Testing Me' + testentry.issued_date = datetime.datetime(2012, 3, 7, 10, 0, 0, 'UTC') + testentry.severity = 'important' + testentry.summary = 'summary' + testentry.title = 'title' + testentry.releasetitle = 'releasetitle' + testentry.update_date = datetime.datetime(2015, 5, 1, 10, 0, 0, 'UTC') + testentry.rights = 'rights' + testentry.solution = 'solution' + testentry.reboot_suggested = True + testentry.relogin_suggested = True + testentry.restart_suggested = True + + testentry.collections.add(self.coll_one_for_test()) + testentry.references.add(self.ref_one_for_test()) + testentry.collections.add(self.coll_two_for_test()) + testentry.references.add(self.ref_two_for_test()) + + # this is here to make sure manytomany works as expected + self.ref_two_for_test().save() + + testentry.save() + + ##XXX FIXME + testobj = self.Update.objects.get(_updateid='1') + import subprocess + subprocess.check_call(['cp', '/home/riehecky/code/mydjangosite/mydjangosite/test.db', '/tmp/saved.db']) + + result = False + if testobj.collections == testobj.collections: + result = True + + self.assertTrue(result, msg="Data fetched from DB has wrong collections") + + def test_django_urls_is_correct(self): + '''does the references.urls property work as expected''' + testentry = self.Update() + testentry.updateid = '1' + testentry.updatefrom = 'me@example.com' + testentry.updatetype = 'security' + testentry.status = 'stable' + testentry.description = 'Testing Me' + testentry.issued_date = datetime.datetime(2014, 3, 1, 10, 0, 0, 'UTC') + testentry.severity = 'important' + testentry.summary = 'summary' + testentry.title = 'title' + testentry.releasetitle = 'releasetitle' + testentry.rights = 'rights' + testentry.solution = 'solution' + testentry.reboot_suggested = True + testentry.relogin_suggested = True + testentry.restart_suggested = True + + testentry.collections.add(self.coll_one_for_test()) + testentry.references.add(self.ref_one_for_test()) + testentry.collections.add(self.coll_two_for_test()) + testentry.references.add(self.ref_two_for_test()) + + ##XXX FIXME + testentry.save() + + testobj = self.Update.objects.get(_updateid='1') + + result = False + if testobj.references.urls == ('http://1', 'http://2'): + result = True + + self.assertTrue(result, msg="URLs isn't right") + + def test_django_md5sum_correct(self): + '''does the package md5sum property work as expected''' + testentry = self.Update() + testentry.updateid = '1' + testentry.updatefrom = 'me@example.com' + testentry.updatetype = 'security' + testentry.status = 'stable' + testentry.description = 'Testing Me' + testentry.issued_date = datetime.datetime(2014, 3, 1, 10, 0, 0, 'UTC') + testentry.severity = 'important' + testentry.summary = 'summary' + testentry.title = 'title' + testentry.releasetitle = 'releasetitle' + testentry.rights = 'rights' + testentry.solution = 'solution' + testentry.reboot_suggested = True + testentry.relogin_suggested = True + testentry.restart_suggested = True + + testentry.collections.add(self.coll_one_for_test()) + testentry.references.add(self.ref_one_for_test()) + testentry.collections.add(self.coll_two_for_test()) + testentry.references.add(self.ref_two_for_test()) + + ##XXX FIXME + testentry.save() + + testobj = self.Update.objects.get(_updateid='1') + + ##XXX FIXME + print('----') + print("->Where are my collections?") + print(testobj.xml) + print('----') + + result = False + if testobj.collections['iop']['aaasdf-jkl-gh.noarch.rpm'].sums['md5'] == 'd41d8cd98f00b204e9800998ecf8427e': + result = True + + self.assertTrue(result, msg="Didn't find sum within database") + +class UpdateModelTestsNoFixture(TestCase): + '''test loading a bunch of stuff into the database''' + Updateinfo = Updateinfo + def test_load_sample_epel(self): + '''Can we parse the epel sample into the database?''' + if os.path.exists('/usr/share/doc/python-Updateinfo/samples/EPEL6-updateinfo.xml'): + uinfo = self.Updateinfo() + _fd = open('/usr/share/doc/python-Updateinfo/samples/EPEL6-updateinfo.xml', 'r') + uinfo.xml = _fd.read() + _fd.close() + uinfo.save() + else: + raise unittest.SkipTest('Sample data not found in /usr/share/doc/') + + def test_load_sample_fedora(self): + '''Can we parse the Fedora sample into the database?''' + if os.path.exists('/usr/share/doc/python-Updateinfo/samples/Fedora-updateinfo.xml'): + uinfo = self.Updateinfo() + _fd = open('/usr/share/doc/python-Updateinfo/samples/Fedora-updateinfo.xml', 'r') + uinfo.xml = _fd.read() + _fd.close() + uinfo.save() + else: + raise unittest.SkipTest('Sample data not found in /usr/share/doc/') + +class UpdateModelTestsAddonsFixture(TestCase): + fixtures = ['addons.json'] + + Update = Update + + def test_pk_one_attribs(self): + '''How are our initial update attribs''' + uone = self.Update.objects.get(pk=1) + + result = False + if uone.updateid == 'SL_contrib_template-1.0-0.el6': + if uone.updatetype == 'newpackage': + if 'sl-addons' in uone.collections: + if uone.collections['sl-addons']['SL_contrib_template/SL_contrib_template-1.0-0.el6.noarch.rpm'].sums['sha256'] == '164b85a51ee8cd77543de6f901b1d0b09e22bd0a3ad9a4a39f889f38196d0fb3': + result = True + + self.assertTrue(result, msg="Didn't find what I expected for package attribs") + + def test_pk_one_yaml(self): + '''How is our initial update as yaml''' + uone = self.Update.objects.get(pk=1) + + txt = '''title: Sl_Contrib_Template +updateid: SL_contrib_template-1.0-0.el6 +issued_date: 2013-03-08 00:00:00 +releasetitle: Scientific Linux +updatetype: newpackage +description: Submitting packages for inclusion in Scientific Linux addons requires + filling out a template. This package includes that template and a simple script + to check that it is filled out. +collections: +- sl-addons: + - release_name: Scientific Linux 6 Addons + - SL_contrib_template/SL_contrib_template-1.0-0.el6.noarch.rpm: + arch: noarch + name: SL_contrib_template + release: 0.el6 + srpm: SL_contrib_template-1.0-0.el6.src.rpm + sums: + sha256: 164b85a51ee8cd77543de6f901b1d0b09e22bd0a3ad9a4a39f889f38196d0fb3 + version: '1.0' + - SL_contrib_template/SL_contrib_template-1.0-0.el6.src.rpm: + arch: src + name: SL_contrib_template + release: 0.el6 + srpm: SL_contrib_template-1.0-0.el6.src.rpm + sums: + sha256: c5d122cf473cc7ecc01d315358ef770150414b40f9248eae7377cbf2cc88ad3d + version: '1.0' +references: +- http://listserv.fnal.gov/scripts/wa.exe?A2=ind1303&L=scientific-linux-devel&X=23EA9C45B29E3FC65C&P=950: + refid: SL_contrib_template-1.0-0.el6 + title: Release Announcement + type: self +updatefrom: riehecky@fnal.gov +status: stable +''' + + result = False + if uone.yaml == txt: + result = True + + self.assertTrue(result, msg="Didn't find what I expected for yaml") + + def test_pk_one_xml(self): + '''How is our initial update as xml''' + uone = self.Update.objects.get(pk=1) + + result = False + + txt = ''' +without collections my XML is bad +''' + + ##XXX FIXME + print('----') + print("without collections my XML is bad") + print(uone.xml) + import subprocess + subprocess.check_call(['cp', '/home/riehecky/code/mydjangosite/mydjangosite/test.db', '/tmp/fixture.db']) + print('----') + if uone.xml == txt: + result = True + + self.assertTrue(result, msg="Didn't find what I expected for xml") + diff --git a/updateinfo/updateinfo_django_app/tests/test_updateinfo.py b/updateinfo/updateinfo_django_app/tests/test_updateinfo.py new file mode 100644 index 0000000..989443c --- /dev/null +++ b/updateinfo/updateinfo_django_app/tests/test_updateinfo.py @@ -0,0 +1,224 @@ +#pylint: disable=line-too-long + +############################################################ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Version 0.2 by Pat Riehecky for Scientific Linux +# Copyright (2019). Fermi Research Alliance, LLC. +############################################################ + +from __future__ import unicode_literals +from __future__ import absolute_import + +from django.test import TestCase +import unittest + +############################################################ +# Testing module: +from updateinfo.updateinfo_django_app.models import Updateinfo +############################################################ + +# for Compat Tests +from updateinfo.updateinfo_django_app.models import Update +from updateinfo.updateinfo_django_app.models import Collection +from updateinfo.updateinfo_django_app.models import Reference +from updateinfo.updateinfo_django_app.models import Package +from updateinfo.updateinfo.tests import UpdateinfoTests as UpdateinfoUpdateinfoTests + +############################################################ +# Create your tests here. +############################################################ +class UpdateinfoCompatUpdateModelTests(TestCase, UpdateinfoUpdateinfoTests): + Updateinfo = Updateinfo + Update = Update + Collection = Collection + Reference = Reference + Package = Package + + def test_django_object(self): + '''Make sure we are testing the right one''' + result = False + if self.Updateinfo.Update.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_update(self): + '''Make sure we are testing the right one''' + result = False + if self.Updateinfo.Update.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_update_collectionstore(self): + '''Make sure we are testing the right one''' + result = False + if self.Updateinfo.Update.CollectionStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_update_collectionstore_collection(self): + '''Make sure we are testing the right one''' + result = False + if self.Updateinfo.Update.CollectionStore.Collection.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_update_collectionstore_collection_package(self): + '''Make sure we are testing the right one''' + result = False + if self.Updateinfo.Update.CollectionStore.Collection.Package.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_update_collectionstore_collection_package_sum(self): + '''Make sure we are testing the right one''' + result = False + if self.Updateinfo.Update.CollectionStore.Collection.Package.PackageSumStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_update_referencestore(self): + '''Make sure we are testing the right one''' + result = False + if self.Updateinfo.Update.ReferenceStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_update_referencestore_reference(self): + '''Make sure we are testing the right one''' + result = False + if self.Updateinfo.Update.ReferenceStore.Reference.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_collectionstore(self): + '''Make sure we are testing the right one''' + result = False + if self.Updateinfo.CollectionStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_collectionstore_collection(self): + '''Make sure we are testing the right one''' + result = False + if self.Updateinfo.CollectionStore.Collection.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_collectionstore_collection_package(self): + '''Make sure we are testing the right one''' + result = False + if self.Updateinfo.CollectionStore.Collection.Package.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_object_collectionstore_collection_package_sum(self): + '''Make sure we are testing the right one''' + result = False + if self.Updateinfo.CollectionStore.Collection.Package.PackageSumStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_update(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_update_collectionstore(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.CollectionStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_update_collectionstore_collection(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.CollectionStore.Collection.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_update_collectionstore_collection_package(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.CollectionStore.Collection.Package.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_update_collectionstore_collection_package_sum(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.CollectionStore.Collection.Package.PackageSumStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_update_referencestore(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.ReferenceStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_update_referencestore_reference(self): + '''Make sure we are testing the right one''' + result = False + if self.Update.ReferenceStore.Reference.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_collection(self): + '''Make sure we are testing the right one''' + result = False + if self.Collection.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_collection_package(self): + '''Make sure we are testing the right one''' + result = False + if self.Collection.Package.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_collection_package_sum(self): + '''Make sure we are testing the right one''' + result = False + if self.Collection.Package.PackageSumStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_package(self): + '''Make sure we are testing the right one''' + result = False + if self.Package.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_package_sum(self): + '''Make sure we are testing the right one''' + result = False + if self.Package.PackageSumStore.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') + + def test_django_reference(self): + '''Make sure we are testing the right one''' + result = False + if self.Reference.__module__.startswith('updateinfo.updateinfo_django_app'): + result = True + self.assertTrue(result, msg='Not the django object') +