Update testing

pull/30/head
Raphaël Vinot 2016-08-18 00:23:49 +02:00
parent 76812f96aa
commit cdcb1cca5e
4 changed files with 44 additions and 24 deletions

View File

@ -1,3 +1,6 @@
[![Build Status](https://travis-ci.org/MISP/PyMISP.svg?branch=master)](https://travis-ci.org/MISP/PyMISP)
[![Coverage Status](https://coveralls.io/repos/github/MISP/PyMISP/badge.svg?branch=master)](https://coveralls.io/github/MISP/PyMISP?branch=master)
# PyMISP - Python Library to access MISP
PyMISP is a Python library to access [MISP](https://github.com/MISP/MISP) platforms via their REST API.
@ -20,7 +23,7 @@ git clone https://github.com/CIRCL/PyMISP.git && cd PyMISP
python setup.py install
~~~~
## Samples and how to use PyMISP
## Samples and how to use PyMISP
Various examples and samples scripts are in the [examples/](examples/) directory.

View File

@ -10,13 +10,13 @@ import argparse
def init(url, key):
return PyMISP(url, key, True, 'json')
return PyMISP(url, key, True, 'json', debug=True)
def up_event(m, event, content):
with open(content, 'r') as f:
result = m.update_event(event, f.read())
print result.text
print(result)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Get an event from a MISP instance.')

View File

@ -86,23 +86,6 @@ class NoKey(PyMISPError):
pass
def deprecated(func):
'''This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used.'''
@functools.wraps(func)
def new_func(*args, **kwargs):
warnings.warn_explicit(
"Call to deprecated function {}.".format(func.__name__),
category=DeprecationWarning,
filename=func.__code__.co_filename,
lineno=func.__code__.co_firstlineno + 1
)
return func(*args, **kwargs)
return new_func
class PyMISP(object):
"""
Python API for MISP

View File

@ -1,14 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import requests_mock
import json
import pymisp
from pymisp import PyMISP
@requests_mock.Mocker()
class TestOffline(object):
class TestOffline(unittest.TestCase):
def setUp(self):
self.domain = 'http://misp.local/'
@ -17,12 +19,44 @@ class TestOffline(object):
self.types = json.load(open('tests/describeTypes.json', 'r'))
def initURI(self, m):
m.register_uri('GET', self.domain + 'servers/getVersion', json={"version": "2.4.50"})
m.register_uri('GET', self.domain + 'servers/getVersion', json={"version": pymisp.__version__[1:]})
m.register_uri('GET', self.domain + 'attributes/describeTypes.json', json=self.types)
m.register_uri('GET', self.domain + 'events/2', json=self.event)
m.register_uri('POST', self.domain + 'events/2', json=self.event)
m.register_uri('DELETE', self.domain + 'events/2', json={'message': 'Event deleted.'})
m.register_uri('DELETE', self.domain + 'events/3', json={'errors': ['Invalid event'], 'message': 'Invalid event', 'name': 'Invalid event', 'url': '/events/3'})
m.register_uri('DELETE', self.domain + 'attribute/2', json={'message': 'Attribute deleted.'})
def test_getEvent(self, m):
self.initURI(m)
pymisp = PyMISP(self.domain, self.key, debug=True)
e = pymisp.get_event(2)
print(e)
e1 = pymisp.get_event(2)
e2 = pymisp.get(2)
self.assertEqual(e1, e2)
self.assertEqual(self.event, e2)
def test_updateEvent(self, m):
self.initURI(m)
pymisp = PyMISP(self.domain, self.key, debug=True)
e0 = pymisp.update_event(2, json.dumps(self.event))
e1 = pymisp.update_event(2, self.event)
self.assertEqual(e0, e1)
e = {'Event': self.event}
e2 = pymisp.update(e)
self.assertEqual(e1, e2)
self.assertEqual(self.event, e2)
def test_deleteEvent(self, m):
self.initURI(m)
pymisp = PyMISP(self.domain, self.key, debug=True)
d = pymisp.delete_event(2)
self.assertEqual(d, {'message': 'Event deleted.'})
d = pymisp.delete_event(3)
self.assertEqual(d, {'errors': ['Invalid event'], 'message': 'Invalid event', 'name': 'Invalid event', 'url': '/events/3'})
def test_deleteAttribute(self, m):
# FIXME: https://github.com/MISP/MISP/issues/1449
self.initURI(m)
pymisp = PyMISP(self.domain, self.key, debug=True)
d = pymisp.delete_attribute(2)
self.assertEqual(d, {'message': 'Event deleted.'})