Skip to content

Commit

Permalink
Merge pull request #146 from swiftss-org/fix-failing-build
Browse files Browse the repository at this point in the history
Fix failing build
  • Loading branch information
szigyi committed Mar 8, 2024
2 parents 3f60905 + 4d52ae0 commit 2c75653
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If you are on _Windows_ and not Linux (or other *nix) you will also need to have
Create a virtual environment for this project.

If you are using [pyenv](https://github.com/pyenv/pyenv):
```
```shell
pyenv virtualenv registry-api
pyenv activate registry-api
```
Expand All @@ -50,27 +50,32 @@ $ activate venv


Install project dependencies:
```
```shell
make dep
```

### Start Developing

Spin up the project:
```
```shell
make run
```

Run migrations (every time you update Django models):
```
```shell
make migrate
```

Run tests:
```
```shell
make test
```

Run one test:
```shell
make test-one file=tmh_registry/registry/tests/api/viewsets/test_discharges.py test_name=TestDischargeCreate
```

Everything you need for this project is under [Makefile](./Makefile). Take a look at the commands by running `make`.

### Create a local user in Django
Expand Down
9 changes: 4 additions & 5 deletions tmh_registry/registry/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Meta:
episode_type = LazyAttribute(
lambda _: faker.random_element(Episode.EpisodeChoices.values)
)
comments = LazyAttribute(lambda _: faker.sentence(nb_words=10))
# comments = LazyAttribute(lambda _: faker.sentence(nb_words=10))
cepod = LazyAttribute(
lambda _: faker.random_element(Episode.CepodChoices.values)
)
Expand All @@ -93,9 +93,7 @@ class Meta:
)
diathermy_used = True
antibiotic_used = True
antibiotic_type = LazyAttribute(
lambda _: faker.random_element(Episode.AntibioticChoices.values)
)
antibiotic_type = LazyAttribute(lambda _: faker.sentence(nb_words=10))

@post_generation
def medical_personnel(self, create, extracted, **kwargs):
Expand All @@ -117,7 +115,7 @@ class Meta:
episode = SubFactory(EpisodeFactory)
date = LazyAttribute(lambda _: faker.date_object())
aware_of_mesh = LazyAttribute(lambda _: faker.boolean())
infection = LazyAttribute(lambda _: faker.boolean())
infection = LazyAttribute(lambda _: faker.sentence(nb_words=3))


class FollowUpFactory(DjangoModelFactory):
Expand All @@ -133,6 +131,7 @@ class Meta:
seroma = LazyAttribute(lambda _: faker.boolean())
infection = LazyAttribute(lambda _: faker.boolean())
numbness = LazyAttribute(lambda _: faker.boolean())
further_surgery_need = LazyAttribute(lambda _: faker.boolean())

@post_generation
def attendees(self, create, extracted, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_episode_test_data(self):
"surgery_date": "2021-10-12",
"episode_type": Episode.EpisodeChoices.UMBILICAL.label,
"surgeon_ids": [self.medical_personnel.id],
"comments": "A random comment",
# "comments": "A random comment",
"cepod": Episode.CepodChoices.PLANNED.label,
"side": Episode.SideChoices.LEFT.label,
"occurence": Episode.OccurenceChoices.RECURRENT.label,
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_create_episode_successful(self):
self.medical_personnel.user.email,
)

self.assertEqual(response.data["comments"], data["comments"])
# self.assertEqual(response.data["comments"], data["comments"])
self.assertEqual(response.data["cepod"], data["cepod"])
self.assertEqual(response.data["side"], data["side"])
self.assertEqual(response.data["occurence"], data["occurence"])
Expand Down Expand Up @@ -196,11 +196,11 @@ def test_create_episode_successful(self):

def test_create_successful_without_optional_fields(self):
data = self.get_episode_test_data()
data.pop("comments")
# data.pop("comments") TODO Sabi: should b reverted when comment is enabled
response = self.client.post(
"/api/v1/episodes/", data=data, format="json"
)

self.assertEqual(HTTP_201_CREATED, response.status_code)

self.assertEqual(response.data["comments"], "")
# self.assertEqual(response.data["comments"], "") TODO Sabi: should b reverted when comment is enabled
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_discharge_data(self):
"episode_id": self.episode.id,
"date": "2022-02-22",
"aware_of_mesh": True,
"infection": False,
"infection": "Infection is present",
}

def test_successful(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def get_follow_up_data(self):
"seroma": True,
"infection": False,
"numbness": True,
"further_surgery_need": True
}

def test_successful(self):
Expand Down
8 changes: 6 additions & 2 deletions tmh_registry/users/api/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

from tmh_registry.users.models import MedicalPersonnel

import traceback
import logging


class IsMedicalPersonnel(permissions.BasePermission):
message = "MedicalPersonnel instance is required"

def has_permission(self, request, view):
try:
request.user.medical_personnel
return request.user.medical_personnel.user.is_staff
except MedicalPersonnel.DoesNotExist:
return False
except Exception:
return False

return True

0 comments on commit 2c75653

Please sign in to comment.