Example #1
0
 def test_fields(self):
     company = Company(
         {
             "id": "0692683e-5197-4853-a0fe-e43e35b8e7c5",
             "name": "Test Company",
             "created_on": "2020-01-01",
             "address": {
                 "line_1": "123 Test Street",
                 "town": "London",
                 "country": {"name": "UK"},
             },
         }
     )
     assert company.get_address_display() == "123 Test Street, London, UK"
     assert company.created_on.date() == datetime.date(2020, 1, 1)
 def search_company(self, query, page=1, limit=20, **kwargs):
     params = {
         "original_query": query,
         "offset": (page * limit) - limit,
         "limit": limit,
     }
     path = "/v4/public/search/company"
     data = self.post(path, **params)
     return {
         "count": data["count"],
         "results": [Company(company) for company in data["results"]],
     }
Example #3
0
 def test_company_detail(self, mock_get_company):
     """
     Company Detail should call the Datahub API
     """
     mock_get_company.return_value = Company(self.company_data)
     response = self.client.get(
         reverse(
             "barriers:company_detail",
             kwargs={
                 "barrier_id": self.barrier["id"],
                 "company_id": self.company_id,
             },
         ), )
     assert response.status_code == HTTPStatus.OK
     mock_get_company.assert_called_with(self.company_id)
     assert response.context["company"].id == self.company_id
     assert response.context["company"].name == self.company_name
Example #4
0
 def test_add_company(self, mock_get_company, mock_patch):
     """
     Add company should change the session, not call the API
     """
     mock_get_company.return_value = Company(self.company_data)
     response = self.client.post(
         reverse(
             "barriers:company_detail",
             kwargs={
                 "barrier_id": self.barrier["id"],
                 "company_id": self.company_id,
             },
         ),
         data={"company_id": self.company_id},
     )
     assert response.status_code == HTTPStatus.FOUND
     new_company = {
         "id": self.company_id,
         "name": self.company_name,
     }
     assert new_company in self.client.session["companies"]
     assert mock_patch.called is False
 def get_company(self, id):
     path = f"/v4/public/company/{id}"
     return Company(self.get(path))