forked from ColtonProvias/sqlalchemy-jsonapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new unit test and setup testcase
- Loading branch information
kjohnson3
committed
Feb 28, 2017
1 parent
94f1804
commit f9c223a
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Model file for unit testing.""" | ||
|
||
from sqlalchemy import Column, String, Integer | ||
from sqlalchemy.ext.declarative import declarative_base | ||
|
||
from sqlalchemy_jsonapi import JSONAPI | ||
|
||
|
||
Base = declarative_base() | ||
|
||
|
||
class User(Base): | ||
"""Simple user model.""" | ||
|
||
__tablename__ = 'users' | ||
id = Column(Integer, primary_key=True) | ||
first = Column(String(50), nullable=False) | ||
last = Column(String(50), nullable=False) | ||
|
||
|
||
serializer = JSONAPI(Base) |
44 changes: 44 additions & 0 deletions
44
sqlalchemy_jsonapi/unittests/test_serializer_post_collection.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Test for serializer's post_collection.""" | ||
|
||
from sqlalchemy_jsonapi.unittests.utils import testcases | ||
from sqlalchemy_jsonapi.unittests.models import serializer | ||
|
||
|
||
class PostCollection(testcases.SqlalchemyJsonapiTestCase): | ||
"""Tests for serializer.post_collection.""" | ||
|
||
def test_201_resource_creation(self): | ||
"""Create resource object succesfully.""" | ||
payload = { | ||
'data': { | ||
'type': 'users', | ||
'attributes': { | ||
'first': 'Sally', | ||
'last': 'Smith' | ||
} | ||
} | ||
} | ||
response = serializer.post_collection(self.session, payload, 'users') | ||
|
||
expected_response = { | ||
'data': { | ||
'attributes': { | ||
'first': 'Sally', | ||
'last': 'Smith' | ||
}, | ||
'id': 1, | ||
'relationships': {}, | ||
'type': 'users' | ||
}, | ||
'included': [], | ||
'jsonapi': { | ||
'version': '1.0' | ||
}, | ||
'meta': { | ||
'sqlalchemy_jsonapi_version': '4.0.9' | ||
} | ||
} | ||
|
||
actual = response.data | ||
self.assertEqual(expected_response, actual) | ||
self.assertEqual(201, response.status_code) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Testcases for sqlalchemy_jsonapi unittests.""" | ||
|
||
import unittest | ||
|
||
from sqlalchemy_jsonapi.unittests.models import Base | ||
from sqlalchemy.orm import sessionmaker | ||
from sqlalchemy import create_engine | ||
|
||
|
||
class SqlalchemyJsonapiTestCase(unittest.TestCase): | ||
"""Base test case for all tests.""" | ||
|
||
def setUp(self, *args, **kwargs): | ||
"""Configure sqlalchemy and session.""" | ||
super(SqlalchemyJsonapiTestCase, self).setUp(*args, **kwargs) | ||
self.engine = create_engine('sqlite://') | ||
Session = sessionmaker(bind=self.engine) | ||
self.session = Session() | ||
Base.metadata.create_all(self.engine) | ||
|
||
def tearDown(self, *args, **kwargs): | ||
"""Reset the sqlalchemy engine.""" | ||
super(SqlalchemyJsonapiTestCase, self).tearDown(*args, **kwargs) | ||
Base.metadata.drop_all(self.engine) |