def test_list(self): PackageRepository.objects.all().delete() user = factory.make_User() handler = PackageRepositoryHandler(user, {}) expected_package_repositories = [ self.dehydrate(factory.make_PackageRepository()) for _ in range(3) ] self.assertItemsEqual(expected_package_repositories, handler.list({}))
def test_delete(self): user = factory.make_admin() handler = PackageRepositoryHandler(user, {}) package_repository = factory.make_PackageRepository() handler.delete({'id': package_repository.id}) self.assertRaises(PackageRepository.DoesNotExist, PackageRepository.objects.get, id=package_repository.id)
def test_update(self): user = factory.make_admin() handler = PackageRepositoryHandler(user, {}) package_repository = factory.make_PackageRepository() url = factory.make_url(scheme='http') handler.update({'id': package_repository.id, 'url': url}) package_repository = reload_object(package_repository) self.assertEquals(url, package_repository.url)
def test_create(self): user = factory.make_admin() handler = PackageRepositoryHandler(user, {}) package_repository_name = factory.make_name('package_repository_name') handler.create({ 'name': package_repository_name, 'url': factory.make_url(scheme='http'), }) self.assertIsNotNone( PackageRepository.objects.get(name=package_repository_name))
def test_update(self): user = factory.make_admin() handler = PackageRepositoryHandler(user, {}, None) package_repository = factory.make_PackageRepository() url = factory.make_url(scheme='http') handler.update({'id': package_repository.id, 'url': url}) package_repository = reload_object(package_repository) self.assertEquals(url, package_repository.url) event = Event.objects.get(type__level=AUDIT) self.assertIsNotNone(event) self.assertEqual( event.description, "Updated package repository '%s'." % package_repository.name)
def test_create(self): user = factory.make_admin() handler = PackageRepositoryHandler(user, {}, None) package_repository_name = factory.make_name('package_repository_name') handler.create({ 'name': package_repository_name, 'url': factory.make_url(scheme='http'), }) self.assertIsNotNone( PackageRepository.objects.get(name=package_repository_name)) event = Event.objects.get(type__level=AUDIT) self.assertIsNotNone(event) self.assertEqual( event.description, "Created package repository '%s'." % package_repository_name)
def test_delete_is_admin_only(self): user = factory.make_User() handler = PackageRepositoryHandler(user, {}) self.assertRaises(HandlerPermissionError, handler.delete, {})