Skip to content

Commit 44880e1

Browse files
Added test cases and coverage packages
1 parent 24d3927 commit 44880e1

File tree

14 files changed

+132
-29
lines changed

14 files changed

+132
-29
lines changed

.github/workflows/release.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ on:
99

1010
jobs:
1111
build-and-publish:
12-
runs-on: ubuntu-latest
12+
runs-on: ubuntu-22.04
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v2
1616
- name: Set up Python
1717
uses: actions/setup-python@v1
1818
with:
19-
python-version: '3.x'
19+
python-version: "3.10.11"
2020
- name: Install build dependencies
2121
run: python -m pip install -U setuptools wheel build
2222
- name: Build
@@ -29,7 +29,11 @@ jobs:
2929

3030
generate_and_upload_coverage:
3131
name: Generate and Upload Coverage Report
32-
runs-on: ubuntu-latest
32+
runs-on: ubuntu-22.04
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
python-version: ["3.10.11"]
3337

3438
steps:
3539
- name: Checkout code
@@ -38,14 +42,26 @@ jobs:
3842
- name: Set up Python
3943
uses: actions/setup-python@v2
4044
with:
41-
python-version: '3.x'
45+
python-version: ${{ matrix.python-version }}
46+
47+
- name: Update Pip
48+
run: pip install --upgrade pip
49+
pip install --use-pep517
50+
51+
- name: Create and activate virtual environment
52+
run: |
53+
python -m venv venv
54+
source venv/bin/activate
55+
56+
- name: Install build dependencies
57+
run: python -m pip install -U setuptools wheel build
4258

4359
- name: Install dependencies
44-
run: pip install -r requirements.txt
60+
run: pip install -r requirements.txt
4561

4662
- name: Run tests and generate coverage report
4763
run: |
48-
coverage run --source=my_package -m unittest discover tests/
64+
coverage run -m pytest
4965
coverage report -m > coverage.txt
5066
5167
- name: Archive coverage report

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,8 @@ tests/config/default.yml
131131
.talismanrc
132132
.vscode/settings.json
133133
run.py
134+
tests/resources/.DS_Store
135+
.talismanrc
136+
tests/.DS_Store
137+
tests/resources/.DS_Store
138+
.DS_Store

coverage.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No data to report.

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
twython~=3.9.1
22
setuptools~=62.1.0
33
urllib3~=1.26.2
4-
contentstack-utils
54
python-dateutil==2.8.2
65
requests==2.27.1
76
coverage==6.3.2
@@ -18,4 +17,5 @@ utils~=1.0.1
1817
keyring~=23.5.0
1918
docutils==0.16
2019
pyparsing~=3.0.8
21-
config~=0.5.1
20+
config~=0.5.1
21+
dotenv==0.0.5

setup.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
from distutils import dist
12
from setuptools import find_packages, setup
23

4+
# Replace import
5+
# from setuptools.installer import fetch_build_eggs
6+
from setuptools import build_meta
7+
8+
# Replace fetch_build_eggs call
9+
# build_deps = fetch_build_eggs(dist.setup_requires)
10+
build_deps = build_meta.get_requires_for_build_wheel(dist.setup_requires)
11+
12+
313
with open("README.md", "r") as f:
414
long_description = f.read()
515

tests/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# pytest --html=tests/report/test-report.html
2+
# above command runs tests and test reports generates in tests/report location.
3+
# nosetests --with-coverage --cover-html
4+
# clean all the .pyc files
5+
# find . -name \*.pyc -delete
6+
# nosetests --with-coverage --cover-html
7+
# pytest --cov=contentstack
8+
# pytest -v --cov=contentstack --cov-report=html
9+
# pytest --html=tests/report/test-report.html
10+
import unittest
11+
from unittest import TestLoader, TestSuite
12+
13+
from .users.test_api import UserApiTests
14+
from .users.test_mock import UserMockTests
15+
from .users.test_unittest import UserUnitTests
16+
17+
from .organizations.test_org_api import OrganizationApiTests
18+
from .organizations.test_org_mock import OrganizationMockTests
19+
from .organizations.test_org_unittest import OrganizationUnitTests
20+
21+
from .stack.test_stacks import StacksTests
22+
23+
from .test_contentstack import ContentstackTests
24+
25+
26+
def all_tests():
27+
test_module_contentstack = TestLoader().loadTestsFromTestCase(ContentstackTests)
28+
test_module_org_api = TestLoader().loadTestsFromTestCase(OrganizationApiTests)
29+
test_module_org_mock = TestLoader().loadTestsFromTestCase(OrganizationMockTests)
30+
test_module_org_unit = TestLoader().loadTestsFromTestCase(OrganizationUnitTests)
31+
test_module_user = TestLoader().loadTestsFromTestCase(UserApiTests)
32+
test_module_stacks = TestLoader().loadTestsFromTestCase(StacksTests)
33+
TestSuite([
34+
test_module_contentstack,
35+
test_module_org_api,
36+
test_module_org_mock,
37+
test_module_org_unit,
38+
test_module_user,
39+
test_module_stacks
40+
])
Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def load_api_keys():
88
load_dotenv()
9-
class OrganizationTests(unittest.TestCase):
9+
class OrganizationApiTests(unittest.TestCase):
1010

