Skip to content

Commit

Permalink
Add framework for user module
Browse files Browse the repository at this point in the history
  • Loading branch information
isears committed Apr 22, 2018
1 parent 37219c0 commit 50e5329
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 4 deletions.
2 changes: 2 additions & 0 deletions openmrsapi/__init__.py
Expand Up @@ -2,6 +2,8 @@
import os
import json

from .user import *

try:
API_ENDPOINT = os.environ['OPENMRS_API_ENDPOINT']
USER = os.environ['OPENMRS_USERNAME']
Expand Down
4 changes: 0 additions & 4 deletions openmrsapi/tests/test_all.py
Expand Up @@ -41,7 +41,3 @@ def test_display_to_uuid(self):
uuids = openmrsapi.display_to_uuid('user', user['display'])
assert len(uuids) == 1
assert uuids[0] == user['uuid']


if __name__ == '__main__':
unittest.main()
36 changes: 36 additions & 0 deletions openmrsapi/tests/test_user.py
@@ -0,0 +1,36 @@
import unittest
import openmrsapi

class TestUser(unittest.TestCase):
def setUp(self):
self.created_user_uuids = list()

def tearDown(self):
for uuid in self.created_user_uuids:
openmrsapi.user.remove(uuid)

def test_create(self):
new_user = openmrsapi.user.add(
'openmrsapi-createtest',
'Openmrsapi123',
first_name='Openmrsapi',
last_name='CreateTest',
role='Organizational: Doctor',
gender='M'
)

assert 'uuid' in new_user
self.created_user_uuids.append(new_user['uuid'])

def test_delete(self):
new_user = openmrsapi.user.add(
'openmrsapi-deletetest',
'Openmrsapi123',
first_name='Openmrsapi',
last_name='DeleteTest',
role='Organizational: Doctor',
gender='M'
)

res = openmrsapi.user.remove(new_user['uuid'])
assert len(res) == 0
55 changes: 55 additions & 0 deletions openmrsapi/user.py
@@ -0,0 +1,55 @@
import requests
import openmrsapi
import json


def add(
username,
password,
first_name='',
middle_name='',
last_name='',
force_pass_change=False,
role='',
gender='',
provider_account=True,
person_uuid=''):
"""
Adds a user, as well as a person for that user if 'person_uuid' not specified
:param username: A username for the user
:type username: str
:param password: A password for the user
:type password: str
:param first_name: User's first name (not used if person_uuid specified)
:type first_name: str
:param middle_name: User's middle name (not used if person_uuid specified)
:type middle_name: str
:param last_name: User's last name (not used if person_uuid specified)
:type last_name: str
:param force_pass_change: Whether or not to force a password change on first login
:type force_pass_change: bool
:param role: The user's role (must be the name of a valid openmrs role)
:type role: str
:param gender: The user's gender (must be one of 'M' or 'F'; other genders not supported in openmrs)
:type gender: str
:param provider_account: Whether or not the new account is a provider account
:type provider_account: bool
:param person_uuid: UUID of an existing person in the openmrs database
:type person_uuid: str
:rtype: dict
:return: The new user's data (guaranteed to contain uuid)
"""
pass


def remove(uuid):
"""
Removes a user as well as the person backing that user
:param uuid: UUID of user to be removed
:type uuid: str
:rtype: dict
:return: Empty if successful, error information otherwise
"""
pass

0 comments on commit 50e5329

Please sign in to comment.