Browse Source

Second attempt add first tests for rbuser.to_string method (#33)

* WiP: fix linting errors (#14)

* fix linting errors

* add circle file

* update rrs to py3

* convert scripts to py3

* get rrs working

* fix shell reset

* Added install fix for pyldap (#18)

* Added install fix for pyldap

* Changed Packages to install

* install open ldap

* install open ldap

* install open ldap

* install open ldap

* install open ldap

* Changed pip insall to pip3

* fix install

* fix install

* Update config.yml

* Update config.yml

* fix install

* Remove pylint as its job is being done by codeclimate (#22)

* close #19 (#21)

* Fixed formatting in README (#23)

* Fixed formatting in README

* change to lower case for table of content to properly link

* Accidentally updated the wrong list

Linted useradm to be slightly more pep8

Linted rbaccount

Linted rbconfig

Linted rberror

Linted rbopt

Linted rbuser.py

Linted rbuserdb.py

Linted sever.py

Linted Files To a great extent without having to refactor major chuncks (#25)

* Linted useradm to be slightly more pep8

* Linted rbaccount

* Linted rbconfig

* Linted rberror

* Linted rbopt

* Linted rbuser.py

* Linted rbuserdb.py

* Linted sever.py

add .codeclimate (#26)

* set up docker ldap for test (#27)

* Fixed uncapitalised constants

* Added .__str__() method

* added set_attr method

* Added first tests to rbuser

* linted after additions

* Added .__str__() method

* added set_attr method

* Added first tests to rbuser

* linted after additions

* fixed linting errors

* fixed linting errors

* fixed linting errors

* Changed names to have numbers and types rather than names. Also changed unittest discover to run with -verbose flag

* Fixed indent

* Fixed indent

* Fixed expected output

* Chagned issues
pull/35/merge
greenday 4 years ago
committed by GitHub
parent
commit
e63599e76a
6 changed files with 100 additions and 5 deletions
  1. +1
    -0
      .circleci/config.yml
  2. +0
    -0
      __init__.py
  3. +0
    -0
      tests/__init__.py
  4. +80
    -0
      tests/test_rbuser_tostring.py
  5. +0
    -0
      useradm/__init__.py
  6. +19
    -5
      useradm/rbuser.py

+ 1
- 0
.circleci/config.yml View File

@@ -15,5 +15,6 @@ jobs:
- run: apk add --no-cache openldap-dev cyrus-sasl-dev git build-base
- checkout
- run: pip install -r useradm/requirements.txt
- run: python -m unittest discover -v
- store_test_results:
path: "test-reports/"

+ 0
- 0
__init__.py View File


+ 0
- 0
tests/__init__.py View File


+ 80
- 0
tests/test_rbuser_tostring.py View File

@@ -0,0 +1,80 @@
"""RedBrick Test Module; Tests the to_string method of the rbuser module."""

import unittest
from useradm import rbuser


class RBUserTestCase(unittest.TestCase):
"""Test Case class for to_string method"""

def setUp(self):
"""Call before every test case."""
self.member_one_attr = {'cn': 'Member One',
'id': 15358462,
'uid': 'memberOne',
'bday': 12,
'host': 'carbon',
'year': 3,
'gecos': 'new member',
'byear': 2017,
'bmonth': 2,
'passwd': 'e1NTSEF9WlBURGtJdmZJSld0WUlrak9zdGxscXYySTRRVEhBYj=',
'newbie': True,
'course': 'CASE',
'created': '2009-10-06 11:20:13',
'altmail': 'memberOne@example.dcu.ie',
'updated': '2015-09-28 01:42:21',
'birthday': '12 02 2017',
'usertype': 'member',
'updatedby': 'admin',
'uidNumber': 102007,
'createdby': 'admin',
'gidNumber': 1017,
'yearsPaid': 1,
'loginShell': '/usr/local/shells/zsh',
'objectClass': ['redbrick', 'posixAccount', 'top', 'shadowAccount'],
'oldusertype': 'newb',
'userPassword': 'e1NTSEF9WlBURGtJdmZJSld0WUlrak9zdGxscXYySTRRVEhj=',
'homeDirectory': '/home/redbrick/memberOne',
'disuser_period': 0,
'shadowLastChange': 17073, }
self.member_one_output = \
'cn : Member One\n' + \
'id : 15358462\n' + \
'uid : memberOne\n' + \
'bday : 12\n' + \
'host : carbon\n' + \
'year : 3\n' + \
'byear : 2017\n' + \
'gecos : new member\n' + \
'bmonth : 2\n' + \
'course : CASE\n' + \
'newbie : True\n' + \
'passwd : e1NTSEF9WlBURGtJdmZJSld0WUlrak9zdGxscXYySTRRVEhBYj=\n' + \
'altmail : memberOne@example.dcu.ie\n' + \
'created : 2009-10-06 11:20:13\n' + \
'updated : 2015-09-28 01:42:21\n' + \
'birthday : 12 02 2017\n' + \
'usertype : member\n' + \
'createdby : admin\n' + \
'gidNumber : 1017\n' + \
'uidNumber : 102007\n' + \
'updatedby : admin\n' + \
'yearsPaid : 1\n' + \
'loginShell : /usr/local/shells/zsh\n' + \
'objectClass : [\'redbrick\', \'posixAccount\', \'top\', ' + \
'\'shadowAccount\']\n' + \
'oldusertype : newb\n' + \
'userPassword : e1NTSEF9WlBURGtJdmZJSld0WUlrak9zdGxscXYySTRRVEhj=\n' + \
'homeDirectory : /home/redbrick/memberOne\n' + \
'disuser_period : 0\n' + \
'shadowLastChange : 17073\n'

def test_to_string(self):
"""Test case A. note that all test method names must begin with 'test.'"""
member_one = rbuser.RBUser()
member_one.set_attr(**self.member_one_attr)
assert member_one.__str__() == self.member_one_output, 'member1 attributes not as expected'

if __name__ == "__main__":
unittest.main() # run all tests

+ 0
- 0
useradm/__init__.py View File


+ 19
- 5
useradm/rbuser.py View File

@@ -16,7 +16,7 @@ __author__ = 'Cillian Sharkey'
#-----------------------------------------------------------------------------#


class RBUser:
class RBUser():
"""Class to represent a user."""

# List of valid LDAP attributes for a user. The order of these is used
@@ -123,14 +123,28 @@ class RBUser:
for i in self.attr_list_all:
setattr(self, i, getattr(usr, i))

self.set_attr()

def __str__(self):
"""Returns a string representation of a user"""
attr = list(sorted(self.__dict__, key=str))
attr = sorted(attr, key=len)
output_string = ''
for i in attr:
space = 18 - len(i)
if i in self.attr_list_all and self.__dict__[i] is not None:
output_string += i + ' ' * space + ': ' + str(self.__dict__[i]) + '\n'
else:
output_string += i + ' ' * space + ': ' + ' ----- ' + '\n'
return output_string

def set_attr(self, **attrs):
"""Sets one or many arrtributes of the user"""

for i in self.attr_list_all:
if i in attrs:
setattr(self, i, attrs[i])
elif not hasattr(self, i):
# fixme set list attributes to empty list [] or None ??
# if i in self.attr_list_value:
# setattr(self, i, [])
# else:
setattr(self, i, None)

def merge(self, usr, override=0):


Loading…
Cancel
Save