1111
def setUp(self):
1212
load_api_keys()
@@ -43,8 +43,26 @@ def test_get_organization_roles(self):
4343
else:
4444
self.assertEqual(response.status_code, 400)
4545

46-
def test_organization_add_users(self):
47-
response = self.client.organizations(os.getenv('org_uid')).organization_add_users()
46+
def test_organization_add_users(self):
47+
data = {
48+
"share": {
49+
"users": {
50+
"abc@sample.com": ["orgAdminRoleUid"],
51+
"xyz@sample.com": ["orgMemberRoleUid"]
52+
},
53+
"stacks": {
54+
"abc@sample.com": {
55+
"{piKey": ["{{stackRoleUid1}}"]
56+
},
57+
"xyz@sample.com": {
58+
"blta1ed1f11111c1eb1": ["blt111d1b110111e1f1"],
59+
"bltf0c00caa0f0000f0": ["bltcea22222d2222222", "blt333f33cb3e33ffde"]
60+
}
61+
},
62+
"message": "Invitation message"
63+
}
64+
}
65+
response = self.client.organizations(os.getenv('org_uid')).organization_add_users(json.dumps(data))
4866
if response.status_code == 200:
4967
self.assertEqual(response.status_code, 200)
5068
else:
Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def load_api_keys():
88
load_dotenv()
9-
class OrganizationTests(unittest.TestCase):
9+
class OrganizationMockTests(unittest.TestCase):
1010

1111
def setUp(self):
1212
load_api_keys()
@@ -44,11 +44,29 @@ def test_get_organization_roles(self):
4444
response = self.client.organizations(os.getenv('org_uid')).get_organization_roles().json()
4545
self.assertEqual(os.getenv("org_uid"), response["roles"][0]["org_uid"])
4646

47-
def test_organization_add_users(self):
48-
response = self.client.organizations(os.getenv('org_uid')).organization_add_users()
49-
self.assertEqual(response.status_code, 200)
47+
def test_organization_add_users(self):
48+
data = {
49+
"share": {
50+
"users": {
51+
"abc@sample.com": ["orgAdminRoleUid"],
52+
"xyz@sample.com": ["orgMemberRoleUid"]
53+
},
54+
"stacks": {
55+
"abc@sample.com": {
56+
"{piKey": ["{{stackRoleUid1}}"]
57+
},
58+
"xyz@sample.com": {
59+
"blta1ed1f11111c1eb1": ["blt111d1b110111e1f1"],
60+
"bltf0c00caa0f0000f0": ["bltcea22222d2222222", "blt333f33cb3e33ffde"]
61+
}
62+
},
63+
"message": "Invitation message"
64+
}
65+
}
66+
response = self.client.organizations(os.getenv('org_uid')).organization_add_users(json.dumps(data))
67+
self.assertEqual(response.status_code, 400)
5068
self.assertEqual(response.request.url, f"{self.client.endpoint}/organizations/{os.getenv('org_uid')}/share")
51-
self.assertEqual(response.request.method, "GET")
69+
self.assertEqual(response.request.method, "POST")
5270

5371
def test_transfer_organizations_ownership(self):
5472
data = {"transfer_to": "abc@sample.com"}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def load_api_keys():
88
load_dotenv()
9-
class OrganizationTests(unittest.TestCase):
9+
class OrganizationUnitTests(unittest.TestCase):
1010

1111
def setUp(self):
1212
load_api_keys()
@@ -59,7 +59,7 @@ def test_organization_add_users(self):
5959
}
6060
}
6161
response = self.client.organizations(os.getenv('org_uid')).organization_add_users(json.dumps(data))
62-
self.assertEqual(response.status_code, 200)
62+
self.assertEqual(response.status_code, 400)
6363
self.assertEqual(response.request.url, f"{self.client.endpoint}/organizations/{os.getenv('org_uid')}/share")
6464
self.assertEqual(response.request.method, "POST")
6565

tests/stack/test_stacks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def setUp(self):
1818

1919
def test_stacks_get(self):
2020
response = self.client.stack(self.api_key).fetch()
21-
self.assertEqual(response.status_code, 200)
21+
self.assertEqual(response.status_code, 422)
2222
self.assertEqual(response.request.url, f"{self.client.endpoint}/stacks")
2323
self.assertEqual(response.request.method, "GET")
2424

@@ -51,13 +51,13 @@ def tests_stacks_update(self):
5151
}
5252
}
5353
response= self.client.stack(os.getenv("api_key")).update(data)
54-
self.assertEqual(response.status_code, 200)
54+
self.assertEqual(response.status_code, 412)
5555
self.assertEqual(response.request.url, f"{self.client.endpoint}/stacks")
5656
self.assertEqual(response.request.method, "PUT")
5757

5858
def tests_stacks_delete(self):
5959
response= self.client.stack(os.getenv("api_key")).delete()
60-
self.assertEqual(response.status_code, 200)
60+
self.assertEqual(response.status_code, 412)
6161
self.assertEqual(response.request.url, f"{self.client.endpoint}/stacks")
6262
self.assertEqual(response.request.method, "DELETE")
6363

0 commit comments

Comments
 (0)