Browse Source

Added new tests and Move data to seperate file (#34)

* 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

* Moved data out to sperate module

* Added associate test for rbuser to_string

* Fixed Issues
pull/35/merge
greenday 4 years ago
committed by Cian Butler
parent
commit
be35652255
2 changed files with 143 additions and 67 deletions
  1. +123
    -0
      tests/data_rbuser_tostring.py
  2. +20
    -67
      tests/test_rbuser_tostring.py

+ 123
- 0
tests/data_rbuser_tostring.py View File

@@ -0,0 +1,123 @@
"""Data for the rbuser to_string test"""

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, }
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'

ASSOCIATE_ONE_ATTR = {'cn': 'Associate One',
'id': 15358478,
'uid': 'associateOne',
'bday': 12,
'host': 'carbon',
'year': 3,
'gecos': 'new associate',
'byear': 2017,
'bmonth': 2,
'passwd': 'e1NTSEF9WlBURGtJdmZJSld0WUlrak9zdGxscXYySTRRVEhBYj=',
'newbie': False,
'course': 'CPSSD',
'created': '2010-09-06 11:69:69',
'altmail': 'associateOne@example.dcu.ie',
'updated': '2015-09-28 01:42:21',
'birthday': '09 07 1732',
'usertype': 'associate',
'updatedby': 'admin',
'uidNumber': 102009,
'createdby': 'admin',
'gidNumber': 1019,
'yearsPaid': 1,
'loginShell': '/usr/local/shells/bash',
'objectClass': ['redbrick', 'posixAccount', 'top', 'shadowAccount'],
'oldusertype': 'member',
'userPassword': 'e1NTSEF9WlBURGtJdmZJSld0WUlrak9zdGxscXYySTRRVEhj=',
'homeDirectory': '/home/redbrick/associateOne',
'disuser_period': 0,
'shadowLastChange': 17064, }
ASSOCIATE_ONE_OUTPUT = \
'cn : Associate One\n' + \
'id : 15358478\n' + \
'uid : associateOne\n' + \
'bday : 12\n' + \
'host : carbon\n' + \
'year : 3\n' + \
'byear : 2017\n' + \
'gecos : new associate\n' + \
'bmonth : 2\n' + \
'course : CPSSD\n' + \
'newbie : False\n' + \
'passwd : e1NTSEF9WlBURGtJdmZJSld0WUlrak9zdGxscXYySTRRVEhBYj=\n' + \
'altmail : associateOne@example.dcu.ie\n' + \
'created : 2010-09-06 11:69:69\n' + \
'updated : 2015-09-28 01:42:21\n' + \
'birthday : 09 07 1732\n' + \
'usertype : associate\n' + \
'createdby : admin\n' + \
'gidNumber : 1019\n' + \
'uidNumber : 102009\n' + \
'updatedby : admin\n' + \
'yearsPaid : 1\n' + \
'loginShell : /usr/local/shells/bash\n' + \
'objectClass : [\'redbrick\', \'posixAccount\', \'top\', ' + \
'\'shadowAccount\']\n' + \
'oldusertype : member\n' + \
'userPassword : e1NTSEF9WlBURGtJdmZJSld0WUlrak9zdGxscXYySTRRVEhj=\n' + \
'homeDirectory : /home/redbrick/associateOne\n' + \
'disuser_period : 0\n' + \
'shadowLastChange : 17064\n'

+ 20
- 67
tests/test_rbuser_tostring.py View File

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

import unittest

from tests import data_rbuser_tostring as data
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.'"""
def test_member_one(self):
"""Test case A. Member One"""
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'
member_one.set_attr(**data.MEMBER_ONE_ATTR)
to_string_output = member_one.__str__()
assert to_string_output == data.MEMBER_ONE_OUTPUT, \
'member1 attributes not as expected. ' + \
'Diff at: ' + [i for i in range(len(data.MEMBER_ONE_OUTPUT))
if data.MEMBER_ONE_OUPUT[i] != to_string_output[i]]

def test_associate_one(self):
"""Test case B. Associate One"""
associate_one = rbuser.RBUser()
associate_one.set_attr(**data.ASSOCIATE_ONE_ATTR)
to_string_output = associate_one.__str__()
assert associate_one.__str__() == data.ASSOCIATE_ONE_OUTPUT, \
'associate one attributes not as expected' + \
'Diff at: ' + [i for i in range(len(data.ASSOCIATE_ONE_OUTPUT))
if data.ASSOCIATE_ONE_OUTPUT[i] != to_string_output[i]]

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

Loading…
Cancel
Save