Skip to content

Implemented qvarn notification feature - #4

Open
geotom wants to merge 2 commits into
vaultit:notificationsfrom
geotom:notifications
Open

Implemented qvarn notification feature#4
geotom wants to merge 2 commits into
vaultit:notificationsfrom
geotom:notifications

Conversation

@geotom

@geotom geotom commented Aug 23, 2018

Copy link
Copy Markdown

Implemented qvarn notification feature based on https://raw.githubusercontent.com/vaultit/qvarn/master/docs/qvarn-api-doc/050-api-overview.yarn

  • Updated .gitignore to ignore Eclipse project files
  • Makefile has optional PYTHON_3.6 parameter and code for setting up
    database
  • Implemented notifications view
  • Implemented notifications view tests
  • Notifications related updated to postgresql backend

https://raw.githubusercontent.com/vaultit/qvarn/master/docs/qvarn-api-doc/050-api-overview.yarn

- Updated .gitignore to ignore Eclipse project files
- Makefile has optional PYTHON_3.6 parameter and code for setting up
database
- Implemented notifications view
- Implemented notifications view tests
- Notifications related updated to postgresql backend
@geotom

geotom commented Aug 23, 2018

Copy link
Copy Markdown
Author

Tests were implemented using the qvarn documentation example and run successful against the notifications view

@sirex sirex left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general looks good, but there are some things, that probably could be fixed.

listen_on_type probably should not bu duplicated in table and json blob, unless there is a good reason for that.

User information is not added to changes table.

I'm not 100% sure, but probably it might be possible to do an SQL or at least a JSON injection, when using op method and raw JSON strings. PostgreSQL has methods that allows you to avoid dealing with JSON serialization directly.

And I don't like style of tests in general. This is my personal opinion, but I like, when tests have almost no logic, they just call a function and check the results. It is OK to repeat things in tests. Tests should be focused on testing one simple thing. In you case, one test for creating listeners tests all different variations, how listener can be created.

An one more serious issue with tests is that they share a global state. This makes it impossible to run one test function.

Comment thread qvarn/backends/postgresql.py Outdated
import os
import pathlib
import urllib.parse
import datetime

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. Oversaw it due to my linter not working.

Comment thread qvarn/backends/postgresql.py Outdated
from sqlalchemy.dialects.postgresql import insert
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql.functions import FunctionElement
from sqlalchemy.sql.expression import exists

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Only exists is unused and remained from a test.

Comment thread qvarn/backends/postgresql.py Outdated
from qvarn.backends import WrongRevision
from qvarn.backends import UnexpectedError
from qvarn.validation import validated
from coreschema.schemas import Boolean

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import. I think you should used a static code checker, something like flake8.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you're absolutely right. Eclipse does code analysis, but looking again it seems that the additional Eclipse plugin I installed to adhere the editorconfig file messed with the PyDev code analysis.

Comment thread qvarn/backends/postgresql.py Outdated
self.values = values
self.inlist = inlist


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to PEP-8, methods should be separated by a single blank line:

Method definitions inside a class are surrounded by a single blank line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Once again my pep8 automatic error reporting seem to not run due to some problems with the project setup. Personally I'm also no fan of having a 1 line rule for classes and 2 lines for top-level functions. I find it not very consistent and makes reading classes more difficult.

Comment thread qvarn/backends/postgresql.py Outdated
resource_type = schema['type']
files = version.get('files', [])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hanging trailing spaces does not contribute to the code, but make it more difficult to review.

Comment thread tests/views/test_notifications.py Outdated
def test_listeners_post (client, storage):
global LISTENER_1, LISTENER_2, LISTENER_3, LISTENER_4, REVISION_1

storage.wipe_all_data('test')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are wiping test resources, but in tests, you are using orgs resource.

assert result.status_code == 201
assert result.headers['location'].endswith(f'/orgs/listeners/{listener["id"]}')
assert listener['type'] == 'listener'
assert 'id' in listener

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, this already was checked in 56th line.

LISTENER_3 = listener['id']
assert 'notify_on_all' in listener and listener['notify_on_all'] is True
elif k == 'listener4':
LISTENER_4 = listener['id']

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, this tests contains too much logic and that makes it more difficult to read and debug. I like, when tests are simple and focused on one thing.

result = client.get('/orgs/listeners')
listeners = {r['id']:None for r in result.json()['resources']}

assert 'resources' in result.json()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already checked in 96th line.

Comment thread tests/views/test_notifications.py Outdated

# Test if listeners are listed
result = client.get('/orgs/listeners')
listeners = {r['id']:None for r in result.json()['resources']}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simply use set() here, instead of dict().

- Changes and fixed to adhere to PEP8
- Removing unused imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants