Repository: keephq/keep
Pull request: feat: Adding tests for parser

<!-- 
Thanks for creating this pull request 🤗

Please make sure that the pull request is limited to one type (docs, feature, etc.) and keep it as small as possible. You can open multiple prs instead of opening a huge one.
-->

<!-- If this pull request closes an issue, please mention the issue number below -->
Closes #99 

## 📑 Description
<!-- Add a brief description of the pr -->

<!-- You can also choose to add a list of changes and if they have been completed or not by using the markdown to-do list syntax
- [ ] Not Completed
- [x] Completed
-->

## ✅ Checks
<!-- Make sure your pr passes the CI checks and do check the following fields as needed - -->
- [x] My pull request adheres to the code style of this project
- [x] My code requires changes to the documentation
- [x] I have updated the documentation as required
- [ ] All the tests have passed

## ℹ Additional Information
<!-- Any additional information like breaking changes, dependencies added, screenshots, comparisons between new and old behavior, etc. -->


Problem statement:
Cover parser with unit test
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.

Hints from issue discussion:

Commit message: Added first test's for parser

dipping the toe into the water

Patch to review:
diff --git a/keep/parser/tests_for_parser/test_parser.py b/keep/parser/tests_for_parser/test_parser.py
new file mode 100644
index 0000000000..2a976a009f
--- /dev/null
+++ b/keep/parser/tests_for_parser/test_parser.py
@@ -0,0 +1,22 @@
+# here we are going to create all needed tests for the parser.py parse function
+import pytest
+import requests
+
+from keep.parser.parser import Parser
+
+
+def test_parse_with_nonexistent_file():
+    self = Parser()
+    # Expected error when a given input does not describe an existing file
+    with pytest.raises(FileNotFoundError):
+        self.parse('')
+
+
+def test_parse_with_nonexistent_url():
+    self = Parser()
+    # Expected error when a given input does not describe an existing URL
+    with pytest.raises(requests.exceptions.ConnectionError):
+        self.parse('https://ThisWebsiteDoNotExist.com')
+
+
+
diff --git a/pyproject.toml b/pyproject.toml
index 4524bc5136..5ae4146620 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -42,6 +42,8 @@ black = "^23.1.0"
 isort = "^5.12.0"
 autopep8 = "^2.0.1"
 flake8 = "^6.0.0"
+pytest = "^7.2.2"
+coverage = "^7.2.2"
 
 [build-system]
 requires = ["poetry-core"]


Code review comments:
diff_hunk: @@ -0,0 +1,22 @@
+# here we are going to create all needed tests for the parser.py parse function
+import pytest
+import requests
+
+from keep.parser.parser import Parser
+
+
+def test_parse_with_nonexistent_file():
+    self = Parser()
+    # Expected error when a given input does not describe an existing file
+    with pytest.raises(FileNotFoundError):
+        self.parse('')
path: keep/parser/tests_for_parser/test_parser.py
text: @user1:
parser.parser('non-existing-file')

diff_hunk: @@ -0,0 +1,22 @@
+# here we are going to create all needed tests for the parser.py parse function
+import pytest
+import requests
+
+from keep.parser.parser import Parser
+
+
+def test_parse_with_nonexistent_file():
+    self = Parser()
path: keep/parser/tests_for_parser/test_parser.py
text: @user1:
parser = Parser()