Skip to content

Commit

Permalink
Fix tests for Plone 52 (#8)
Browse files Browse the repository at this point in the history
* fix unit tests

* use github actions

* Update ci.yml

* Update ci.yml

* update ci.yml

* remove stray -

* don't freshclam

* no need to start clamd on ubuntu

* add sockets for testing to clamd.conf

* please sudo + some isort

* install daemon?

* start clamd + some isort

* coverage

* debug clamd

* configure defaults

* configure defaults

* freshclam?

* use different logfile for freshclam

* typo

* test virus signature changes, debug geckodriver

* debug geckodriver

* fix test

* install xvfb

* install xvfb

* remove robot test dummy

* remove robot test boilerplate

* omit createcoverage script to deal with coverage errors

* pip location

* github token for coveralls; rm .travis.yml

* play with coverage command line; update changelog, python versions

* try lemurheavy/coveralls-public#1435 (comment)

* update readme badges

* test Python 3.6-3.8, coverage from master (once it's calculated)

* make tests more robust
  • Loading branch information
tschorr committed Jan 21, 2021
1 parent 37daa25 commit a09e336
Show file tree
Hide file tree
Showing 18 changed files with 148 additions and 224 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: collective.clamav CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install ClamAV
run: |
sudo apt-get -y install clamav clamav-daemon clamav-freshclam clamav-unofficial-sigs
sudo bash -c 'echo -e "TCPSocket 3310\nLocalSocket /tmp/clamd.socket\n$(cat /etc/clamav/clamd.conf)" > /etc/clamav/clamd.conf'
sudo freshclam -l /tmp/freshclam.log
sudo systemctl start clamav-daemon.service
sudo systemctl status clamav-daemon.service
head /etc/clamav/clamd.conf
- name: pip install
run: pip install -r requirements.txt -c constraints_plone52.txt
- name: buildout
run: buildout -t 10 -c test_plone52.cfg
- name: Run tests
run: bin/test --all
- name: Coverage
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
pip install coverage
coverage run --include=src/* bin/test --all
coverage json --include=src/*
pip install -q coveralls
coveralls --service=github
8 changes: 8 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[settings]
# for details see
# http://docs.plone.org/develop/styleguide/python.html#grouping-and-sorting
force_alphabetical_sort = True
force_single_line = True
lines_after_imports = 2
line_length = 200
not_skip = __init__.py
53 changes: 0 additions & 53 deletions .travis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Changelog
- Added a test for value NOT_CHANGED to the validator module because
of a change in converter.py of plone.formwidget.namedfile [Andreas Mantke]
- isort and flake8 fixes in validator module [Andreas Mantke]
- Fix tests for Plone 5.2, discontinue Travis and switch to Github Actions
[tschorr]



Expand Down
7 changes: 5 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
collective.clamav
=================

.. image:: https://travis-ci.org/collective/collective.clamav.svg?branch=master
:target: https://travis-ci.org/collective/collective.clamav
.. image:: https://github.com/collective/collective.clamav/workflows/collective.clamav%20CI/badge.svg
:target: https://github.com/collective/collective.clamav/actions?query=workflow%3A%22collective.clamav+CI%22

.. image:: https://coveralls.io/repos/github/collective/collective.clamav/badge.svg?branch=master
:target: https://coveralls.io/github/collective/collective.clamav?branch=master

A product providing clamav antivirus integration for Plone sites with AT and Dexterity content types.
It does that by defining a validator which could be used with any content
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"Programming Language :: Python",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Operating System :: OS Independent",
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
],
Expand Down
2 changes: 1 addition & 1 deletion src/collective/clamav/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""Init and utils."""
from zope.i18nmessageid import MessageFactory
from Products.validation import validation
from zope.i18nmessageid import MessageFactory


_ = MessageFactory('collective.clamav')
Expand Down
6 changes: 3 additions & 3 deletions src/collective/clamav/browser/controlpanel.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from plone.app.registry.browser import controlpanel
from collective.clamav import _
from collective.clamav.interfaces import IAVScannerSettings
from plone.app.registry.browser import controlpanel


class ClamavControlPanelForm(controlpanel.RegistryEditForm):
Expand All @@ -10,10 +10,10 @@ class ClamavControlPanelForm(controlpanel.RegistryEditForm):
description = _(u"""""")

def updateFields(self):
super(ClamavControlPanelForm, self).updateFields()
super(ClamavControlPanelForm, self).updateFields()

def updateWidgets(self):
super(ClamavControlPanelForm, self).updateWidgets()
super(ClamavControlPanelForm, self).updateWidgets()


class ClamavControlPanelView(controlpanel.ControlPanelFormWrapper):
Expand Down
9 changes: 5 additions & 4 deletions src/collective/clamav/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"""Module where all interfaces, events and exceptions live."""

from collective.clamav import _
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.interface import Interface
from zope import schema
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
from zope.interface import Interface
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.schema.vocabulary import SimpleTerm
from zope.schema.vocabulary import SimpleVocabulary


class ICollectiveClamavLayer(IDefaultBrowserLayer):
Expand All @@ -14,7 +15,7 @@ class ICollectiveClamavLayer(IDefaultBrowserLayer):

clamdConnectionType = SimpleVocabulary(
[SimpleTerm(title=u'Unix Socket', value='socket'),
SimpleTerm(title=u'Network', value='net')]
SimpleTerm(title=u'Network', value='net')],
)


Expand Down
8 changes: 3 additions & 5 deletions src/collective/clamav/scanner.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
import clamd

from zope.interface import implementer

from collective.clamav.interfaces import IAVScanner

from six import BytesIO
from zope.interface import implementer

import clamd


class ScanError(Exception):
Expand Down
14 changes: 6 additions & 8 deletions src/collective/clamav/testing.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
# -*- coding: utf-8 -*-
from collective.clamav.interfaces import IAVScanner
from plone.app.contenttypes.testing import PLONE_APP_CONTENTTYPES_FIXTURE
from plone.app.robotframework.testing import REMOTE_LIBRARY_BUNDLE_FIXTURE
from plone.app.testing import applyProfile
from plone.app.testing import FunctionalTesting
from plone.app.testing import IntegrationTesting
from plone.app.testing import PloneSandboxLayer
from plone.testing import z2

import collective.clamav

from plone.app.testing import TEST_USER_ID
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.testing import z2
from zope.component import getGlobalSiteManager
from zope.configuration import xmlconfig
from zope.interface import implements
from zope.interface import implementer

from collective.clamav.interfaces import IAVScanner
import base64
import collective.clamav


class CollectiveClamavLayer(PloneSandboxLayer):
Expand Down Expand Up @@ -64,6 +61,7 @@ def setUpPloneSite(self, portal):

EICAR = base64.b64decode(s)


@implementer(IAVScanner)
class MockAVScanner(object):
"""Mock objects to run tests withoud clamav present.
Expand Down Expand Up @@ -94,7 +92,7 @@ def setUpZope(self, app, configurationContext):
def setUpPloneSite(self, portal):
applyProfile(portal, 'collective.clamav:default')
setRoles(portal, TEST_USER_ID, ['Manager'])
portal.invokeFactory('Folder', 'virus-folder')
portal.invokeFactory('Folder', 'virus-folder') # noqa: P001
setRoles(portal, TEST_USER_ID, ['Member'])


Expand Down
66 changes: 0 additions & 66 deletions src/collective/clamav/tests/robot/test_example.robot

This file was deleted.

35 changes: 18 additions & 17 deletions src/collective/clamav/tests/test_functional.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
# -*- coding: utf-8 -*-
from os.path import dirname, join
from io import StringIO

from collective.clamav import tests
from collective.clamav.testing import EICAR
from collective.clamav.testing import AVMOCK_FUNCTIONAL_TESTING # noqa
from collective.clamav import tests

from plone.testing.z2 import Browser
from io import BytesIO
from os.path import dirname
from os.path import join
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID, TEST_USER_NAME, TEST_USER_PASSWORD
from plone.app.testing import TEST_USER_ID
from plone.app.testing import TEST_USER_NAME
from plone.app.testing import TEST_USER_PASSWORD
from plone.testing.z2 import Browser

import unittest


def getFileData(filename):
""" return a file object from the test data folder """
filename = join(dirname(tests.__file__), 'data', filename)
return open(filename, 'r').read()
return open(filename, 'rb').read()


class TestIntegration(unittest.TestCase):
Expand All @@ -33,7 +34,7 @@ def setUp(self):

self.browser = Browser(self.layer['app'])
self.browser.addHeader(
'Authorization', 'Basic %s:%s' % (
'Authorization', 'Basic {0}:{1}'.format(
TEST_USER_NAME,
TEST_USER_PASSWORD,
),
Expand All @@ -49,17 +50,17 @@ def test_atvirusfile(self):
self.browser.open(
self.portal.absolute_url() + '/virus-folder/++add++File')
control = self.browser.getControl(name='form.widgets.file')
control.filename = 'virus.txt'
control.value = StringIO(EICAR)
with BytesIO(EICAR) as virus_file:
control.add_file(virus_file, 'text/plain', 'virus.txt')
self.browser.getControl('Save').click()
self.assertFalse('Eicar-Test-Signature' not in self.browser.contents)

# And let's see if a clean file passes...
self.browser.open(
self.portal.absolute_url() + '/virus-folder/++add++File')
control = self.browser.getControl(name='form.widgets.file')
control.filename = 'nonvirus.txt'
control.value = StringIO('Not a virus')
with BytesIO(b'Not a virus') as clean_file:
control.add_file(clean_file, 'text/plain', 'nonvirus.txt')
self.browser.getControl('Save').click()
self.assertTrue('Item created' in self.browser.contents)

Expand All @@ -70,8 +71,8 @@ def test_atvirusimage(self):
self.portal.absolute_url() + '/virus-folder/++add++Image')
control = self.browser.getControl(name='form.widgets.image')
image_data = getFileData('image.png')
control.filename = 'virus.png'
control.value = StringIO(image_data + EICAR)
with BytesIO(image_data + EICAR) as virus_image:
control.add_file(virus_image, 'image/png', 'virus.png')
self.browser.getControl('Save').click()

self.assertFalse('Changes saved' in self.browser.contents)
Expand All @@ -81,7 +82,7 @@ def test_atvirusimage(self):
self.browser.open(
self.portal.absolute_url() + '/virus-folder/++add++Image')
control = self.browser.getControl(name='form.widgets.image')
control.filename = 'nonvirus.png'
control.value = StringIO(image_data)
with BytesIO(image_data) as clean_image:
control.add_file(clean_image, 'image/png', 'nonvirus.png')
self.browser.getControl('Save').click()
self.assertTrue('Item created' in self.browser.contents)
Loading

0 comments on commit a09e336

Please sign in to comment.