Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented qvarn notification feature #4

Open
wants to merge 2 commits into
base: notifications
Choose a base branch
from

Conversation

geotom
Copy link

@geotom geotom commented Aug 23, 2018

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
Copy link
Author

geotom commented Aug 23, 2018

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

Copy link
Collaborator

@sirex sirex left a comment

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.

@@ -6,13 +6,18 @@
import os
import pathlib
import urllib.parse
import datetime
Copy link
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
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.


import ruamel.yaml as yaml
import sqlalchemy as sa
from sqlalchemy.engine import reflection
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.dialects.postgresql import ARRAY
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
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
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.

@@ -22,11 +27,21 @@
from qvarn.backends import WrongRevision
from qvarn.backends import UnexpectedError
from qvarn.validation import validated
from coreschema.schemas import Boolean
Copy link
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
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.

@@ -109,6 +124,7 @@ def __init__(self, name, values, inlist):
self.values = values
self.inlist = inlist


Copy link
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
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.


def _create_resource_type_tables(self, schema):
version = schema['versions'][-1]
subpaths = version.get('subpaths', {})
resource_type = schema['type']
files = version.get('files', [])

Copy link
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.

def test_listeners_post (client, storage):
global LISTENER_1, LISTENER_2, LISTENER_3, LISTENER_4, REVISION_1

storage.wipe_all_data('test')
Copy link
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
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
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
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.


# Test if listeners are listed
result = client.get('/orgs/listeners')
listeners = {r['id']:None for r in result.json()['resources']}
Copy link
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