Skip to content

Commit

Permalink
Docs for Email Automation
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul-verma committed Feb 24, 2022
1 parent 36d19d4 commit b44b4ec
Show file tree
Hide file tree
Showing 5 changed files with 433 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELIST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Future Themes (In-Progress or Planned):

1.2.18
------
- Added support for text and attr dict based search in XML/HTML NodeLocator.
- Added documentation for Email Reading Automation

1.2.17
------
Expand Down
4 changes: 1 addition & 3 deletions arjuna-samples/arjex/test/pkg/emailauto/check_email_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ def check_email_links(request):
ms = EmailServer.imap()
mb = ms.get_mailbox()

mb._force_state(0)
# Write code to Trigger the event that leads to sending email(s) to this mailbox.

# After the event
lemail = mb.latest(subject="Docker")
print(lemail.find_link("confirm-email"))

ms.quit()

ms.quit()
33 changes: 23 additions & 10 deletions arjuna/tpi/parser/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class NodeLocator:
Keyword Arguments:
tags: (Optional) Descendant tags for the node. Can be a string of single or multiple tags or a list/tuple of tags.
**attrs: Arbitrary number of key value pairs representing attribute name and value.
text: Partial text content.
attrs: Arbitrary attributes as a dictionary. Use this when the attr names are not valid Python names.
**attr_kwargs: Arbitrary number of key value pairs representing attribute name and value. The values here will override those in attr_dict if there is an overlap of name(s).
Raises:
Exception: If neither tag nor an attribute is provided.
Expand All @@ -53,12 +56,18 @@ class NodeLocator:
Supports nested node finding.
'''

def __init__(self, *, tags: 'strOrSequence'=None, **attrs):
def __init__(self, *, tags: 'strOrSequence'=None, text=None, attrs={}, **attr_kwargs):

if tags is None and not attrs:
if tags is None and text is None and not attrs and not attr_kwargs:
raise Exception("You must provided tags and/or attributes for finding nodes.")

attr_conditions = []

if text:
attr_conditions.append("contains(text(), '{}')".format(text))

attrs.update(attr_kwargs)

if attrs:
for attr, value in attrs.items():
if value is None:
Expand Down Expand Up @@ -124,19 +133,21 @@ def get_text(self, normalize: bool=False) -> str:
Text of this node.
Keyword Arguments:
normalize: If True, empty lines are removed and individual lines are trimmed.
normalize: If True, all extra space is trimmed to a single space.
'''
texts = self.texts

if normalize:
return "".join([l for l in texts if l !="\n"]).strip()
text = "".join([l for l in texts if l !="\n"]).strip()
text = " ".join(text.split())
return text
else:
return "".join(texts).strip()

@property
def normalized_text(self) -> str:
'''
Text of this node with empty lines removed and individual lines trimmed.
Text of this node with all extra space trimmed to a single space.
'''
return self.get_text(normalize=True)

Expand Down Expand Up @@ -446,13 +457,15 @@ def from_lxml_element(cls, element, clone=False) -> XmlNode:
return XmlNode(element).clone()

@classmethod
def node_locator(cls, *, tags: 'strOrSequence'=None, **attrs):
def node_locator(cls, *, tags: 'strOrSequence'=None, text=None, attrs={}, **attr_kwargs):
'''
Create a locator for finding an XML Node in an **XmlNode**.
Keyword Arguments:
tags: (Optional) Descendant tags for the node. Can be a string of single or multiple tags or a list/tuple of tags.
**attrs: Arbitrary number of key value pairs representing attribute name and value.
text: Partial text content.
attrs: Arbitrary attributes as a dictionary. Use this when the attr names are not valid Python names.
**attr_kwargs: Arbitrary number of key value pairs representing attribute name and value. The values here will override those in attr_dict if there is an overlap of name(s).
Raises:
Exception: If neither tag nor an attribute is provided.
Expand All @@ -462,4 +475,4 @@ def node_locator(cls, *, tags: 'strOrSequence'=None, **attrs):
Supports nested node finding.
'''
return NodeLocator(tags=tags, **attrs)
return NodeLocator(tags=tags, text=text, attrs=attrs, **attr_kwargs)
Loading

0 comments on commit b44b4ec

Please sign in to comment.