Skip to content

Commit

Permalink
Merge pull request #51 from xsnippet/remove-unused-attrs
Browse files Browse the repository at this point in the history
Remove unused snippet attributes
  • Loading branch information
malor committed Dec 24, 2017
2 parents b58ce84 + bef23ff commit 5038f68
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 28 deletions.
19 changes: 4 additions & 15 deletions tests/resources/test_snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ def snippets():
'content': 'def foo(): pass',
'syntax': 'python',
'tags': ['tag_a', 'tag_b'],
'author_id': None,
'is_public': True,
'created_at': now - datetime.timedelta(100),
'updated_at': now - datetime.timedelta(100),
},
Expand All @@ -42,8 +40,6 @@ def snippets():
'content': 'int do_something() {}',
'syntax': 'cpp',
'tags': ['tag_c'],
'author_id': None,
'is_public': True,
'created_at': now,
'updated_at': now,
},
Expand Down Expand Up @@ -235,8 +231,6 @@ async def test_get_snippets_filter_by_title_and_tag_with_pagination(
'content': '(println "Hello, World!")',
'syntax': 'clojure',
'tags': ['tag_a'],
'author_id': None,
'is_public': True,
'created_at': now,
'updated_at': now,
}
Expand Down Expand Up @@ -272,8 +266,6 @@ async def test_get_snippets_pagination(testapp, snippets, db):
'content': '(println "Hello, World!")',
'syntax': 'clojure',
'tags': ['tag_b'],
'author_id': None,
'is_public': True,
'created_at': now,
'updated_at': now,
}
Expand Down Expand Up @@ -374,7 +366,7 @@ async def test_get_snippets_pagination_bad_request_unknown_param(testapp):

async def test_post_snippet(testapp, snippets, db):
snippet = snippets[0]
for key in ('id', 'author_id', 'created_at', 'updated_at'):
for key in ('id', 'created_at', 'updated_at'):
del snippet[key]

resp = await testapp.post(
Expand All @@ -398,15 +390,13 @@ async def test_post_snippet(testapp, snippets, db):
('title', 42), # must be string
('content', 42), # must be string
('tags', ['a tag with whitespaces']), # tag must not contain spaces
('is_public', 'yes'), # must be bool
('author_id', 42), # readonly
('created_at', '2016-09-11T19:07:43'), # readonly
('updated_at', '2016-09-11T19:07:43'), # readonly
('non-existent-key', 'must not be accepted'),
])
async def test_post_snippet_malformed_snippet(name, value, testapp, snippets):
snippet = snippets[0]
for key in ('id', 'author_id', 'created_at', 'updated_at'):
for key in ('id', 'created_at', 'updated_at'):
del snippet[key]
snippet[name] = value

Expand All @@ -431,7 +421,7 @@ async def test_post_snippet_syntax_enum_allowed(
appinstance['conf']['snippet']['syntaxes'] = 'python\nclojure'

snippet = snippets[0]
for key in ('id', 'author_id', 'created_at', 'updated_at'):
for key in ('id', 'created_at', 'updated_at'):
del snippet[key]

snippet['syntax'] = 'python'
Expand All @@ -458,7 +448,7 @@ async def test_post_snippet_syntax_enum_not_allowed(
appinstance['conf']['snippet']['syntaxes'] = 'python\nclojure'

snippet = snippets[0]
for key in ('id', 'author_id', 'created_at', 'updated_at'):
for key in ('id', 'created_at', 'updated_at'):
del snippet[key]

snippet['syntax'] = 'go'
Expand All @@ -482,7 +472,6 @@ async def test_post_snippet_syntax_enum_not_allowed(
async def test_data_model_indexes_exist(db):
res = await db.snippets.index_information()

assert res['author_idx']['key'] == [('author_id', 1)]
assert res['title_idx']['key'] == [('title', 1)]
assert res['title_idx']['partialFilterExpression'] == {
'title': {'$type': 'string'}
Expand Down
6 changes: 0 additions & 6 deletions tests/services/test_snippet.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ def snippets():
'content': 'def foo(): pass',
'syntax': 'python',
'tags': ['tag_a', 'tag_b'],
'author_id': None,
'is_public': True,
'created_at': now - datetime.timedelta(100),
'updated_at': now - datetime.timedelta(100),
},
Expand All @@ -41,8 +39,6 @@ def snippets():
'content': 'int do_something() {}',
'syntax': 'cpp',
'tags': ['tag_c'],
'author_id': None,
'is_public': True,
'created_at': now,
'updated_at': now,
},
Expand Down Expand Up @@ -206,9 +202,7 @@ async def test_create(testservice, db):
'title': 'my snippet',
'content': '...',
'syntax': 'python',
'is_public': True,
'tags': [],
'author_id': None,
}

assert created == created_db
Expand Down
3 changes: 0 additions & 3 deletions xsnippet/api/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ async def setup(app):
# ensure necessary indexes exist. background=True allows operations
# read/write operations on collections while indexes are being built
futures = [
db.snippets.create_index('author_id',
name='author_idx',
background=True),
db.snippets.create_index('title',
name='title_idx',
# create a partial index to skip null values -
Expand Down
2 changes: 0 additions & 2 deletions xsnippet/api/resources/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
'content': {'type': 'string', 'required': True},
'syntax': {'type': 'string'},
'tags': {'type': 'list', 'schema': {'type': 'string', 'regex': '[\w_-]+'}},
'is_public': {'type': 'boolean'},
'author_id': {'type': 'integer', 'readonly': True},
'created_at': {'type': 'datetime', 'readonly': True},
'updated_at': {'type': 'datetime', 'readonly': True},
}
Expand Down
2 changes: 0 additions & 2 deletions xsnippet/api/services/snippet.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ async def delete(self, id):
def _normalize(self, snippet):
rv = dict({
'title': None,
'author_id': None,
'syntax': 'text',
'is_public': True,
'tags': [],
}, **snippet)

Expand Down

0 comments on commit 5038f68

Please sign in to comment.