-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support after, before, newer/older_than searches on dates
- Loading branch information
Showing
2 changed files
with
42 additions
and
49 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from datetime import date | ||
|
||
import pytest | ||
|
||
from gmail_yaml_filters.ruleset import RuleAction, RuleCondition, RuleSet | ||
|
||
|
||
|
@@ -22,52 +26,32 @@ def sample_rule(name): | |
# Test how identifier_map and formatter_map operate | ||
|
||
|
||
def test_condition_has(): | ||
assert _flat({"has": "whatever"}) == { | ||
"hasTheWord": RuleCondition("hasTheWord", "whatever"), | ||
} | ||
|
||
|
||
def test_condition_has_special(): | ||
assert _flat({"has": "drive"}) == { | ||
"hasTheWord": RuleCondition("hasTheWord", "has:drive"), | ||
} | ||
|
||
|
||
def test_condition_has_label(): | ||
assert _flat({"labeled": "whatever"}) == { | ||
"hasTheWord": RuleCondition("hasTheWord", "label:(whatever)"), | ||
} | ||
|
||
|
||
def test_condition_does_not_have_label(): | ||
assert _flat({"labeled": "-whatever"}) == { | ||
"doesNotHaveTheWord": RuleCondition("doesNotHaveTheWord", "label:(whatever)"), | ||
} | ||
|
||
|
||
def test_condition_is(): | ||
assert _flat({"is": "snoozed"}) == { | ||
"hasTheWord": RuleCondition("hasTheWord", "is:(snoozed)"), | ||
} | ||
|
||
|
||
def test_condition_is_not(): | ||
assert _flat({"is": "-snoozed"}) == { | ||
"doesNotHaveTheWord": RuleCondition("doesNotHaveTheWord", "is:(snoozed)"), | ||
} | ||
|
||
|
||
def test_action_archive(): | ||
assert _flat({"archive": True}) == { | ||
"shouldArchive": RuleAction("shouldArchive", "true"), | ||
} | ||
|
||
|
||
def test_action_forward(): | ||
assert _flat({"forward": "[email protected]"}) == { | ||
"forwardTo": RuleAction("forwardTo", "[email protected]"), | ||
} | ||
@pytest.mark.parametrize( | ||
"input,condition,value", | ||
[ | ||
({"has": "whatever"}, "hasTheWord", "whatever"), | ||
({"has": "drive"}, "hasTheWord", "has:drive"), | ||
({"labeled": "whatever"}, "hasTheWord", "label:(whatever)"), | ||
({"labeled": "-whatever"}, "doesNotHaveTheWord", "label:(whatever)"), | ||
({"is": "snoozed"}, "hasTheWord", "is:(snoozed)"), | ||
({"is": "-snoozed"}, "doesNotHaveTheWord", "is:(snoozed)"), | ||
({"after": date(2024, 2, 15)}, "hasTheWord", "after:2024-02-15"), | ||
({"before": date(2024, 2, 15)}, "hasTheWord", "before:2024-02-15"), | ||
], | ||
) | ||
def test_flattened_condition(input, condition, value): | ||
assert _flat(input) == {condition: RuleCondition(condition, value)} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"input,condition,value", | ||
[ | ||
({"archive": True}, "shouldArchive", "true"), | ||
({"forward": "[email protected]"}, "forwardTo", "[email protected]"), | ||
], | ||
) | ||
def test_flattened_action(input, condition, value): | ||
assert _flat(input) == {condition: RuleAction(condition, value)} | ||
|
||
|
||
def test_publishable(): | ||
|