-
Notifications
You must be signed in to change notification settings - Fork 0
Creates repository sql database#25 #35
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
from flask import json | ||
from flask.testing import FlaskClient | ||
from pytest_mock import MockFixture | ||
|
||
|
||
def test_list_should_return_nothing(client): | ||
"""Should return an empty array""" | ||
def test_list_all_elements(client: FlaskClient, mocker: MockFixture): | ||
enriquezrene marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Should return all elements in a list""" | ||
from time_tracker_api.projects.projects_namespace import project_dao | ||
repository_find_all_mock = mocker.patch.object(project_dao.repository, 'find_all', return_value=[]) | ||
|
||
response = client.get("/projects", follow_redirects=True) | ||
|
||
assert 200 == response.status_code | ||
|
||
json_data = json.loads(response.data) | ||
assert [] == json_data | ||
repository_find_all_mock.assert_called_once() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from time_tracker_api.sql_repository import db | ||
from time_tracker_api.sql_repository import db, SQLAuditedModel | ||
|
||
|
||
class TestModel(db.Model): | ||
class PersonSQLModel(db.Model, SQLAuditedModel): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason to have SQL as part of the class name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this is the SQLAlchemy model, not a generic one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it extremelly necessat to include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, because this model is specific to the SQL implementation. As well as I have the SQL prefix in the repository and other resources related to this particular technology, which has its own characteristics: specific library, handling of commits, rollbacks, the concept of tables, columns and so forth, which is not the same as, for instance, an In-memory implementation, a Mongo Implementation, etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just by looking it has the SQL prefix you know that this has SQL-specific logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are not going to add support for Mongo, in-memory or so. We should not pollute code with implementation details. |
||
__tablename__ = 'tests' | ||
id = db.Column(db.Integer, primary_key=True) | ||
name = db.Column(db.String(80), unique=True, nullable=False) | ||
name = db.Column(db.String(80), unique=False, nullable=False) | ||
email = db.Column(db.String(120), unique=True, nullable=False) | ||
age = db.Column(db.Integer, nullable=False) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
def test_app_exists(app): | ||
"""Does app exists""" | ||
assert app is not None |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,16 +8,19 @@ | |
|
||
def test_create(sql_repository): | ||
"""Should create a new Entry""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not naming the function/method name as
Then you can get rid of comments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function just tests the function create of the repository, this is a simple and unique name. As I explained before the comment in the function is providing a verbose description of the test. |
||
from .resources import TestModel | ||
global sample_element | ||
sample_element = TestModel(name=fake.name(), | ||
email=fake.safe_email(), | ||
age=fake.pyint(min_value=10, max_value=80)) | ||
sample_element = dict(name=fake.name(), | ||
email=fake.safe_email(), | ||
age=fake.pyint(min_value=10, max_value=80)) | ||
|
||
result = sql_repository.create(sample_element) | ||
|
||
assert result is not None | ||
assert result.id is not None | ||
assert result.created_at is not None | ||
assert result.created_by is not None | ||
assert result.updated_at is None | ||
assert result.updated_by is None | ||
|
||
existing_elements_registry.append(result) | ||
|
||
|
@@ -43,6 +46,9 @@ def test_update(sql_repository): | |
assert updated_element.id == existing_element.id | ||
assert updated_element.name == "Jon Snow" | ||
assert updated_element.age == 34 | ||
enriquezrene marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert updated_element.updated_at is not None | ||
assert updated_element.updated_at > updated_element.created_at | ||
assert updated_element.updated_by is not None | ||
|
||
|
||
def test_find_all(sql_repository): | ||
|
@@ -54,10 +60,10 @@ def test_find_all(sql_repository): | |
|
||
def test_find_all_that_contains_property_with_string(sql_repository): | ||
"""Find all elements that have a property that partially contains a string (case-insensitive)""" | ||
from .resources import TestModel | ||
new_element = TestModel(name='Ramsay Snow', | ||
email=fake.safe_email(), | ||
age=fake.pyint(min_value=10, max_value=80)) | ||
fake_name = fake.name() | ||
new_element = dict(name="%s Snow" % fake_name, | ||
email=fake.safe_email(), | ||
age=fake.pyint(min_value=10, max_value=80)) | ||
sql_repository.create(new_element) | ||
existing_elements_registry.append(new_element) | ||
|
||
|
@@ -67,8 +73,8 @@ def test_find_all_that_contains_property_with_string(sql_repository): | |
search_jon_result = sql_repository.find_all_contain_str('name', 'Jon') | ||
assert len(search_jon_result) == 1 | ||
|
||
search_ram_result = sql_repository.find_all_contain_str('name', 'RAM') | ||
assert search_ram_result[0] is new_element | ||
search_ram_result = sql_repository.find_all_contain_str('name', fake_name) | ||
assert search_ram_result[0].name == new_element['name'] | ||
|
||
|
||
def test_delete_existing_element(sql_repository): | ||
|
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.