Skip to content

Commit 5e1c150

Browse files
surajitsurajit
authored andcommitted
add test for company
1 parent 74ed6e7 commit 5e1c150

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/routes/test_company.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from unittest import mock
22

33
from hubspot_api.utils import CompanyException
4+
from models.payment import Organization
45

56

67
@mock.patch("routes.v1.company.utils.get_company_by_name")
@@ -21,3 +22,53 @@ def test_company_for_hubspot_companyexception(mock_get_company_by_name, client):
2122
assert response.json() == {
2223
"detail": "Something went wrong in fetching company from Hubspot"
2324
}
25+
26+
27+
@mock.patch("routes.v1.company.utils.create_company")
28+
def test_create_company(mock_create_company, client):
29+
mock_create_company.return_value = {"company_id": 1111}
30+
response = client.post(
31+
"/api/v1/companies/", json={"org_id": 123, "name": "Warner Bros co"}
32+
)
33+
assert response.status_code == 200
34+
assert response.json() == {"company_id": 1111}
35+
36+
37+
@mock.patch("routes.v1.company.utils.create_company")
38+
def test_create_company_with_hubspot_companyexception(mock_create_company, client, db):
39+
mock_create_company.side_effect = CompanyException(
40+
"Something went wrong in creating company in Hubspot"
41+
)
42+
response = client.post(
43+
"/api/v1/companies/", json={"org_id": 123, "name": "Warner Bros co"}
44+
)
45+
company = db.query(Organization).filter_by(name="Warner Bros co").all()
46+
assert response.status_code == 200
47+
assert response.json() == {
48+
"detail": "Something went wrong in creating company in Hubspot"
49+
}
50+
assert company == []
51+
52+
53+
def test_create_company_with_duplicate_organization_org_id(client, organization):
54+
response = client.post(
55+
"/api/v1/companies/", json={"org_id": 12345, "name": "UWISO"}
56+
)
57+
assert response.status_code == 200
58+
assert response.json() == {
59+
"detail": "duplicate key value violates unique constraint "
60+
'"organization_org_id_key"\nDETAIL: Key (org_id)=('
61+
"12345) already exists.\n"
62+
}
63+
64+
65+
def test_create_company_with_duplicate_organization_name(client, organization):
66+
response = client.post(
67+
"/api/v1/companies/", json={"org_id": 1232245, "name": "Test org"}
68+
)
69+
assert response.status_code == 200
70+
assert response.json() == {
71+
"detail": "duplicate key value violates unique constraint "
72+
'"organization_name_key"\nDETAIL: Key (name)=('
73+
"Test org) already exists.\n"
74+
}

0 commit comments

Comments
 (0)