id
int64
0
843k
repository_name
stringlengths
7
55
file_path
stringlengths
9
332
class_name
stringlengths
3
290
human_written_code
stringlengths
12
4.36M
class_skeleton
stringlengths
19
2.2M
total_program_units
int64
1
9.57k
total_doc_str
int64
0
4.2k
AvgCountLine
float64
0
7.89k
AvgCountLineBlank
float64
0
300
AvgCountLineCode
float64
0
7.89k
AvgCountLineComment
float64
0
7.89k
AvgCyclomatic
float64
0
130
CommentToCodeRatio
float64
0
176
CountClassBase
float64
0
48
CountClassCoupled
float64
0
589
CountClassCoupledModified
float64
0
581
CountClassDerived
float64
0
5.37k
CountDeclInstanceMethod
float64
0
4.2k
CountDeclInstanceVariable
float64
0
299
CountDeclMethod
float64
0
4.2k
CountDeclMethodAll
float64
0
4.2k
CountLine
float64
1
115k
CountLineBlank
float64
0
9.01k
CountLineCode
float64
0
94.4k
CountLineCodeDecl
float64
0
46.1k
CountLineCodeExe
float64
0
91.3k
CountLineComment
float64
0
27k
CountStmt
float64
1
93.2k
CountStmtDecl
float64
0
46.1k
CountStmtExe
float64
0
90.2k
MaxCyclomatic
float64
0
759
MaxInheritanceTree
float64
0
16
MaxNesting
float64
0
34
SumCyclomatic
float64
0
6k
142,048
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/tests/people/test_forms.py
karaage.tests.people.test_forms.PasswordChangeFormTestCase
class PasswordChangeFormTestCase(TestCase): def _valid_change(self): person = fixtures.PersonFactory() valid_change = { "username": person.username, "old": "test", "new1": "wai5bixa8Igohxa", "new2": "wai5bixa8Igohxa", } return person, valid_change def test_valid_data(self): person, form_data = self._valid_change() form = forms.PasswordChangeForm(data=form_data, person=person) self.assertEqual(form.is_valid(), True, form.errors.items()) self.assertEqual(form.cleaned_data["new1"], "wai5bixa8Igohxa") self.assertEqual(form.cleaned_data["new2"], "wai5bixa8Igohxa") def test_password_old_password_wrong(self): person, form_data = self._valid_change() form_data["old"] = "abc" form = forms.PasswordChangeForm(data=form_data, person=person) self.assertEqual(form.is_valid(), False) self.assertEqual(form.errors.items(), dict.items( {"old": [six.u("Your old password was incorrect")]})) @skip_if_missing_requirements("cracklib") def test_password_short(self): person, form_data = self._valid_change() form_data["new1"] = "abc" form_data["new2"] = "abc" form = forms.PasswordChangeForm(data=form_data, person=person) self.assertEqual(form.is_valid(), False) self.assertEqual( form.errors.items(), dict.items( { "new2": [ six.u( "Your password was found to be insecure: Password must be at least 6 characters long.") ] } ), ) @skip_if_missing_requirements("cracklib") def test_password_simple(self): person, form_data = self._valid_change() form_data["new1"] = "qwerty" form_data["new2"] = "qwerty" form = forms.PasswordChangeForm(data=form_data, person=person) self.assertEqual(form.is_valid(), False) self.assertEqual( form.errors.items(), dict.items({"new2": [six.u( "Your password was found to be insecure: it is based on a dictionary word.")]}), ) def test_password_mismatch(self): person, form_data = self._valid_change() form_data["new2"] = "!invalid!" form = forms.PasswordChangeForm(data=form_data, person=person) self.assertEqual(form.is_valid(), False) self.assertEqual(form.errors.items(), dict.items( {"new2": [six.u("The two password fields didn't match.")]}))
class PasswordChangeFormTestCase(TestCase): def _valid_change(self): pass def test_valid_data(self): pass def test_password_old_password_wrong(self): pass @skip_if_missing_requirements("cracklib") def test_password_short(self): pass @skip_if_missing_requirements("cracklib") def test_password_simple(self): pass def test_password_mismatch(self): pass
9
0
9
0
9
0
1
0
1
3
2
0
6
0
6
6
62
6
56
21
47
0
37
19
30
1
1
0
6
142,049
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/tests/people/test_forms.py
karaage.tests.people.test_forms.AdminPasswordChangeFormTestCase
class AdminPasswordChangeFormTestCase(TestCase): def _valid_change(self): person = fixtures.PersonFactory() valid_change = {"username": person.username, "new1": "wai5bixa8Igohxa", "new2": "wai5bixa8Igohxa"} return person, valid_change def test_valid_data(self): person, form_data = self._valid_change() form = forms.AdminPasswordChangeForm(data=form_data, person=person) self.assertEqual(form.is_valid(), True, form.errors.items()) self.assertEqual(form.cleaned_data["new1"], "wai5bixa8Igohxa") self.assertEqual(form.cleaned_data["new2"], "wai5bixa8Igohxa") @skip_if_missing_requirements("cracklib") def test_password_short(self): person, form_data = self._valid_change() form_data["new1"] = "abc" form_data["new2"] = "abc" form = forms.AdminPasswordChangeForm(data=form_data, person=person) self.assertEqual(form.is_valid(), False) self.assertEqual( form.errors.items(), dict.items( { "new2": [ six.u( "Your password was found to be insecure: Password must be at least 6 characters long.") ] } ), ) @skip_if_missing_requirements("cracklib") def test_password_simple(self): person, form_data = self._valid_change() form_data["new1"] = "qwerty" form_data["new2"] = "qwerty" form = forms.AdminPasswordChangeForm(data=form_data, person=person) self.assertEqual(form.is_valid(), False) self.assertEqual( form.errors.items(), dict.items({"new2": [six.u( "Your password was found to be insecure: it is based on a dictionary word.")]}), ) def test_password_mismatch(self): person, form_data = self._valid_change() form_data["new2"] = "!invalid!" form = forms.AdminPasswordChangeForm(data=form_data, person=person) self.assertEqual(form.is_valid(), False) self.assertEqual(form.errors.items(), dict.items( {"new2": [six.u("The two password fields didn't match.")]}))
class AdminPasswordChangeFormTestCase(TestCase): def _valid_change(self): pass def test_valid_data(self): pass @skip_if_missing_requirements("cracklib") def test_password_short(self): pass @skip_if_missing_requirements("cracklib") def test_password_simple(self): pass def test_password_mismatch(self): pass
8
0
9
0
8
0
1
0
1
3
2
0
5
0
5
5
50
5
45
18
37
0
31
16
25
1
1
0
5
142,050
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/tests/people/test_forms.py
karaage.tests.people.test_forms.AddPersonFormTestCase
class AddPersonFormTestCase(TestCase): def _valid_user(self): project = fixtures.ProjectFactory() valid_user = { "username": "testuser", "project": project.id, "institute": project.institute.id, "full_name": "Joe Blow", "short_name": "Joe", "needs_account": True, "email": "test@example.com", "telephone": "8888888888", "password1": "wai5bixa8Igohxa", "password2": "wai5bixa8Igohxa", } return valid_user def test_valid_data(self): form_data = self._valid_user() form = forms.AddPersonForm(data=form_data) self.assertEqual(form.is_valid(), True, form.errors.items()) self.assertEqual(form.cleaned_data["password1"], "wai5bixa8Igohxa") self.assertEqual(form.cleaned_data["password2"], "wai5bixa8Igohxa") @skip_if_missing_requirements("cracklib") def test_password_short(self): form_data = self._valid_user() form_data["password1"] = "abc" form_data["password2"] = "abc" form = forms.AddPersonForm(data=form_data) self.assertEqual(form.is_valid(), False) self.assertEqual( form.errors.items(), dict.items( { "password2": [ six.u( "Your password was found to be insecure: Password must be at least 6 characters long.") ] } ), ) @skip_if_missing_requirements("cracklib") def test_password_simple(self): form_data = self._valid_user() form_data["password1"] = "qwerty" form_data["password2"] = "qwerty" form = forms.AddPersonForm(data=form_data) self.assertEqual(form.is_valid(), False) self.assertEqual( form.errors.items(), dict.items( {"password2": [six.u( "Your password was found to be insecure: it is based on a dictionary word.")]} ), ) def test_password_mismatch(self): form_data = self._valid_user() form_data["password2"] = "!invalid!" form = forms.AddPersonForm(data=form_data) self.assertEqual(form.is_valid(), False) self.assertEqual( form.errors.items(), dict.items( {"password2": [six.u("The two password fields didn't match.")]}) ) def test_invalid_username(self): form_data = self._valid_user() form_data["username"] = "!invalid!" form = forms.AddPersonForm(data=form_data) self.assertEqual(form.is_valid(), False) self.assertEqual( form.errors.items(), dict.items({"username": [ six.u("Usernames can only contain letters, numbers and underscores")]}), ) def test_upper_username(self): form_data = self._valid_user() form_data["username"] = "INVALID" form = forms.AddPersonForm(data=form_data) self.assertEqual(form.is_valid(), False) self.assertEqual(form.errors.items(), dict.items( {"username": [six.u("Username must be all lowercase")]})) def test_long_username(self): form_data = self._valid_user() form_data["username"] = "long" * 100 form = forms.AddPersonForm(data=form_data) self.assertEqual(form.is_valid(), False) self.assertEqual( form.errors.items(), dict.items({"username": [ six.u("Ensure this value has at most 255 characters (it has 400).")]}), )
class AddPersonFormTestCase(TestCase): def _valid_user(self): pass def test_valid_data(self): pass @skip_if_missing_requirements("cracklib") def test_password_short(self): pass @skip_if_missing_requirements("cracklib") def test_password_simple(self): pass def test_password_mismatch(self): pass def test_invalid_username(self): pass def test_upper_username(self): pass def test_long_username(self): pass
11
0
10
0
10
0
1
0
1
3
2
0
8
0
8
8
91
7
84
27
73
0
49
25
40
1
1
0
8
142,051
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/tests/machines/test_models.py
karaage.tests.machines.test_models.AccountTestCase
class AccountTestCase(TestCase): @unittest.skip("broken with mysql/postgresql") def test_username(self): assert_raises = self.assertRaises(django_exceptions.ValidationError) # Max length account = AccountFactory(username="a" * 255) account.full_clean() # Name is too long account = AccountFactory(username="a" * 256) with assert_raises: account.full_clean()
class AccountTestCase(TestCase): @unittest.skip("broken with mysql/postgresql") def test_username(self): pass
3
0
11
2
7
2
1
0.22
1
1
1
0
1
0
1
1
13
2
9
5
6
2
8
4
6
1
1
1
1
142,052
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/tests/institutes/test_models.py
karaage.tests.institutes.test_models.InstituteTestCase
class InstituteTestCase(UnitTestCase): def test_add(self): InstituteFactory(name="TestInstitute54") def test_add_existing_name(self): group, _ = Group.objects.get_or_create(name="testinstitute27") institute = InstituteFactory(name="Test Institute 27", group=group) self.assertEqual(institute.group.name, "testinstitute27") self.assertEqual(institute.group.name, institute.name.lower().replace(" ", "")) @unittest.skip("broken with mysql/postgresql") def test_username(self): assert_raises = self.assertRaises(django_exceptions.ValidationError) # Max length institution = InstituteFactory(name="a" * 255) institution.full_clean() # Name is too long institution = InstituteFactory(name="a" * 256) with assert_raises: institution.full_clean() def test_change_group(self): """Check that when changing an institutes group, old accounts are removed from the institute and new ones are added. """ account1 = simple_account() group1 = GroupFactory() # Test initial creation of the institute self.resetDatastore() institute = InstituteFactory(group=group1) self.assertEqual(self.datastore.method_calls, [ mock.call.save_institute(institute)]) # Test setting up initial group for institute self.resetDatastore() group1.save() group1.add_person(account1.person) self.assertEqual( self.datastore.method_calls, [ mock.call.save_group(group1), mock.call.add_account_to_group(account1, group1), mock.call.add_account_to_institute(account1, institute), ], ) # Test changing an existing institutions group account2 = simple_account(institute=institute) self.resetDatastore() group2 = GroupFactory() group2.add_person(account2.person) group2.save() institute.group = group2 institute.save() self.assertEqual( self.datastore.method_calls, [ mock.call.save_group(group2), mock.call.add_account_to_group(account2, group2), mock.call.save_group(group2), mock.call.save_institute(institute), # old accounts are removed mock.call.remove_account_from_institute(account1, institute), # new accounts are added mock.call.add_account_to_institute(account2, institute), ], ) # Test deleting institute self.resetDatastore() institute.delete() self.assertEqual( self.datastore.method_calls, [mock.call.remove_account_from_institute( account2, institute), mock.call.delete_institute(institute)], )
class InstituteTestCase(UnitTestCase): def test_add(self): pass def test_add_existing_name(self): pass @unittest.skip("broken with mysql/postgresql") def test_username(self): pass def test_change_group(self): '''Check that when changing an institutes group, old accounts are removed from the institute and new ones are added. ''' pass
6
1
18
2
14
3
1
0.19
1
3
3
0
4
0
4
6
78
10
57
15
51
11
36
14
31
1
2
1
4
142,053
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/tests/fixtures.py
karaage.tests.fixtures.ProjectFactory.Meta
class Meta: model = karaage.projects.models.Project
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
2
2
1
0
2
2
1
0
0
0
0
142,054
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/tests/fixtures.py
karaage.tests.fixtures.InstituteFactory.Meta
class Meta: model = karaage.institutes.models.Institute django_get_or_create = ("name",)
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,055
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/tests/fixtures.py
karaage.tests.fixtures.GroupFactory.Meta
class Meta: model = karaage.people.models.Group django_get_or_create = ("name",)
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,056
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/tests/fixtures.py
karaage.tests.fixtures.AccountFactory.Meta
class Meta: model = karaage.machines.models.Account django_get_or_create = ("person", "username")
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,057
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/projects/tables.py
karaage.projects.tables.ProjectTable.Meta
class Meta: model = Project fields = ("is_active", "pid", "name", "institute", "leaders", "last_usage") empty_text = "No items"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
0
0
0
142,058
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/projects/tables.py
karaage.projects.tables.ProjectFilter.Meta
class Meta: model = Project fields = ("pid", "name", "institute", "is_approved", "active")
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,059
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/projects/models.py
karaage.projects.models.Project.Meta
class Meta: ordering = ["pid"] db_table = "project" app_label = "karaage"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
0
0
0
142,060
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/projects/forms.py
karaage.projects.forms.UserProjectForm.Meta
class Meta: model = Project fields = ("name", "description", "additional_req")
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,061
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/projects/forms.py
karaage.projects.forms.ProjectForm.Meta
class Meta: model = Project fields = ( "pid", "name", "institute", "leaders", "description", "start_date", "end_date", "additional_req", "rcao", )
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
13
0
13
3
12
0
3
3
2
0
0
0
0
142,062
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgsoftware/tests/fixtures.py
karaage.plugins.kgsoftware.tests.fixtures.SoftwareFactory.Meta
class Meta: model = Software django_get_or_create = ("name",)
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,063
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgsoftware/tables.py
karaage.plugins.kgsoftware.tables.SoftwareTable.Meta
class Meta: model = Software fields = ("name", "description", "group", "category", "softwareversion__last_used") empty_text = "No items"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
0
0
0
142,064
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgsoftware/tables.py
karaage.plugins.kgsoftware.tables.SoftwareLicenseAgreementTable.Meta
class Meta: model = SoftwareLicenseAgreement fields = ("software", "license", "person", "date") empty_text = "No items"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
0
0
0
142,065
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgsoftware/tables.py
karaage.plugins.kgsoftware.tables.SoftwareFilter.Meta
class Meta: model = Software fields = ( "name", "description", "group", "category", "academic_only", "restricted", )
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
10
0
10
3
9
0
3
3
2
0
0
0
0
142,066
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgsoftware/models.py
karaage.plugins.kgsoftware.models.SoftwareVersion.Meta
class Meta: db_table = "software_version" ordering = ["-version"]
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,067
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/common/forms.py
karaage.common.forms.CommentForm.Meta
class Meta: model = LogEntry fields = ["change_message"]
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,068
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/tests/people/test_models.py
karaage.tests.people.test_models.PersonTestCase
class PersonTestCase(TestCase): def test_minimum_create(self): institute = InstituteFactory() person = Person.objects.create( username="mchagr", password="test", short_name="RK", full_name="Rick Spicy McHaggis", email="test@example.com", institute=institute, ) person.full_clean() self.assertFalse(person.is_admin) self.assertFalse(person.is_systemuser) self.assertEqual(str(person), "Rick Spicy McHaggis") self.assertEqual(person.short_name, "RK") self.assertEqual(person.email, "test@example.com") self.assertEqual(person.first_name, "Rick Spicy") self.assertEqual(person.last_name, "McHaggis") @unittest.skip("broken with mysql/postgresql") def test_username(self): assert_raises = self.assertRaises(django_exceptions.ValidationError) # Max length person = PersonFactory(username="a" * 255) person.full_clean() # Name is too long person = PersonFactory(username="a" * 256) with assert_raises: person.full_clean() def test_locking(self): person = PersonFactory() self.assertTrue(person.login_enabled) # Test that a locked person is disabled person.lock() self.assertFalse(person.login_enabled) # Test that an unlocked person is enabled person.unlock() self.assertTrue(person.login_enabled)
class PersonTestCase(TestCase): def test_minimum_create(self): pass @unittest.skip("broken with mysql/postgresql") def test_username(self): pass def test_locking(self): pass
5
0
13
1
11
1
1
0.12
1
4
3
0
3
0
3
3
44
6
34
10
29
4
26
9
22
1
1
1
3
142,069
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/common/models.py
karaage.common.models.LogEntry.Meta
class Meta: verbose_name = _("log entry") verbose_name_plural = _("log entries") db_table = "admin_log" app_label = "karaage" ordering = ("-action_time", "-pk")
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
6
0
6
6
5
0
6
6
5
0
0
0
0
142,070
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/common/tables.py
karaage.common.tables.LogEntryTable.Meta
class Meta: model = LogEntry fields = ("action_time", "user", "obj", "action_flag", "change_message") empty_text = "No items"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
0
0
0
142,071
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/people/tables.py
karaage.people.tables.PersonFilter.Meta
class Meta: model = Person fields = ( "active", "username", "full_name", "email", "institute", "is_admin", )
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
10
0
10
3
9
0
3
3
2
0
0
0
0
142,072
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/people/tables.py
karaage.people.tables.LeaderTable.Meta
class Meta: fields = ( "leader", "institute", "project", ) empty_text = "No items"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
7
0
7
3
6
0
3
3
2
0
0
0
0
142,073
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/people/tables.py
karaage.people.tables.GroupTable.Meta
class Meta: model = Group fields = ("name", "description") empty_text = "No items"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
0
0
0
142,074
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/people/tables.py
karaage.people.tables.GroupFilter.Meta
class Meta: model = Group fields = ("name", "description")
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,075
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/management/commands/change_pid.py
karaage.management.commands.change_pid.Command
class Command(BaseCommand): help = "Change a pid for a project and all accounts for that project" def add_arguments(self, parser): parser.add_argument("old_pid", type=str) parser.add_argument("new_pid", type=str) @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, *args, **options): old = options["old_pid"] new = options["new_pid"] try: project = Project.objects.get(pid=old) except Project.DoesNotExist: raise CommandError("project %s does not exist" % old) project_re = re.compile(r"^%s$" % settings.PROJECT_VALIDATION_RE) if not project_re.search(new): raise CommandError(settings.PROJECT_VALIDATION_ERROR_MSG) while True: confirm = input( 'Change project "%s" to "%s (yes,no): ' % (old, new)) if confirm == "yes": break elif confirm == "no": return sys.exit(0) else: print("Please enter yes or no") project.pid = new project.save() print("Changed pid on project") print("Done")
class Command(BaseCommand): def add_arguments(self, parser): pass @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, *args, **options): pass
5
0
15
3
13
0
4
0
1
2
1
0
2
0
2
2
36
7
29
10
24
0
25
9
22
6
1
2
7
142,076
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/management/commands/change_username.py
karaage.management.commands.change_username.Command
class Command(BaseCommand): help = "Change a username for a person and all accounts for that person" def add_arguments(self, parser): parser.add_argument("old_username", type=str) parser.add_argument("new_username", type=str) @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, *args, **options): old = options["old_username"] new = options["new_username"] try: person = Person.objects.get(username=old) except Person.DoesNotExist: raise CommandError("person %s does not exist" % old) try: validate_username_for_rename_person(new, person) except UsernameInvalid as e: raise CommandError(e.args[0]) except UsernameTaken as e: raise CommandError(e.args[0]) while 1: confirm = input( 'Change person "%s" and accounts to "%s (yes,no): ' % (old, new)) if confirm == "yes": break elif confirm == "no": return sys.exit(0) else: print("Please enter yes or no") for account in person.account_set.filter(date_deleted__isnull=True): account.username = new account.save() print("Changed username to %s" % account.username) person.username = new person.save() print("Changed username on person") print("Done")
class Command(BaseCommand): def add_arguments(self, parser): pass @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, *args, **options): pass
5
0
19
3
16
0
5
0
1
4
3
0
2
0
2
2
44
8
36
11
31
0
32
9
29
8
1
2
9
142,077
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/management/commands/import_csv_users.py
karaage.management.commands.import_csv_users.Command
class Command(BaseCommand): help = """Import users from a CSV file with the following format. username,password,short_name,full_name,email,institute,project""" def add_arguments(self, parser): parser.add_argument("csvfile", type=str) @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, *args, **options): csvfile = options.get("csvfile") verbosity = int(options.get("verbosity", 1)) try: data = DictReader(open(csvfile)) except FileNotFoundError: sys.stderr.write("ERROR: Failed to read CSV file.\n") sys.exit(1) success = 0 fail_count = 0 skip = 0 for user in data: fail = False if verbosity >= 1: print("Attempting to import user '%s'" % user["username"]) if "username" not in user: sys.stderr.write("Error: Failed to find username column.\n") fail = True if "password" not in user: sys.stderr.write("Error: Failed to find password column.\n") fail = True if "short_name" not in user: sys.stderr.write("Error: Failed to find short_name column.\n") fail = True if "full_name" not in user: sys.stderr.write("Error: Failed to find full_name column.\n") fail = True if "email" not in user: sys.stderr.write("Error: Failed to find email column.\n") fail = True if "institute" not in user: sys.stderr.write("Error: Failed to find institute column.\n") fail = True if "project" not in user: sys.stderr.write("Error: Failed to find project column.\n") fail = True if not RE_VALID_USERNAME.match(user["username"]): sys.stderr.write( "Error: Username is invalid. Use only letters, digits and underscores.\n") fail = True try: validate_email(user["email"]) except exceptions.ValidationError: sys.stderr.write( "Error: E-mail address '%s' is invalid.\n" % user["email"]) fail = True if fail: sys.stderr.write( "Skipping row for username '%s' due to errors\n" % user["username"]) fail_count += 1 continue try: Person.objects.get(username=user["username"]) sys.stderr.write( "Error: Username '%s' exists. Skipping\n" % user["username"]) skip += 1 continue except Person.DoesNotExist: pass try: institute = Institute.objects.get(name=user["institute"]) user["institute"] = institute except Institute.DoesNotExist: sys.stderr.write( "Error: Institute '%s' does not exist. Skipping\n" % user["institute"]) fail_count += 1 continue project = None if user["project"]: try: project = Project.objects.get(pid=user["project"]) except Project.DoesNotExist: sys.stderr.write( "Error: Project '%s' does not exist. Skipping\n" % user["project"]) fail_count += 1 continue user["password1"] = user["password"] person = Person.objects.create_user(**user) print("Successfully added user '%s'" % person) if project: add_user_to_project(person, project) success += 1 print("") print("Added: %s" % success) print("Skipped: %s" % skip) print("Failed: %s" % fail_count) sys.exit(0)
class Command(BaseCommand): def add_arguments(self, parser): pass @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, *args, **options): pass
5
0
49
7
42
0
10
0
1
7
3
0
2
0
2
2
104
16
88
16
83
0
85
15
82
19
1
3
20
142,078
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/management/commands/invite_csv_users.py
karaage.management.commands.invite_csv_users.Command
class Command(BaseCommand): help = """Initiate bulk invitation a CSV file with the following format: username,password,short_name,full_name,email,institute,project""" def add_arguments(self, parser): parser.add_argument("csvfile", type=str) @django.db.transaction.non_atomic_requests @tldap.transaction.commit_on_success def handle(self, *args, **options): csvfile = options.get("csvfile") verbosity = int(options.get("verbosity", 1)) try: data = csv.DictReader(open(csvfile)) except csv.Error: sys.stderr.write("ERROR: Failed to read CSV file.\n") sys.exit(1) success = 0 fail_count = 0 skip = 0 for user in data: fail = False if verbosity >= 1: print("Attempting to send an invite to user '%s' at '%s'" % (user.get("username"), user.get("email"))) if "username" not in user: sys.stderr.write("Error: Failed to find username column.\n") fail = True if "password" not in user: sys.stderr.write("Error: Failed to find password column.\n") fail = True if "short_name" not in user: sys.stderr.write("Error: Failed to find short_name column.\n") fail = True if "full_name" not in user: sys.stderr.write("Error: Failed to find full_name column.\n") fail = True if "email" not in user: sys.stderr.write("Error: Failed to find email column.\n") fail = True if "institute" not in user: sys.stderr.write("Error: Failed to find institute column.\n") fail = True if "project" not in user: sys.stderr.write("Error: Failed to find project column.\n") fail = True if not RE_VALID_USERNAME.match(user["username"]): sys.stderr.write( "Error: Username is invalid. Use only letters, digits and underscores.\n") fail = True try: validate_email(user["email"]) except exceptions.ValidationError: sys.stderr.write( "Error: E-mail address '%s' is invalid.\n" % user["email"]) fail = True if fail: sys.stderr.write( "Skipping row for username '%s' due to errors\n" % user["username"]) fail_count += 1 continue try: institute = Institute.objects.get(name=user["institute"]) user["institute"] = institute except Institute.DoesNotExist: sys.stderr.write( "Error: Institute '%s' does not exist. Skipping\n" % user["institute"]) fail_count += 1 continue project = None if user["project"]: try: project = Project.objects.get(pid=user["project"]) except Project.DoesNotExist: sys.stderr.write( "Error: Project '%s' does not exist. Skipping\n" % user["project"]) fail_count += 1 continue applicant, existing_person = get_applicant_from_email( user["email"]) if existing_person: print("skipping %s:%s, user already exists" % (user["username"], user["email"])) skip += 1 continue application = ProjectApplication() applicant.short_name = user["short_name"] applicant.full_name = user["full_name"] applicant.username = user["username"] application.new_applicant = applicant application.project = project application.state = ProjectApplication.OPEN application.header_message = "Please select your institute and hit the 'AAF login' button when prompted" application.reopen() email_link, is_secret = base.get_email_link(application) emails.send_invite_email(application, email_link, is_secret) success += 1 print("") print("Added: %s" % success) print("Skipped: %s" % skip) print("Failed: %s" % fail_count) sys.exit(0)
class Command(BaseCommand): def add_arguments(self, parser): pass @django.db.transaction.non_atomic_requests @tldap.transaction.commit_on_success def handle(self, *args, **options): pass
5
0
51
7
44
0
10
0
1
6
3
0
2
0
2
2
108
16
92
18
87
0
89
17
86
18
1
3
19
142,079
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/people/tables.py
karaage.people.tables.PersonTable.Meta
class Meta: model = Person fields = ("active", "username", "full_name", "institute", "is_admin", "last_usage", "date_approved") empty_text = "No items"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
0
0
0
142,080
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/management/commands/kgcreatesuperuser.py
karaage.management.commands.kgcreatesuperuser.Command
class Command(BaseCommand): help = "Used to create a karaage superuser." def add_arguments(self, parser): parser.add_argument("--username", "-u", help="Username"), parser.add_argument("--email", "-e", help="E-Mail"), parser.add_argument("--short_name", "-f", help="Short Name"), parser.add_argument("--full_name", "-l", help="Full Name"), parser.add_argument("--password", "-p", help="Password"), parser.add_argument("--institute", "-i", help="Institute Name"), @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, *args, **options): username = options["username"] email = options["email"] short_name = options["short_name"] full_name = options["full_name"] password = options["password"] institute_name = options["institute"] # Try to determine the current system user's username to use as a # default. try: import pwd unix_uid = os.getuid() unix_username = pwd.getpwuid(unix_uid)[0] default_username = unix_username.replace(" ", "").lower() if default_username == "root": default_username = "" except (ImportError, KeyError): # KeyError will be raised by getpwuid() if there is no # corresponding entry in the /etc/passwd file (a very restricted # chroot environment, for example). default_username = "" # Determine whether the default username is taken, so we don't display # it as an option. if default_username: try: Person.objects.get(username=default_username) except Person.DoesNotExist: pass else: default_username = "" # Prompt for username/email/password. Enclose this whole thing in a # try/except to trap for a keyboard interrupt and exit gracefully. try: # Get a username while 1: if not username: input_msg = "Username" if default_username: input_msg += " (Leave blank to use %r)" % default_username username = input(input_msg + ": ") if default_username and username == "": username = default_username try: validate_username_for_new_person(username) break except UsernameException as e: sys.stderr.write("%s\n" % e) username = None print("") continue # Get an email while 1: if not email: email = input("E-mail address: ") try: validate_email(email) except exceptions.ValidationError: sys.stderr.write( "Error: That e-mail address is invalid.\n") print("") email = None else: break # Get a password while 1: if not password: password = getpass.getpass() password2 = getpass.getpass("Password (again): ") if password != password2: sys.stderr.write( "Error: Your passwords didn't match.\n") password = None print("") continue if password.strip() == "": sys.stderr.write( "Error: Blank passwords aren't allowed.\n") password = None print("") continue break while 1: if not short_name: short_name = input("Short Name: ") else: break while 1: if not full_name: full_name = input("Full Name: ") else: break group_re = re.compile(r"^%s$" % settings.GROUP_VALIDATION_RE) while 1: if not institute_name: if Institute.objects.count() > 0: print("Choose an existing institute for new superuser.") print("Alternatively enter a new name to create one.") print("") print("Valid choices are:") print("") for i in Institute.active.all(): print("* %s" % i) print else: print("No Institutes in system, will create one now.") print("") institute_name = input("Institute Name: ") if not re.search(group_re, institute_name): sys.stderr.write("%s\n" % settings.GROUP_VALIDATION_ERROR_MSG) institute_name = None print("") continue else: break try: institute = Institute.objects.get(name=institute_name) print("Using existing institute %s." % institute) except Institute.DoesNotExist: group, c = Group.objects.get_or_create(name=institute_name) if c: print("Created new group %s." % group) else: print("Using existing group %s." % group) institute = Institute.objects.create( name=institute_name, group=group, is_active=True) print("Created new institute %s." % institute) except KeyboardInterrupt: sys.stderr.write("\nOperation cancelled.\n") sys.exit(1) data = { "username": username, "email": email, "password": password, "short_name": short_name, "full_name": full_name, "institute": institute, } Person.objects.create_superuser(**data) print("Karaage Superuser created successfully.")
class Command(BaseCommand): def add_arguments(self, parser): pass @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, *args, **options): pass
5
0
79
8
65
6
15
0.09
1
7
4
0
2
0
2
2
164
18
134
23
128
12
120
21
116
29
1
5
30
142,081
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/management/commands/lock_training_accounts.py
karaage.management.commands.lock_training_accounts.Command
class Command(BaseCommand): help = "Lock all training accounts" @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, **options): verbose = int(options.get("verbosity")) training_prefix = getattr(settings, "TRAINING_ACCOUNT_PREFIX", "train") # If training accounts are system users, they will be found by # Person.objects.all() but not Person.active.all() query = Person.objects.all() query = query.filter(username__iregex=training_prefix) query = query.order_by("username") for person in query.all(): try: person.lock() if verbose > 1: print("%s: Locked" % person.username) except Exception as e: print("%s: Failed to lock: %s" % (person, e))
class Command(BaseCommand): @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, **options): pass
4
0
17
2
13
2
4
0.12
1
3
1
0
1
0
1
1
22
3
17
9
13
2
15
7
13
4
1
3
4
142,082
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/management/commands/migrate_project_users.py
karaage.management.commands.migrate_project_users.Command
class Command(BaseCommand): help = "Move all project users (except leaders) out of project safely" def add_arguments(self, parser): parser.add_argument(action="store", dest="Project1", type=str, help="Project to move users from") parser.add_argument( action="store", dest="Project2", type=str, help="Catchall project for users with no remaining project" ) @django.db.transaction.non_atomic_requests @tldap.transaction.commit_on_success def handle(self, *args, **options): Project1 = options.get("Project1") Project2 = options.get("Project2") # get list of project members # first verify projects exist try: projectA = Project.objects.get(pid=Project1) except Project.DoesNotExist: sys.stderr.write("ERROR: Failed to find %s" % Project1) sys.exit(1) try: projectB = Project.objects.get(pid=Project2) except Project.DoesNotExist: sys.stderr.write("ERROR: Failed to find %s" % Project2) sys.exit(1) members = projectA.group.members.all() leaders = projectA.leaders.all() for person in members: # determine if the user is a leader of the given project, abort if true. if person in leaders: # do nothing sys.stdout.write("ignoring %s, project leader\n" % person) else: # determine if the project is the default for any of the user's # accounts... but first sort out whether we've got a single # case or a list. accountlist = person.account_set.all() accountlist = accountlist.filter(date_deleted__isnull=True) if accountlist.count() == 1: account = person.get_account() if projectA == account.default_project: sys.stdout.write( "changing default project for %s to " % person) sys.stdout.write(projectB.pid) sys.stdout.write("\n") # set default project to projectB person.add_group(projectB.group) account.default_project = projectB account.save() # remove user from group sys.stdout.write("removing %s from group " % person) sys.stdout.write(projectA.pid) sys.stdout.write("\n") person.remove_group(projectA.group) elif accountlist.count() > 1: # iterate over groups for account in accountlist: if projectA == account.default_project: # set default project to projectB sys.stdout.write( "changing default project for %s to " % person) sys.stdout.write(projectB.pid) sys.stdout.write("\n") person.add_group(projectB.group) account.default_project = projectB account.save() sys.stdout.write("removing %s from group " % person) sys.stdout.write(projectA.pid) sys.stdout.write("\n") person.remove_group(projectA.group) else: sys.stdout.write( "user %s appears to have no active account.. this shouldn't happen") sys.stdout.write("Done")
class Command(BaseCommand): def add_arguments(self, parser): pass @django.db.transaction.non_atomic_requests @tldap.transaction.commit_on_success def handle(self, *args, **options): pass
5
0
37
4
28
6
6
0.19
1
2
1
0
2
0
2
2
79
9
59
14
54
11
52
13
49
10
1
5
11
142,083
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/management/commands/unlock_training_accounts.py
karaage.management.commands.unlock_training_accounts.Command
class Command(BaseCommand): help = "Unlock all training accounts and reset password." def add_arguments(self, parser): parser.add_argument( "--password", dest="password", action="store_true", default=False, help="Read password to use on stdin." ), parser.add_argument("--number", dest="number", type=int, help="Number of accounts to unlock"), @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, *args, **options): verbose = int(options.get("verbosity")) training_prefix = getattr(settings, "TRAINING_ACCOUNT_PREFIX", "train") # If training accounts are system users, they will be found by # Person.objects.all() but not Person.active.all() query = Person.objects.all() query = query.filter(username__iregex=training_prefix) query = query.order_by("username") if options["number"] is not None: query = query[: options["number"]] password = None if options["password"]: password = sys.stdin.readline().strip() else: password = nicepass(8, 4) print("New password: %s" % password) for person in query.all(): try: if password is not None: if verbose > 1: print("%s: Setting password" % person.username) person.set_password(password) # person.unlock() will call person.save() if verbose > 1: print("%s: Unlocking" % person.username) person.unlock() except Exception as e: print("%s: Failed to unlock: %s" % (person.username, e))
class Command(BaseCommand): def add_arguments(self, parser): pass @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, *args, **options): pass
5
0
20
3
15
2
5
0.09
1
3
1
0
2
0
2
2
45
8
34
11
29
3
29
9
26
8
1
4
9
142,084
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/management/commands/vacant_projects.py
karaage.management.commands.vacant_projects.Command
class Command(BaseCommand): help = "return a list of projects with no currently active users" @django.db.transaction.non_atomic_requests def handle(self, *args, **options): badProjects = 0 for selectedProject in Project.objects.all(): members = selectedProject.group.members.all() memberCount = 0 invalidCount = 0 for person in members: if person.is_active and person.login_enabled: memberCount += 1 else: invalidCount += 1 if memberCount == 0: badProjects += 1 sys.stdout.write("{}: {} locked users".format( selectedProject.pid, invalidCount)) sys.stdout.write("\n") sys.stdout.write( "{} inactive/unpopulated projects\n".format(badProjects)) sys.stdout.write("Done\n")
class Command(BaseCommand): @django.db.transaction.non_atomic_requests def handle(self, *args, **options): pass
3
0
17
0
17
0
5
0
1
1
1
0
1
0
1
1
21
1
20
10
17
0
18
9
16
5
1
3
5
142,085
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/people/forms.py
karaage.people.forms.AdminPersonForm.Meta
class Meta: model = Person fields = [ "short_name", "full_name", "email", "title", "position", "supervisor", "department", "institute", "telephone", "mobile", "fax", "address", "country", "expires", "comment", "is_systemuser", "is_admin", ]
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
21
0
21
3
20
0
3
3
2
0
0
0
0
142,086
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/people/forms.py
karaage.people.forms.PersonForm.Meta
class Meta: model = Person fields = [ "short_name", "full_name", "email", "title", "position", "supervisor", "department", "telephone", "mobile", "fax", "address", "country", ]
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
16
0
16
3
15
0
3
3
2
0
0
0
0
142,087
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/people/models.py
karaage.people.models.Group.Meta
class Meta: ordering = ["name"] db_table = "people_group" app_label = "karaage"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
0
0
0
142,088
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/people/models.py
karaage.people.models.Person.Meta
class Meta: verbose_name_plural = "people" ordering = ["full_name", "short_name"] db_table = "person" app_label = "karaage"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
5
0
5
5
4
0
5
5
4
0
0
0
0
142,089
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/management/commands/lock_expired.py
karaage.management.commands.lock_expired.Command
class Command(BaseCommand): help = "Lock expired accounts" @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, **options): import datetime from django.core.mail import mail_admins from karaage.common import log from karaage.people.models import Person today = datetime.date.today() verbose = int(options.get("verbosity")) for p in Person.objects.filter(expires__lte=today): try: if not p.is_locked(): p.lock() p.expires = None p.save() message = "%s's account has expired and their account has been locked. %s does not know this" % ( p, p, ) mail_admins("Locked expired user %s" % p, message, fail_silently=False) log.change(p, "Account auto expired") if verbose >= 1: print("Locked account for %s - %s" % (p.username, p)) except Exception: print("Failed to lock %s" % p)
class Command(BaseCommand): @django.db.transaction.atomic @tldap.transaction.commit_on_success def handle(self, **options): pass
4
0
28
5
23
0
5
0
1
5
2
0
1
0
1
1
33
6
27
12
19
0
22
11
16
5
1
4
5
142,090
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgapplications/forms.py
karaage.plugins.kgapplications.forms.AafApplicantForm.Meta
class Meta: model = Applicant exclude = ["email", "institute"]
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,091
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgapplications/forms.py
karaage.plugins.kgapplications.forms.ApplicantForm.Meta
class Meta: model = Applicant fields = [ "email", "username", "title", "short_name", "full_name", "institute", "department", "position", "telephone", "mobile", "supervisor", "address", "city", "postcode", "country", "fax", ]
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
20
0
20
3
19
0
3
3
2
0
0
0
0
142,092
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgapplications/forms.py
karaage.plugins.kgapplications.forms.CommonApplicationForm.Meta
class Meta: model = ProjectApplication fields = ["needs_account"]
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,093
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/institutes/forms.py
karaage.institutes.forms.DelegateForm.Meta
class Meta: model = InstituteDelegate fields = ("person", "send_email")
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,094
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/institutes/forms.py
karaage.institutes.forms.InstituteForm.Meta
class Meta: model = Institute fields = ("name", "project_prefix", "saml_entityid", "saml_scoped_affiliation", "is_active")
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,095
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/institutes/models.py
karaage.institutes.models.Institute.Meta
class Meta: ordering = ["name"] db_table = "institute" app_label = "karaage"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
0
0
0
142,096
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/institutes/models.py
karaage.institutes.models.InstituteDelegate.Meta
class Meta: db_table = "institutedelegate" app_label = "karaage"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,097
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/institutes/tables.py
karaage.institutes.tables.InstituteFilter.Meta
class Meta: model = Institute fields = ("name", "active")
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,098
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/institutes/tables.py
karaage.institutes.tables.InstituteTable.Meta
class Meta: model = Institute fields = ("is_active", "name") empty_text = "No items"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
0
0
0
142,099
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/client.py
karaage.tests.client.RegexURLResolver
class RegexURLResolver: # type: ignore pass
class RegexURLResolver: pass
1
0
0
0
0
0
0
0.5
0
0
0
0
0
0
0
0
2
0
2
1
1
1
2
1
1
0
0
0
0
142,100
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/machines/forms.py
karaage.machines.forms.AdminAccountForm.Meta
class Meta: model = Account fields = ("username", "default_project", "disk_quota", "shell")
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,101
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/machines/forms.py
karaage.machines.forms.MachineForm.Meta
class Meta: model = Machine fields = ( "name", "no_cpus", "no_nodes", "type", "start_date", "end_date", "pbs_server_host", "mem_per_core", "scaling_factor", )
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
13
0
13
3
12
0
3
3
2
0
0
0
0
142,102
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/machines/forms.py
karaage.machines.forms.UserAccountForm.Meta
class Meta: model = Account fields = ("shell",)
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,103
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/machines/models.py
karaage.machines.models.Account.Meta
class Meta: ordering = [ "person", ] db_table = "account" app_label = "karaage"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
6
0
6
4
5
0
4
4
3
0
0
0
0
142,104
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/machines/models.py
karaage.machines.models.Machine.Meta
class Meta: db_table = "machine" app_label = "karaage"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,105
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/machines/tables.py
karaage.machines.tables.AccountTable.Meta
class Meta: model = Account fields = ("active", "username", "person", "default_project", "date_created", "date_deleted")
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,106
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/machines/tables.py
karaage.machines.tables.MachineTable.Meta
class Meta: model = Machine fields = ("name",) empty_text = "No items"
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
0
0
0
142,107
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgapplications/forms.py
karaage.plugins.kgapplications.forms.admin_approve_project_form_generator.AdminApproveProjectForm
class AdminApproveProjectForm(parent): if application.project is None: # new project additional_req = forms.CharField( label="Additional requirements", widget=forms.Textarea( attrs={"class": "vLargeTextField", "rows": 10, "cols": 40}), help_text=six.u("Do you have any special requirements?"), required=False, ) pid = forms.RegexField( "^%s$" % settings.PROJECT_VALIDATION_RE, required=False, label="PID", help_text="Leave blank for auto generation", error_messages={ "invalid": settings.PROJECT_VALIDATION_ERROR_MSG}, ) class Meta: model = ProjectApplication fields = include_fields def clean_pid(self): pid = self.cleaned_data["pid"] if not pid: return pid try: Institute.objects.get(name=pid) raise forms.ValidationError( six.u("Project ID already in system")) except Institute.DoesNotExist: pass try: Project.objects.get(pid=pid) raise forms.ValidationError( six.u("Project ID already in system")) except Project.DoesNotExist: pass return pid
class AdminApproveProjectForm(parent): class Meta: def clean_pid(self): pass
3
0
15
0
15
0
4
0.03
1
2
2
0
1
0
1
1
36
2
33
8
30
1
22
8
19
4
1
1
4
142,108
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgapplications/forms.py
karaage.plugins.kgapplications.forms.UserApplicantForm.Meta
class Meta: model = Applicant exclude = ["email"]
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,109
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgapplications/forms.py
karaage.plugins.kgapplications.forms.NewProjectApplicationForm.Meta
class Meta: model = ProjectApplication fields = [ "name", "description", "additional_req", "rcao", ]
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
8
0
8
3
7
0
3
3
2
0
0
0
0
142,110
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgapplications/forms.py
karaage.plugins.kgapplications.forms.InviteUserApplicationForm.Meta
class Meta: model = ProjectApplication fields = ["email", "make_leader", "header_message"]
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,111
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/plugins/kgapplications/forms.py
karaage.plugins.kgapplications.forms.ExistingProjectApplicationForm.Meta
class Meta: model = ProjectApplication fields = ["project"]
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,112
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/common/tables.py
karaage.common.tables.LogEntryFilter.Meta
class Meta: model = LogEntry fields = ("begin_action_time", "end_action_time", "content_type", "object_id")
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,113
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/tests/projects/test_models.py
karaage.tests.projects.test_models.ProjectTestCase
class ProjectTestCase(UnitTestCase): def test_minimum_create(self): institute = InstituteFactory() project = Project.objects.create( pid="test", name="Test", institute=institute) project.full_clean() self.assertEqual(project.name, "Test") self.assertEqual(project.pid, "test") self.assertEqual(project.institute, institute) self.assertEqual(project.group.name, "test") self.assertFalse(project.is_approved) self.assertEqual(project.leaders.count(), 0) self.assertTrue(project.description is None) self.assertTrue(project.deleted_by is None) self.assertTrue(project.date_deleted is None) self.assertTrue(project.approved_by is None) self.assertTrue(project.date_approved is None) self.assertTrue(project.last_usage is None) self.assertTrue(project.additional_req is None) @unittest.skip("broken with mysql/postgresql") def test_pid(self): assert_raises = self.assertRaises(django_exceptions.ValidationError) # Max length person = ProjectFactory(pid="a" * 255) person.full_clean() # Name is too long person = ProjectFactory(pid="a" * 256) with assert_raises: person.full_clean() def test_change_group(self): """Check that when changing an projects group, old accounts are removed from the project and new ones are added. """ account1 = simple_account() group1 = GroupFactory() group1.add_person(account1.person) institute = InstituteFactory() # Test during initial creation of the project self.resetDatastore() project = Project.objects.create(group=group1, institute=institute) self.assertEqual( self.datastore.method_calls, [mock.call.save_project( project), mock.call.add_account_to_project(account1, project)], ) # Test changing an existing projects group account2 = simple_account() self.resetDatastore() group2 = GroupFactory() group2.add_person(account2.person) project.group = group2 project.save() self.assertEqual( self.datastore.method_calls, [ mock.call.save_group(group2), mock.call.add_account_to_group(account2, group2), mock.call.save_project(project), # old accounts are removed mock.call.remove_account_from_project(account1, project), # new accounts are added mock.call.add_account_to_project(account2, project), ], ) # Test deleting project self.resetDatastore() project.delete() self.assertEqual( self.datastore.method_calls, [mock.call.remove_account_from_project( account2, project), mock.call.delete_project(project)], )
class ProjectTestCase(UnitTestCase): def test_minimum_create(self): pass @unittest.skip("broken with mysql/postgresql") def test_pid(self): pass def test_change_group(self): '''Check that when changing an projects group, old accounts are removed from the project and new ones are added. ''' pass
5
1
25
2
19
3
1
0.17
1
4
4
0
3
0
3
5
78
9
59
15
54
10
43
14
39
1
2
1
3
142,114
Karaage-Cluster/karaage
/Users/umroot/Documents/PhD_works/PhD-Core-Contents/Class-level-dataset-curation/data/git_repos_for_analysis/Karaage-Cluster_karaage/karaage/tests/fixtures.py
karaage.tests.fixtures.PersonFactory.Meta
class Meta: model = karaage.people.models.Person django_get_or_create = ("username",)
class Meta: pass
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
0
3
3
2
0
3
3
2
0
0
0
0
142,115
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/machines/test_views.py
karaage.tests.machines.test_views.MachineTestCase
class MachineTestCase(TestCase): def setUp(self): today = timezone.now() # 10cpus mach1 = Machine.objects.get(pk=1) mach1.start_date = today - datetime.timedelta(days=80) mach1.save() # 40 cpus mach2 = Machine.objects.get(pk=2) mach2.start_date = today - datetime.timedelta(days=100) mach2.end_date = today - datetime.timedelta(days=20) mach2.save() # 8000 cpus mach3 = Machine.objects.get(pk=3) mach3.start_date = today - datetime.timedelta(days=30) mach3.save()
class MachineTestCase(TestCase): def setUp(self): pass
2
0
15
0
12
3
1
0.23
1
2
1
0
1
0
1
1
16
0
13
6
11
3
13
6
11
1
1
0
1
142,116
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/datastores/test_ldap_schemas.py
karaage.tests.datastores.test_ldap_schemas.OpenldapAccountTestCase
class OpenldapAccountTestCase(IntegrationTestCase): def setUp(self): super(OpenldapAccountTestCase, self).setUp() def test_kAccountMixin(self): account = AccountFactory() ldap_account = self._ldap_datastore._get_account(account.username) self.assertEqual(ldap_account.get_as_single("uid"), account.username)
class OpenldapAccountTestCase(IntegrationTestCase): def setUp(self): pass def test_kAccountMixin(self): pass
3
0
3
0
3
0
1
0
1
2
1
0
2
0
2
4
8
1
7
5
4
0
7
5
4
1
2
0
2
142,117
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/defaults.py
karaage.tests.defaults.InvalidString
class InvalidString(str): def __mod__(self, other): from django.template.base import TemplateSyntaxError raise TemplateSyntaxError('Undefined variable or unknown value for: "%s"' % other)
class InvalidString(str): def __mod__(self, other): pass
2
0
4
1
3
0
1
0
1
0
0
0
1
0
1
67
5
1
4
3
1
0
4
3
1
1
2
0
1
142,118
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/client.py
karaage.tests.client.TestAllPagesMeta
class TestAllPagesMeta(type): @classmethod def _add_test_methods(mcs, attrs, urlpatterns): # loop through every URL pattern for index, (func, regex, url_name) in enumerate(extract_views_from_urlpatterns(urlpatterns)): if "module_exclude" not in attrs: attrs["module_exclude"] = None if attrs["module_exclude"] is not None: if func.__module__.startswith("%s." % attrs["module_exclude"]): continue elif func.__module__ == attrs["module_exclude"]: continue else: pass if func.__module__.startswith("%s." % attrs["module"]): pass elif func.__module__ == attrs["module"]: pass else: continue if hasattr(func, "__name__"): func_name = func.__name__ elif hasattr(func, "__class__"): func_name = "%s()" % func.__class__.__name__ else: func_name = re.sub(r" at 0x[0-9a-f]+", "", repr(func)) url_pattern = smart_str(simplify_regex(regex)) name = "_".join( [ "test", func.__module__.replace(".", "_"), slugify("%s" % func_name), ] + slugify(url_pattern.replace("/", "_") or "root").replace("_", " ").split(), ) url = url_pattern for key, value in attrs["variables"].items(): url = url.replace("<%s>" % key, value) # bail out if we don't know how to visit this URL properly testfunc = unittest.skipIf( any( re.search(stop_pattern, url) for stop_pattern in [ r"<.*>", ] ), "URL pattern %r contains stop pattern." % url, )( make_test_get_function(name, url, url_pattern), ) attrs[name] = testfunc def __new__(mcs, name, parents, attrs): if parents != (TestCase,): mcs._add_test_methods(attrs, urlconf.urlpatterns) return super(TestAllPagesMeta, mcs).__new__(mcs, name, parents, attrs)
class TestAllPagesMeta(type): @classmethod def _add_test_methods(mcs, attrs, urlpatterns): pass def __new__(mcs, name, parents, attrs): pass
4
0
30
4
26
1
7
0.04
1
2
0
0
1
0
2
15
63
8
53
11
49
2
29
10
26
11
2
3
13
142,119
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/integration.py
karaage.tests.integration.IntegrationTestCase
class IntegrationTestCase(TestCase): LDAP_CONFIG = { "DESCRIPTION": "LDAP datastore", "ENGINE": "karaage.datastores.ldap.AccountDataStore", "LDAP": "default", "PRIMARY_GROUP": "institute", "DEFAULT_PRIMARY_GROUP": "dummy", "NUMBER_SCHEME": "default", "LDAP_ACCOUNT_BASE": os.environ["LDAP_ACCOUNT_BASE"], "LDAP_GROUP_BASE": os.environ["LDAP_GROUP_BASE"], "HOME_DIRECTORY_FORMAT": "/vpac/{default_project}/{uid}", "GECOS_FORMAT": "{cn} ({o})", } def setUp(self): super(IntegrationTestCase, self).setUp() tldap.transaction.enter_transaction_management() self.addCleanup(self.cleanup) if os.environ["LDAP_TYPE"] == "openldap": config = { **self.LDAP_CONFIG, "ACCOUNT": "karaage.datastores.ldap_schemas.OpenldapAccount", "GROUP": "karaage.datastores.ldap_schemas.OpenldapGroup", } elif os.environ["LDAP_TYPE"] == "ds389": config = { **self.LDAP_CONFIG, "ACCOUNT": "karaage.datastores.ldap_schemas.Ds389Account", "GROUP": "karaage.datastores.ldap_schemas.Ds389Group", } else: raise RuntimeError(f"Unknown databasebase type {os.environ['LDAP_TYPE']}.") self._ldap_datastore = DataStore(config) database = self._ldap_datastore._database account = self._ldap_datastore._account_class( { "uid": "kgtestuser3", "givenName": "Test", "sn": "User3", "cn": "Test User3", "gidNumber": 500, "o": "Example", } ) tldap.database.insert(account, database=database) group = self._ldap_datastore._group_class( { "cn": "Example", "gidNumber": 500, } ) tldap.database.insert(group, database=database) group = self._ldap_datastore._group_class( { "cn": "otherinst", "gidNumber": 501, } ) tldap.database.insert(group, database=database) group = self._ldap_datastore._group_class( { "cn": "TestProject1", "memberUid": ["kgtestuser3"], "gidNumber": 504, } ) tldap.database.insert(group, database=database) _DATASTORES.clear() _DATASTORES.append(self._ldap_datastore) def cleanup(self): tldap.transaction.rollback() tldap.transaction.leave_transaction_management() reset() _DATASTORES.clear()
class IntegrationTestCase(TestCase): def setUp(self): pass def cleanup(self): pass
3
0
35
5
30
0
2
0
1
3
1
3
2
1
2
2
85
12
73
9
70
0
27
9
24
3
1
1
4
142,120
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/machines/test_forms.py
karaage.tests.machines.test_forms.AdminAccountFormTestCase
class AdminAccountFormTestCase(TestCase): def setUp(self): super(AdminAccountFormTestCase, self).setUp() self.account = simple_account() def _valid_form_data(self): text = six.text_type data = { "username": self.account.username, "default_project": text(self.account.default_project.id), "shell": settings.DEFAULT_SHELL, } return data def test_valid_data(self): form_data = self._valid_form_data() form_data["username"] = "test-account" form = AdminAccountForm(person=self.account.person, data=form_data, instance=self.account) self.assertEqual(form.is_valid(), True, form.errors.items()) form.save() self.assertEqual(self.account.username, "test-account") def test_invalid_usernamen(self): form_data = self._valid_form_data() form_data["username"] = "!test-account" form = AdminAccountForm(person=self.account.person, data=form_data, instance=self.account) self.assertEqual(form.is_valid(), False) self.assertEqual( form.errors.items(), dict.items({"username": [six.u("Usernames can only contain letters, numbers and underscores")]}), ) def test_upper_username(self): form_data = self._valid_form_data() form_data["username"] = "INVALID" form = AdminAccountForm(person=self.account.person, data=form_data, instance=self.account) self.assertEqual(form.is_valid(), False) self.assertEqual(form.errors.items(), dict.items({"username": [six.u("Username must be all lowercase")]})) def test_long_username(self): form_data = self._valid_form_data() form_data["username"] = "long" * 100 form = AdminAccountForm(person=self.account.person, data=form_data, instance=self.account) self.assertEqual(form.is_valid(), False) self.assertEqual( form.errors.items(), dict.items({"username": [six.u("Ensure this value has at most 255 characters (it has 400).")]}), )
class AdminAccountFormTestCase(TestCase): def setUp(self): pass def _valid_form_data(self): pass def test_valid_data(self): pass def test_invalid_usernamen(self): pass def test_upper_username(self): pass def test_long_username(self): pass
7
0
7
0
7
0
1
0
1
3
1
0
6
1
6
6
48
5
43
18
36
0
33
18
26
1
1
0
6
142,121
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/machines/test_views.py
karaage.tests.machines.test_views.AccountTestCase
class AccountTestCase(TestCase): def setUp(self): def cleanup(): reset() self.addCleanup(cleanup) call_command("loaddata", "test_karaage", **{"verbosity": 0}) form_data = { "title": "Mr", "short_name": "Sam", "full_name": "Sam Morrison2", "position": "Sys Admin", "institute": 1, "department": "eddf", "email": "sam2@vpac.org", "country": "AU", "telephone": "4444444", "username": "samtest2", "password1": "Exaiquouxei0", "password2": "Exaiquouxei0", "needs_account": False, } self.client.login(username="kgsuper", password="aq12ws") response = self.client.post(reverse("kg_person_add"), form_data) self.assertEqual(response.status_code, 302) person = Person.objects.get(username="kgsuper") self.assertEqual(person.short_name, "Super") self.assertEqual(person.full_name, "Super User") def test_add_account(self): project = Project.objects.get(pk=1) person = Person.objects.get(username="samtest2") person.groups.add(project.group) response = self.client.get(reverse("kg_account_add", args=["samtest2"])) self.assertEqual(response.status_code, 200) form_data = { "username": person.username, "shell": "/bin/bash", "default_project": 1, } response = self.client.post(reverse("kg_account_add", args=["samtest2"]), form_data) self.assertEqual(response.status_code, 302) person = Person.objects.get(username="samtest2") self.assertTrue(person.has_account()) def test_fail_add_accounts_username(self): project = Project.objects.get(pk=1) person = Person.objects.get(username="samtest2") person.groups.add(project.group) form_data = { "username": person.username, "shell": "/bin/bash", "default_project": 1, } response = self.client.post(reverse("kg_account_add", args=["samtest2"]), form_data) self.assertEqual(response.status_code, 302) response = self.client.post(reverse("kg_account_add", args=["samtest2"]), form_data) self.assertContains(response, "Username already in use.") def test_fail_add_accounts_project(self): form_data = { "username": "samtest2", "shell": "/bin/bash", "default_project": 1, } response = self.client.post(reverse("kg_account_add", args=["samtest2"]), form_data) self.assertContains(response, "Person does not belong to default project") project = Project.objects.get(pk=1) person = Person.objects.get(username="samtest2") person.groups.add(project.group) form_data = { "username": person.username, "shell": "/bin/bash", "default_project": 1, } response = self.client.post(reverse("kg_account_add", args=["samtest2"]), form_data) self.assertEqual(response.status_code, 302) form_data = { "username": person.username, "shell": "/bin/bash", "default_project": 1, } response = self.client.post(reverse("kg_account_add", args=["samtest2"]), form_data) self.assertContains(response, "Username already in use.") def test_lock_unlock_account(self): project = Project.objects.get(pk=1) person = Person.objects.get(username="samtest2") person.groups.add(project.group) response = self.client.get(reverse("kg_account_add", args=["samtest2"])) self.assertEqual(response.status_code, 200) form_data = { "username": person.username, "shell": "/bin/bash", "default_project": 1, } response = self.client.post(reverse("kg_account_add", args=["samtest2"]), form_data) self.assertEqual(response.status_code, 302) person = Person.objects.get(username="samtest2") ua = person.get_account() self.assertEqual(person.is_locked(), False) self.assertEqual(ua.login_shell(), "/bin/bash") response = self.client.post(reverse("kg_person_lock", args=["samtest2"])) person = Person.objects.get(username="samtest2") ua = person.get_account() self.assertEqual(person.is_locked(), True) self.assertEqual(ua.login_shell(), "/bin/bash") response = self.client.post(reverse("kg_person_unlock", args=["samtest2"])) person = Person.objects.get(username="samtest2") ua = person.get_account() self.assertEqual(person.is_locked(), False) self.assertEqual(ua.login_shell(), "/bin/bash")
class AccountTestCase(TestCase): def setUp(self): pass def cleanup(): pass def test_add_account(self): pass def test_fail_add_accounts_username(self): pass def test_fail_add_accounts_project(self): pass def test_lock_unlock_account(self): pass
7
0
21
3
18
0
1
0
1
2
2
0
5
0
5
5
128
21
107
27
100
0
69
27
62
1
1
0
6
142,122
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/people/test_models.py
karaage.tests.people.test_models.GroupTestCase
class GroupTestCase(TestCase): def test_minimum_create(self): group = Group.objects.create(foreign_id="1111", name="test_group") group.full_clean()
class GroupTestCase(TestCase): def test_minimum_create(self): pass
2
0
3
0
3
0
1
0
1
1
1
0
1
0
1
1
4
0
4
3
2
0
4
3
2
1
1
0
1
142,123
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/projects/test_forms.py
karaage.tests.projects.test_forms.ProjectFormTestCase
class ProjectFormTestCase(TestCase): def setUp(self): super(ProjectFormTestCase, self).setUp() self.project = ProjectFactory() def _valid_form_data(self): data = { "pid": self.project.pid, "name": self.project.name, "description": self.project.description, "institute": self.project.institute.id, "additional_req": self.project.additional_req, "start_date": self.project.start_date, "end_date": self.project.end_date, } return data def test_valid_data(self): form_data = self._valid_form_data() form_data["name"] = "test-project" form = ProjectForm(data=form_data, instance=self.project) self.assertEqual(form.is_valid(), True, form.errors.items()) form.save() self.assertEqual(self.project.name, "test-project") def test_invalid_pid(self): form_data = self._valid_form_data() form_data["pid"] = "!test-project" form = ProjectForm(data=form_data) self.assertEqual(form.is_valid(), False) self.assertEqual( form.errors.items(), dict.items( { "leaders": [six.u("This field is required.")], "pid": [six.u("Project names can only contain letters, numbers and underscores")], } ), )
class ProjectFormTestCase(TestCase): def setUp(self): pass def _valid_form_data(self): pass def test_valid_data(self): pass def test_invalid_pid(self): pass
5
0
9
0
9
0
1
0
1
4
2
0
4
1
4
4
39
3
36
11
31
0
20
11
15
1
1
0
4
142,124
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/projects/test_projects.py
karaage.tests.projects.test_projects.ProjectTestCase
class ProjectTestCase(IntegrationTestCase): def setUp(self): super(ProjectTestCase, self).setUp() call_command("loaddata", "test_karaage", **{"verbosity": 0}) def test_admin_add_project(self): Project.objects.count() self.client.login(username="kgsuper", password="aq12ws") response = self.client.get(reverse("kg_project_add")) self.assertEqual(response.status_code, 200) form_data = { "name": "Test Project 4", "description": "Test", "institute": 1, "leaders": "|2|3|", "start_date": datetime.date.today(), } response = self.client.post(reverse("kg_project_add"), form_data) self.assertEqual(response.status_code, 302) project = Project.objects.get(name="Test Project 4") self.assertEqual(project.is_active, True) self.assertEqual(project.date_approved, datetime.date.today()) self.assertEqual(project.approved_by, Person.objects.get(username="kgsuper")) self.assertEqual(project.pid, "pEx0001") self.assertTrue(Person.objects.get(pk=2) in project.leaders.all()) self.assertTrue(Person.objects.get(pk=3) in project.leaders.all()) lgroup = self._ldap_datastore._get_group(cn=project.pid) self.assertEqual(lgroup["cn"], [project.pid]) def test_admin_add_project_pid(self): Project.objects.count() self.client.login(username="kgsuper", password="aq12ws") response = self.client.get(reverse("kg_project_add")) self.assertEqual(response.status_code, 200) form_data = { "pid": "Enrico", "name": "Test Project 4", "description": "Test", "institute": 1, "leaders": "|2|3|", "start_date": datetime.date.today(), } response = self.client.post(reverse("kg_project_add"), form_data) self.assertEqual(response.status_code, 302) project = Project.objects.get(pid="Enrico") self.assertEqual(project.is_active, True) self.assertEqual(project.date_approved, datetime.date.today()) self.assertEqual(project.approved_by, Person.objects.get(username="kgsuper")) self.assertEqual(project.pid, "Enrico") self.assertTrue(Person.objects.get(pk=2) in project.leaders.all()) self.assertTrue(Person.objects.get(pk=3) in project.leaders.all()) lgroup = self._ldap_datastore._get_group(cn=project.pid) self.assertEqual(lgroup["cn"], [project.pid]) def test_add_remove_user_to_project(self): self.assertRaises(ObjectDoesNotExist, self._ldap_datastore._get_account, uid="kgtestuser2") # login self.client.login(username="kgsuper", password="aq12ws") # get project details project = Project.objects.get(pid="TestProject1") self.assertEqual(project.group.members.count(), 1) response = self.client.get(reverse("kg_project_detail", args=[project.id])) self.assertEqual(response.status_code, 200) self.assertRaises(ObjectDoesNotExist, self._ldap_datastore._get_account, uid="kgtestuser2") # add kgtestuser2 to project new_user = Person.objects.get(username="kgtestuser2") response = self.client.post(reverse("kg_project_detail", args=[project.id]), {"person": new_user.id}) self.assertEqual(response.status_code, 302) project = Project.objects.get(pid="TestProject1") self.assertEqual(project.group.members.count(), 2) account = self._ldap_datastore._get_account(uid="kgtestuser2") groups = account["groups"].load(self._ldap_datastore._database) assert len(groups) == 1 assert groups[0]["cn"] == ["TestProject1"] # remove user for account in new_user.account_set.all(): account.default_project = None account.save() response = self.client.post(reverse("kg_remove_project_member", args=[project.id, new_user.username])) self.assertEqual(response.status_code, 302) project = Project.objects.get(pid="TestProject1") self.assertEqual(project.group.members.count(), 1) lgroup = self._ldap_datastore._get_group(cn=project.pid) assert "kgtestuser2" not in lgroup["memberUid"] def test_delete_project(self): self.client.login(username="kgsuper", password="aq12ws") project = Project.objects.get(pid="TestProject1") for account in Account.objects.filter(default_project=project): account.default_project = None account.save() self.assertEqual(project.is_active, True) response = self.client.post(reverse("kg_project_delete", args=[project.id])) self.assertEqual(response.status_code, 302) project = Project.objects.get(pid="TestProject1") self.assertEqual(project.is_active, False) self.assertEqual(project.group.members.count(), 0) self.assertEqual(project.date_deleted, datetime.date.today()) self.assertEqual(project.deleted_by, Person.objects.get(username="kgsuper")) def test_change_default(self): pass def test_admin_edit_project(self): project = Project.objects.get(pid="TestProject1") self.assertEqual(project.is_active, True) self.assertEqual(project.name, "Test Project 1") self.assertTrue(Person.objects.get(pk=1) in project.leaders.all()) self.assertFalse(Person.objects.get(pk=2) in project.leaders.all()) self.assertFalse(Person.objects.get(pk=3) in project.leaders.all()) self.assertTrue(Person.objects.get(pk=3) in project.group.members.all()) self.client.login(username="kgsuper", password="aq12ws") response = self.client.get(reverse("kg_project_edit", args=[project.id])) self.assertEqual(response.status_code, 200) form_data = { "name": "Test Project 1 was 4", "description": "Test", "institute": 1, "leaders": "|2|3|", "start_date": project.start_date, } response = self.client.post(reverse("kg_project_edit", args=[project.id]), form_data) self.assertEqual(response.status_code, 302) project = Project.objects.get(pid="TestProject1") self.assertEqual(project.is_active, True) # this is not changed because we don't support editing leaders with # this interface any more self.assertTrue(Person.objects.get(pk=1) in project.leaders.all()) self.assertFalse(Person.objects.get(pk=2) in project.leaders.all()) self.assertFalse(Person.objects.get(pk=3) in project.leaders.all()) lgroup = self._ldap_datastore._get_group(cn=project.pid) self.assertEqual(lgroup["cn"], [project.pid]) def test_user_add_project(self): pass def test_user_edit_project(self): pass def test_change_group(self): group, _ = Group.objects.get_or_create(name="example") project = Project.objects.get(pid="TestProject1") project.group = group project.save()
class ProjectTestCase(IntegrationTestCase): def setUp(self): pass def test_admin_add_project(self): pass def test_admin_add_project_pid(self): pass def test_add_remove_user_to_project(self): pass def test_delete_project(self): pass def test_change_default(self): pass def test_admin_edit_project(self): pass def test_user_add_project(self): pass def test_user_edit_project(self): pass def test_change_group(self): pass
11
0
16
2
13
1
1
0.05
1
6
4
0
10
0
10
12
167
32
129
34
118
6
110
34
99
2
2
1
12
142,125
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/test_all_pages.py
karaage.tests.test_all_pages.TestKaraagePages
class TestKaraagePages(TestAllPagesCase): """Discover all URLs, do a HTTP GET and confirm 200 OK and no DB changes.""" fixtures = ["test_karaage.json"] variables = { "username": "kgsuper", "group_name": "example", "account_id": "1", "project_id": "1", "projectquota_id": "1", "institute_id": "1", "institutequota_id": "1", "machine_id": "1", "category_id": "1", } module = "karaage" module_exclude = "karaage.plugins"
class TestKaraagePages(TestAllPagesCase): '''Discover all URLs, do a HTTP GET and confirm 200 OK and no DB changes.''' pass
1
1
0
0
0
0
0
0.13
1
0
0
0
0
0
0
1
18
1
15
5
14
2
5
5
4
0
2
0
0
142,126
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/test_commands.py
karaage.tests.test_commands.CommandsTestCase
class CommandsTestCase(TestCase): def test_daily_cleanup(self): callback = Mock() daily_cleanup.connect(callback) try: call_command("daily_cleanup") finally: daily_cleanup.disconnect(daily_cleanup) self.assertEqual(callback.call_count, 1)
class CommandsTestCase(TestCase): def test_daily_cleanup(self): pass
2
0
10
2
8
0
1
0
1
0
0
0
1
0
1
1
11
2
9
3
7
0
8
3
6
1
1
1
1
142,127
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/test_people.py
karaage.tests.test_people.FakeRequest
class FakeRequest(object): def __init__(self, person): self.user = person
class FakeRequest(object): def __init__(self, person): pass
2
0
2
0
2
0
1
0
1
0
0
0
1
1
1
1
3
0
3
3
1
0
3
3
1
1
1
0
1
142,128
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/test_people.py
karaage.tests.test_people.PersonTestCase
class PersonTestCase(IntegrationTestCase): fixtures = [ "test_karaage.json", ] def test_login(self): if django.VERSION >= (1, 9): url_prefix = "" else: url_prefix = "http://testserver" form_data = { "username": "kgsuper", "password": "aq12ws", } response = self.client.post(reverse("kg_profile_login"), form_data, follow=True) self.assertEqual(response.status_code, 200) self.assertEqual(response.redirect_chain[0][0], url_prefix + reverse("index")) user = auth.get_user(self.client) assert user.is_authenticated assert user.username == "kgsuper" def test_logout(self): if django.VERSION >= (1, 9): url_prefix = "" else: url_prefix = "http://testserver" response = self.client.post(reverse("kg_profile_logout"), follow=True) self.assertEqual(response.status_code, 200) self.assertEqual(response.redirect_chain[0][0], url_prefix + reverse("index")) user = auth.get_user(self.client) assert not user.is_authenticated def do_permission_tests(self, test_object, users): for user_id in users: # print("can user '%d' access '%s'?"%(user_id, test_object)) person = Person.objects.get(id=user_id) request = FakeRequest(person) result = test_object.can_view(request) expected_result = users[user_id] # print("---> got:'%s' expected:'%s'"%(result, expected_result)) self.assertEqual( result, expected_result, "%r.can_view(%r) returned %r but we expected %r" % (test_object, person, result, expected_result), ) # print() def test_permissions(self): test_object = Project.objects.get(pid="TestProject1") self.do_permission_tests( test_object, { 1: True, # person 1 can view: person's institute delegate, # project leader 2: False, # person 2 cannot view 3: True, # person 3 can view: project member 4: True, # person 4 can view: is_staff }, ) test_object = Person.objects.get(id=1) self.do_permission_tests( test_object, { 1: True, # person 1 can view: self, project member, # person's institute delegate 2: False, # person 2 cannot view 3: False, # person 3 cannot view 4: True, # person 4 can view: is_staff, institute delegate }, ) test_object = Person.objects.get(id=2) self.do_permission_tests( test_object, { 1: True, # person 1 can view: person's institute delegate 2: True, # person 2 can view: self 3: False, # person 3 cannot view 4: True, # person 4 can view: is_staff }, ) test_object = Person.objects.get(id=3) self.do_permission_tests( test_object, { 1: True, # person 1 can view: person's institute delegate, # project leader 2: False, # person 2 cannot view 3: True, # person 3 can view: self, project member 4: True, # person 4 can view: is_staff }, ) test_object = Person.objects.get(id=4) self.do_permission_tests( test_object, { 1: True, # person 1 can view: person's institute delegate 2: False, # person 2 cannot view 3: False, # person 3 cannot view 4: True, # person 4 can view: self, is_staff }, ) # add user 2 to project # test that members can see other people in own project # print("------------------------------------------------------------") project = Project.objects.get(pid="TestProject1") project.group.members.set([2, 3]) test_object = Project.objects.get(pid="TestProject1") self.do_permission_tests( test_object, { 1: True, # person 1 can view: person's institute delegate 2: True, # person 2 can view: project member 3: True, # person 3 can view: project member 4: True, # person 4 can view: is_staff }, ) test_object = Person.objects.get(id=1) self.do_permission_tests( test_object, { 1: True, # person 1 can view: self, project member, # delegate of institute 2: False, # person 2 cannot view 3: False, # person 3 cannot view 4: True, # person 4 can view: is_staff }, ) test_object = Person.objects.get(id=2) self.do_permission_tests( test_object, { 1: True, # person 1 can view: person's institute delegate, # project leader 2: True, # person 2 can view: self 3: True, # person 3 can view: project member 4: True, # person 4 can view: is_staff }, ) test_object = Person.objects.get(id=3) self.do_permission_tests( test_object, { 1: True, # person 1 can view: person's institute delegate, # project leader 2: True, # person 2 can view: project member 3: True, # person 3 can view: self, project member 4: True, # person 4 can view: is_staff }, ) test_object = Person.objects.get(id=4) self.do_permission_tests( test_object, { 1: True, # person 1 can view: person's institute delegate 2: False, # person 2 cannot view 3: False, # person 3 cannot view 4: True, # person 4 can view: self, is_staff }, ) # change institute of all people # Test institute leader can access people in project despite not being # institute leader for these people. # print("------------------------------------------------------------") Person.objects.all().update(institute=2) # Institute.objects.filter(pk=2).update(delegate=2,active_delegate=2) InstituteDelegate.objects.get_or_create( institute=Institute.objects.get(id=2), person=Person.objects.get(id=2), defaults={"send_email": False} ) project = Project.objects.get(pid="TestProject1") project.leaders.set([2]) test_object = Project.objects.get(pid="TestProject1") self.do_permission_tests( test_object, { 1: True, # person 1 can view: person's institute delegate 2: True, # person 2 can view: project member, person's # institute delegate, project leader 3: True, # person 3 can view: project member 4: True, # person 4 can view: is_staff }, ) test_object = Person.objects.get(id=1) self.do_permission_tests( test_object, { 1: True, # person 1 can view: self, project member 2: True, # person 2 can view: person's institute delegate 3: False, # person 3 cannot view 4: True, # person 4 can view: is_staff }, ) test_object = Person.objects.get(id=2) self.do_permission_tests( test_object, { 1: True, # person 1 can view: project's institute leader 2: True, # person 2 can view: self, person's institute delegate, # project leader 3: True, # person 3 can view: project member 4: True, # person 4 can view: is_staff }, ) test_object = Person.objects.get(id=3) self.do_permission_tests( test_object, { 1: True, # person 1 can view: project's institute leader 2: True, # person 2 can view: project member, person's institute # delegate, project leader 3: True, # person 3 can view: self, project member 4: True, # person 4 can view: is_staff }, ) test_object = Person.objects.get(id=4) self.do_permission_tests( test_object, { 1: True, # person 1 can view: person's institute delegate 2: True, # person 2 can view: person's institute delegate 3: False, # person 3 cannot view 4: True, # person 4 can view: self, is_staff }, ) def test_admin_create_user_with_account(self): users = Person.objects.count() project = Project.objects.get(pid="TestProject1") p_users = project.group.members.count() logged_in = self.client.login(username="kgsuper", password="aq12ws") self.assertEqual(logged_in, True) response = self.client.get(reverse("kg_person_add")) self.assertEqual(response.status_code, 200) form_data = { "title": "Mr", "short_name": "Sam", "full_name": "Sam Morrison", "position": "Sys Admin", "institute": 1, "department": "eddf", "email": "sam2@vpac.org", "country": "AU", "telephone": "4444444", "username": "samtest", "password1": "Exaiquouxei0", "password2": "Exaiquouxei0", "project": 1, "needs_account": True, } response = self.client.post(reverse("kg_person_add"), form_data) self.assertEqual(response.status_code, 302) self.assertEqual(Person.objects.count(), users + 1) users = users + 1 person = Person.objects.get(username="samtest") self.assertEqual(person.is_active, True) self.assertEqual(person.username, "samtest") self.assertEqual(Account.objects.count(), 2) self.assertEqual(project.group.members.count(), p_users + 1) luser = self._ldap_datastore._get_account(uid="samtest") self.assertEqual(luser["givenName"], ["Sam"]) self.assertEqual(luser["homeDirectory"], ["/vpac/TestProject1/samtest"]) def test_admin_create_user(self): users = Person.objects.count() project = Project.objects.get(pid="TestProject1") project.group.members.count() logged_in = self.client.login(username="kgsuper", password="aq12ws") self.assertEqual(logged_in, True) response = self.client.get(reverse("kg_person_add")) self.assertEqual(response.status_code, 200) form_data = { "title": "Mr", "short_name": "Sam", "full_name": "Sam Morrison2", "position": "Sys Admin", "institute": 1, "department": "eddf", "email": "sam2@vpac.org", "country": "AU", "telephone": "4444444", "username": "samtest2", "password1": "Exaiquouxei0", "password2": "Exaiquouxei0", "needs_account": False, } response = self.client.post(reverse("kg_person_add"), form_data) self.assertEqual(response.status_code, 302) self.assertEqual(Person.objects.count(), users + 1) person = Person.objects.get(username="samtest2") self.assertEqual(person.is_active, True) self.assertEqual(person.username, "samtest2") # Try adding it again - Should fail response = self.client.post(reverse("kg_person_add"), form_data) self.assertEqual(response.status_code, 200) def test_admin_update_person(self): logged_in = self.client.login(username="kgsuper", password="aq12ws") self.assertEqual(logged_in, True) person = Person.objects.get(username="kgtestuser3") self.assertEqual(person.mobile, "") luser = self._ldap_datastore._get_account(uid="kgtestuser3") self.assertEqual(luser["gidNumber"], [500]) self.assertEqual(luser["o"], ["Example"]) self.assertEqual(luser["gecos"], ["Test User3 (Example)"]) response = self.client.get(reverse("kg_person_edit", args=["kgtestuser3"])) self.assertEqual(response.status_code, 200) form_data = { "title": "Mr", "short_name": "Test", "full_name": "Test User3", "position": "Sys Admin", "institute": 2, "department": "eddf", "email": "sam2@vpac.org", "country": "AU", "telephone": "4444444", "mobile": "555666", } response = self.client.post(reverse("kg_person_edit", args=["kgtestuser3"]), form_data) self.assertEqual(response.status_code, 302) person = Person.objects.get(username="kgtestuser3") self.assertEqual(person.mobile, "555666") luser = self._ldap_datastore._get_account(uid="kgtestuser3") self.assertEqual(luser["gidNumber"], [501]) self.assertEqual(luser["o"], ["OtherInst"]) self.assertEqual(luser["gecos"], ["Test User3 (OtherInst)"]) def test_delete_activate_person(self): self.client.login(username="kgsuper", password="aq12ws") person = Person.objects.get(username="kgtestuser3") self.assertEqual(person.is_active, True) self.assertEqual(person.projects.count(), 1) self.assertEqual(person.account_set.count(), 1) self.assertEqual(person.account_set.all()[0].date_deleted, None) luser = self._ldap_datastore._get_account(uid="kgtestuser3") self.assertEqual(luser["givenName"], ["Test"]) response = self.client.get(reverse("kg_person_delete", args=[person.username])) self.assertEqual(response.status_code, 200) # Test deleting response = self.client.post(reverse("kg_person_delete", args=[person.username])) self.assertEqual(response.status_code, 302) person = Person.objects.get(username="kgtestuser3") self.assertEqual(person.is_active, False) self.assertEqual(person.projects.count(), 0) self.assertEqual(person.account_set.count(), 1) self.assertEqual(person.account_set.all()[0].date_deleted, datetime.date.today()) self.assertRaises(ObjectDoesNotExist, self._ldap_datastore._get_account, uid="kgtestuser3") # Test activating response = self.client.post(reverse("kg_person_activate", args=[person.username])) self.assertEqual(response.status_code, 302) person = Person.objects.get(username="kgtestuser3") self.assertEqual(person.is_active, True) def stest_delete_account(self): person = Person.objects.get(pk=Person.objects.count()) ua = person.account_set.all()[0] self.assertEqual(person.is_active, True) self.assertEqual(person.account_set.count(), 1) self.assertEqual(ua.date_deleted, None) response = self.client.post("/%susers/accounts/delete/%i/" % (settings.BASE_URL, ua.id)) self.assertEqual(response.status_code, 302) person = Person.objects.get(pk=Person.objects.count()) ua = person.account_set.all()[0] self.assertEqual(ua.date_deleted, datetime.date.today()) self.assertEqual(person.project_set.count(), 0) def stest_default_projects(self): person = Person.objects.get(pk=Person.objects.count()) ua = person.account_set.all()[0] self.assertEqual(person.project_set.count(), 1) self.assertEqual(person.project_set.all()[0], ua.default_project) project = Project.objects.create( pid="test2", name="test project", leader=person, start_date=datetime.date.today(), institute=Institute.objects.get(name="VPAC"), is_active=True, is_approved=True, ) project.users.add(person) self.assertEqual(person.project_set.count(), 2) # change default response = self.client.post(reverse("kg_account_set_default", args=[ua.id, project.pid])) self.assertEqual(response.status_code, 302) person = Person.objects.get(pk=Person.objects.count()) ua = person.account_set.all()[0] project = Project.objects.get(pid="test2") self.assertEqual(person.project_set.count(), 2) self.assertEqual(project, ua.default_project) def stest_add_user_to_project(self): person = Person.objects.get(pk=Person.objects.count()) assert len(person.account_set.all()) == 1 self.assertEqual(person.project_set.count(), 1) Project.objects.create( pid="test2", name="test project 5", leader=Person.objects.get(username="leader"), start_date=datetime.date.today(), institute=Institute.objects.get(name="VPAC"), is_active=True, is_approved=True, ) response = self.client.post( reverse("kg_person_detail", args=[person.username]), {"project": "test2", "project-add": "true"} ) self.assertEqual(response.status_code, 200) self.assertEqual(person.project_set.count(), 2) def test_password_reset_by_self(self): logged_in = self.client.login(username="kgtestuser1", password="aq12ws") self.assertEqual(logged_in, True) if django.VERSION >= (1, 9): url_prefix = "" else: url_prefix = "http://testserver" # send request url = reverse("kg_profile_reset") done_url = reverse("kg_profile_reset_done") response = self.client.post(url, follow=True) self.assertEqual(response.status_code, 200) self.assertEqual(response.redirect_chain[0][0], url_prefix + done_url) # check email self.assertEqual(len(mail.outbox), 1) message = mail.outbox[0] self.assertEqual(message.subject, "TestOrg Password change") url = re.search(r"(?P<url>https?://[^\s]+)", message.body).group("url") self.assertTrue(url.startswith("https://example.com/users/persons/reset/")) url = url[25:] # get password reset page response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) # send new password url = "/persons/reset/MQ/set-password/" form_data = { "new_password1": "VQA#y!xD=BpI<sM69`RW:%", "new_password2": "VQA#y!xD=BpI<sM69`RW:%", } done_url = "/persons/reset/done/" response = self.client.post(url, form_data, follow=True) self.assertEqual(response.status_code, 200) self.assertEqual(response.redirect_chain[0][0], url_prefix + done_url) # test new password logged_in = self.client.login(username="kgtestuser1", password="VQA#y!xD=BpI<sM69`RW:%") self.assertEqual(logged_in, True) def test_password_reset_by_admin(self): logged_in = self.client.login(username="kgsuper", password="aq12ws") self.assertEqual(logged_in, True) if django.VERSION >= (1, 9): url_prefix = "" else: url_prefix = "http://testserver" # send request url = reverse("kg_person_reset", args=["kgtestuser1"]) done_url = reverse("kg_person_reset_done", args=["kgtestuser1"]) response = self.client.post(url, follow=True) self.assertEqual(response.status_code, 200) self.assertEqual(response.redirect_chain[0][0], url_prefix + done_url) self.client.logout() # check email self.assertEqual(len(mail.outbox), 1) message = mail.outbox[0] self.assertEqual(message.subject, "TestOrg Password change") url = re.search(r"(?P<url>https?://[^\s]+)", message.body).group("url") self.assertTrue(url.startswith("https://example.com/users/persons/reset/")) url = url[25:] # get password reset page response = self.client.get(url, follow=True) self.assertEqual(response.status_code, 200) # send new password url = "/persons/reset/MQ/set-password/" form_data = { "new_password1": "VQA#y!xD=BpI<sM69`RW:%", "new_password2": "VQA#y!xD=BpI<sM69`RW:%", } done_url = "/persons/reset/done/" response = self.client.post(url, form_data, follow=True) self.assertEqual(response.status_code, 200) self.assertEqual(response.redirect_chain[0][0], url_prefix + done_url) # test new password logged_in = self.client.login(username="kgtestuser1", password="VQA#y!xD=BpI<sM69`RW:%") self.assertEqual(logged_in, True)
class PersonTestCase(IntegrationTestCase): def test_login(self): pass def test_logout(self): pass def do_permission_tests(self, test_object, users): pass def test_permissions(self): pass def test_admin_create_user_with_account(self): pass def test_admin_create_user_with_account(self): pass def test_admin_update_person(self): pass def test_delete_activate_person(self): pass def stest_delete_account(self): pass def stest_default_projects(self): pass def stest_add_user_to_project(self): pass def test_password_reset_by_self(self): pass def test_password_reset_by_admin(self): pass
14
0
40
4
33
8
1
0.23
1
7
6
0
13
0
13
15
539
69
436
74
422
100
237
74
223
2
2
1
18
142,129
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/unit.py
karaage.tests.unit.UnitTestCase
class UnitTestCase(TestCase): def setUp(self): super(TestCase, self).setUp() self.resetDatastore() def cleanup(): _DATASTORES.clear() reset() self.addCleanup(cleanup) def resetDatastore(self): self.datastore = Mock() _DATASTORES.clear() _DATASTORES.append(self.datastore)
class UnitTestCase(TestCase): def setUp(self): pass def cleanup(): pass def resetDatastore(self): pass
4
0
5
1
5
0
1
0
1
1
0
2
2
1
2
2
15
3
12
5
8
0
12
5
8
1
1
0
3
142,130
Karaage-Cluster/karaage
Karaage-Cluster_karaage/karaage/tests/common/test_forms.py
karaage.tests.common.test_forms.FormsTestCase
class FormsTestCase(TestCase): def test_validate_password(self): username = "somebody" good_password = "ephiikee0eef2Gae" bad_password = "test" old_password = "JaicaeyaivahD9ph" # Long enough. res = forms.validate_password(username, good_password) self.assertEqual(res, good_password) # Passwords match. res = forms.validate_password(username, good_password, good_password) self.assertEqual(res, good_password) # New password is different to old password. res = forms.validate_password(username, good_password, old_password=old_password) self.assertEqual(res, good_password) # New password is different to old password, passwords match. res = forms.validate_password(username, good_password, good_password, old_password=old_password) self.assertEqual(res, good_password) assert_raises = self.assertRaises(django_forms.ValidationError) # Too short. with assert_raises: forms.validate_password(username, bad_password) # password contains username with assert_raises: forms.validate_password(username, "2222" + username + "1111") # Passwords don't match. with assert_raises: forms.validate_password(username, good_password, good_password + "diff") # New password is the same as old password. with assert_raises: forms.validate_password(username, good_password, old_password=good_password) # Second password isn't blank. with assert_raises: forms.validate_password(username, good_password, "")
class FormsTestCase(TestCase): def test_validate_password(self): pass
2
0
44
11
24
9
1
0.36
1
0
0
0
1
0
1
1
45
11
25
8
23
9
25
8
23
1
1
1
1
142,131
Karaage-Cluster/python-tldap
tests/a_unit/test_database.py
tests.a_unit.test_database.TestModelGroup
class TestModelGroup: def test_set_primary_group( self, mock_ldap, account1, group2): """ Test setting primary group for account. """ c = mock_ldap # Add person to group. changes = tldap.database.changeset(account1, {'primary_group': group2}) tldap.database.save(changes) # Assert that we made the correct calls to the backend. expected_calls = [ mock.call.modify( 'uid=tux,ou=People,dc=python-ldap,dc=org', {'gidNumber': [('MODIFY_REPLACE', [b'11'])]}, ) ] c.assert_has_calls(expected_calls) def test_get_primary_group( self, mock_ldap, account1, group1): """ Test getting primary group for account. """ c = mock_ldap c.search = SearchMock() c.search.add_result(b"gidNumber=10", group1) # Get the primary group account1 = tldap.database.preload(account1) group = account1.get_as_single('primary_group') for key in ["cn", "description", "gidNumber", "memberUid"]: assert group[key] == group1[key] def test_add_secondary_group( self, mock_ldap, account1, group1): """ Test adding existing secondary group to account. """ c = mock_ldap c.search = SearchMock() # Add person to group. changes = tldap.database.changeset(group1, {}) changes = tests.database.Group.add_member(changes, account1) tldap.database.save(changes) # Assert that we made the correct calls to the backend. expected_calls = [ mock.call.modify( 'cn=group1,ou=Group,dc=python-ldap,dc=org', {'memberUid': [('MODIFY_ADD', [b'tux'])]}, ) ] c.assert_has_calls(expected_calls) def test_remove_secondary_group( self, mock_ldap, account1, group2): """ Test removing secondary group from account. """ c = mock_ldap c.search = SearchMock() # Add person to group. changes = tldap.database.changeset(group2, {}) changes = tests.database.Group.remove_member(changes, account1) tldap.database.save(changes) # Assert that we made the correct calls to the backend. expected_calls = [ mock.call.modify( 'cn=group2,ou=Group,dc=python-ldap,dc=org', {'memberUid': [('MODIFY_DELETE', [b'tux'])]}, ) ] c.assert_has_calls(expected_calls) def test_get_secondary_group_none( self, mock_ldap, account1): """ Test getting secondary group when none set. """ c = mock_ldap c.search = SearchMock() # Don't try to preload primary group, it will fail. account1 = account1.set('primary_group', None) # Get the secondary groups. account1 = tldap.database.preload(account1) # Test result groups = account1['groups'] assert groups == [] def test_get_secondary_group_set( self, mock_ldap, account1, group2): """ Test getting secondary group when one set. """ c = mock_ldap c.search = SearchMock() c.search.add_result(b"memberUid=tux", group2) # Don't try to preload primary group, it will fail. account1 = account1.set('primary_group', None) # Get the secondary groups. account1 = tldap.database.preload(account1) # Test result groups = account1['groups'] assert len(groups) == 1 group = groups[0] for key in ["cn", "description", "gidNumber"]: assert group[key] == group2[key], key
class TestModelGroup: def test_set_primary_group( self, mock_ldap, account1, group2): ''' Test setting primary group for account. ''' pass def test_get_primary_group( self, mock_ldap, account1, group1): ''' Test getting primary group for account. ''' pass def test_add_secondary_group( self, mock_ldap, account1, group1): ''' Test adding existing secondary group to account. ''' pass def test_remove_secondary_group( self, mock_ldap, account1, group2): ''' Test removing secondary group from account. ''' pass def test_get_secondary_group_none( self, mock_ldap, account1): ''' Test getting secondary group when none set. ''' pass def test_get_secondary_group_set( self, mock_ldap, account1, group2): ''' Test getting secondary group when one set. ''' pass
7
6
17
3
12
3
1
0.27
0
2
2
0
6
0
6
6
110
21
70
31
57
19
49
25
42
2
0
1
8
142,132
Karaage-Cluster/python-tldap
tldap/dict.py
tldap.dict.ImmutableDict
class ImmutableDict: """ Immutable dictionary that cannot be changed without creating a new instance. """ def __init__(self, allowed_keys: Optional[Set[str]] = None, d: Optional[dict] = None) -> None: self._allowed_keys = allowed_keys self._dict = CaseInsensitiveDict(allowed_keys) if d is not None: for key, value in d.items(): self._set(key, value) def fix_key(self, key: str) -> str: return self._dict.fix_key(key) def __getitem__(self, key: str): return self._dict.__getitem__(key) def get(self, key: str, default: any = None): key = self.fix_key(key) try: return self._dict.get(key, default) except KeyError: return default def __contains__(self, key: str): return self._dict.__contains__(key) def keys(self) -> KeysView[str]: return self._dict.keys() def items(self) -> ItemsView[str, any]: return self._dict.items() def __copy__(self: ImmutableDictEntity) -> ImmutableDictEntity: return self.__class__(self._allowed_keys, self._dict) def _set(self, key: str, value: any) -> None: self._dict[key] = value def merge(self: ImmutableDictEntity, d: dict) -> ImmutableDictEntity: clone = self.__copy__() for key, value in d.items(): clone._set(key, value) return clone def set(self: ImmutableDictEntity, key: str, value: any) -> ImmutableDictEntity: clone = self.__copy__() clone._set(key, value) return clone def to_dict(self) -> dict: return self._dict.to_dict()
class ImmutableDict: ''' Immutable dictionary that cannot be changed without creating a new instance. ''' def __init__(self, allowed_keys: Optional[Set[str]] = None, d: Optional[dict] = None) -> None: pass def fix_key(self, key: str) -> str: pass def __getitem__(self, key: str): pass def get(self, key: str, default: any = None): pass def __contains__(self, key: str): pass def keys(self) -> KeysView[str]: pass def items(self) -> ItemsView[str, any]: pass def __copy__(self: ImmutableDictEntity) -> ImmutableDictEntity: pass def _set(self, key: str, value: any) -> None: pass def merge(self: ImmutableDictEntity, d: dict) -> ImmutableDictEntity: pass def set(self: ImmutableDictEntity, key: str, value: any) -> ImmutableDictEntity: pass def to_dict(self) -> dict: pass
13
1
3
0
3
0
1
0.08
0
4
1
2
12
2
12
12
52
11
38
19
25
3
38
19
25
3
0
2
16
142,133
Karaage-Cluster/python-tldap
tests/a_unit/test_dict.py
tests.a_unit.test_dict.TestCaseInsensitive
class TestCaseInsensitive: def test_init_lowercase(self): allowed_values = {'NumberOfPenguins', 'NumberOfSharks'} ci = CaseInsensitiveDict(allowed_values, {'numberofpenguins': 10}) assert ci.keys() == {'NumberOfPenguins'} def test_init_mixedcase(self, ci): allowed_values = {'NumberOfPenguins', 'NumberOfSharks'} ci = CaseInsensitiveDict(allowed_values, {'numberOFpenguins': 10}) assert ci.keys() == {'NumberOfPenguins'} def test_init_uppercase(self, ci): allowed_values = {'NumberOfPenguins', 'NumberOfSharks'} ci = CaseInsensitiveDict(allowed_values, {'NUMBEROFPENGUINS': 10}) assert ci.keys() == {'NumberOfPenguins'} def test_init_not_valid(self, ci): allowed_values = {'NumberOfPenguins', 'NumberOfSharks'} with pytest.raises(KeyError): CaseInsensitiveDict(allowed_values, {'numberOFfish': 10}) def test_set_lowercase(self, ci): ci['numberofpenguins'] = 10 assert ci.keys() == {'NumberOfPenguins'} def test_set_mixedcase(self, ci): ci['numberOFpenguins'] = 10 assert ci.keys() == {'NumberOfPenguins'} def test_set_uppercase(self, ci): ci['NUMBEROFPENGUINS'] = 10 assert ci.keys() == {'NumberOfPenguins'} def test_set_not_valid(self, ci): with pytest.raises(KeyError): ci['numberOFfish'] = 10 def test_get(self, ci): ci['numberOFpenguins'] = 10 assert ci['numberofpenguins'] == 10 assert ci['NumberOfPenguins'] == 10 assert ci['NUMBEROFPENGUINS'] == 10 def test_get_not_set(self, ci): ci['numberOFpenguins'] = 10 with pytest.raises(KeyError): assert ci['NumberOfSharks'] == 10 def test_get_valid(self, ci): ci['numberOFpenguins'] = 10 with pytest.raises(KeyError): assert ci['nUmberoFfIsh'] == 10
class TestCaseInsensitive: def test_init_lowercase(self): pass def test_init_mixedcase(self, ci): pass def test_init_uppercase(self, ci): pass def test_init_not_valid(self, ci): pass def test_set_lowercase(self, ci): pass def test_set_mixedcase(self, ci): pass def test_set_uppercase(self, ci): pass def test_set_not_valid(self, ci): pass def test_get(self, ci): pass def test_get_not_set(self, ci): pass def test_get_valid(self, ci): pass
12
0
4
0
4
0
1
0
0
2
1
0
11
0
11
11
54
12
42
17
30
0
42
17
30
1
0
1
11
142,134
Karaage-Cluster/python-tldap
tldap/django/apps.py
tldap.django.apps.TldapConfig
class TldapConfig(AppConfig): name = 'tldap.django' label = 'tldap' verbose_name = "TLDAP Django Support"
class TldapConfig(AppConfig): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
4
0
4
4
3
0
4
4
3
0
1
0
0
142,135
Karaage-Cluster/python-tldap
tests/a_unit/test_database.py
tests.a_unit.test_database.UnorderedList
class UnorderedList(TestObject): """ A helper object that compares two unordered lists.""" def __init__(self, l): self._l = l def __eq__(self, other): t = list(self._l) # make a mutable copy try: for elem in other: t.remove(elem) except ValueError: return False return not t def __repr__(self): return '<unordered_list %s>' % self._l
class UnorderedList(TestObject): ''' A helper object that compares two unordered lists.''' def __init__(self, l): pass def __eq__(self, other): pass def __repr__(self): pass
4
1
4
0
4
0
2
0.15
1
2
0
0
3
1
3
4
17
3
13
7
9
2
13
7
9
3
1
2
5
142,136
Karaage-Cluster/python-tldap
tests/a_unit/test_database.py
tests.a_unit.test_database.TestObject
class TestObject: def __ne__(self, other): return not self.__eq__(other)
class TestObject: def __ne__(self, other): pass
2
0
2
0
2
0
1
0
0
0
0
2
1
0
1
1
3
0
3
2
1
0
3
2
1
1
0
0
1
142,137
Karaage-Cluster/python-tldap
tldap/django/middleware.py
tldap.django.middleware.TransactionMiddleware
class TransactionMiddleware(MiddlewareMixin): """ Transaction middleware. If this is enabled, each view function will be run with commit_on_response activated - that way a save() doesn't do a direct commit, the commit is done when a successful response is created. If an exception happens, the database is rolled back. """ def process_request(self, request): """Enters transaction management""" tldap.transaction.enter_transaction_management() def process_exception(self, request, exception): """Rolls back the database and leaves transaction management""" tldap.transaction.rollback() def process_response(self, request, response): """Commits and leaves transaction management.""" if tldap.transaction.is_managed(): tldap.transaction.commit() tldap.transaction.leave_transaction_management() return response
class TransactionMiddleware(MiddlewareMixin): ''' Transaction middleware. If this is enabled, each view function will be run with commit_on_response activated - that way a save() doesn't do a direct commit, the commit is done when a successful response is created. If an exception happens, the database is rolled back. ''' def process_request(self, request): '''Enters transaction management''' pass def process_exception(self, request, exception): '''Rolls back the database and leaves transaction management''' pass def process_response(self, request, response): '''Commits and leaves transaction management.''' pass
4
4
4
0
3
1
1
0.9
1
0
0
0
3
0
3
3
21
2
10
4
6
9
10
4
6
2
1
1
4
142,138
Karaage-Cluster/python-tldap
tldap/django/migrations/0001_initial.py
tldap.django.migrations.0001_initial.Migration
class Migration(migrations.Migration): dependencies = [ ] operations = [ migrations.CreateModel( name='Counters', fields=[ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), ('scheme', models.CharField(max_length=20, db_index=True)), ('name', models.CharField(max_length=20, db_index=True)), ('count', models.IntegerField()), ], options={ 'db_table': 'tldap_counters', }, bases=(models.Model,), ), ]
class Migration(migrations.Migration): pass
1
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
21
2
19
3
18
0
3
3
2
0
1
0
0
142,139
Karaage-Cluster/python-tldap
tldap/django/models.py
tldap.django.models.Counters
class Counters(models.Model): """ Keep track of next uidNumber and gidNumber to use for new LDAP objects. """ scheme = models.CharField(max_length=20, db_index=True) name = models.CharField(max_length=20, db_index=True) count = models.IntegerField() class Meta: db_table = 'tldap_counters' @classmethod @transaction.atomic def get_and_increment(cls, scheme, name, default, test): entry, c = cls.objects.select_for_update().get_or_create( scheme=scheme, name=name, defaults={'count': default}) while not test(entry.count): entry.count = entry.count + 1 n = entry.count entry.count = entry.count + 1 entry.save() return n
class Counters(models.Model): ''' Keep track of next uidNumber and gidNumber to use for new LDAP objects. ''' class Meta: @classmethod @transaction.atomic def get_and_increment(cls, scheme, name, default, test): pass
5
1
13
4
9
0
2
0.12
1
0
0
0
0
0
1
1
25
6
17
10
12
2
14
9
11
2
1
1
2
142,140
Karaage-Cluster/python-tldap
tldap/exceptions.py
tldap.exceptions.FieldError
class FieldError(Exception): """Some kind of problem with a field.""" pass
class FieldError(Exception): '''Some kind of problem with a field.''' pass
1
1
0
0
0
0
0
0.5
1
0
0
0
0
0
0
10
3
0
2
1
1
1
2
1
1
0
3
0
0
142,141
Karaage-Cluster/python-tldap
tldap/exceptions.py
tldap.exceptions.InvalidDN
class InvalidDN(Exception): """ DN value is invalid and cannot be parsed. """
class InvalidDN(Exception): ''' DN value is invalid and cannot be parsed. ''' pass
1
1
0
0
0
0
0
1
1
0
0
0
0
0
0
10
2
0
1
1
0
1
1
1
0
0
3
0
0
142,142
Karaage-Cluster/python-tldap
tldap/exceptions.py
tldap.exceptions.MultipleObjectsReturned
class MultipleObjectsReturned(Exception): "The query returned multiple objects when only one was expected." pass
class MultipleObjectsReturned(Exception): '''The query returned multiple objects when only one was expected.''' pass
1
1
0
0
0
0
0
0.5
1
0
0
0
0
0
0
10
3
0
2
1
1
1
2
1
1
0
3
0
0
142,143
Karaage-Cluster/python-tldap
tldap/exceptions.py
tldap.exceptions.ObjectAlreadyExists
class ObjectAlreadyExists(Exception): "The requested object already exists" pass
class ObjectAlreadyExists(Exception): '''The requested object already exists''' pass
1
1
0
0
0
0
0
0.5
1
0
0
0
0
0
0
10
3
0
2
1
1
1
2
1
1
0
3
0
0
142,144
Karaage-Cluster/python-tldap
tldap/exceptions.py
tldap.exceptions.ObjectDoesNotExist
class ObjectDoesNotExist(Exception): "The requested object does not exist" pass
class ObjectDoesNotExist(Exception): '''The requested object does not exist''' pass
1
1
0
0
0
0
0
0.5
1
0
0
0
0
0
0
10
3
0
2
1
1
1
2
1
1
0
3
0
0
142,145
Karaage-Cluster/python-tldap
tldap/exceptions.py
tldap.exceptions.RollbackError
class RollbackError(Exception): """An error in rollback and consistency cannot be guaranteed.""" pass
class RollbackError(Exception): '''An error in rollback and consistency cannot be guaranteed.''' pass
1
1
0
0
0
0
0
0.5
1
0
0
0
0
0
0
10
3
0
2
1
1
1
2
1
1
0
3
0
0
142,146
Karaage-Cluster/python-tldap
tldap/exceptions.py
tldap.exceptions.TestFailure
class TestFailure(Exception): """Simulated failure for testing.""" pass
class TestFailure(Exception): '''Simulated failure for testing.''' pass
1
1
0
0
0
0
0
0.5
1
0
0
0
0
0
0
10
3
0
2
1
1
1
2
1
1
0
3
0
0
142,147
Karaage-Cluster/python-tldap
tldap/dict.py
tldap.dict.CaseInsensitiveDict
class CaseInsensitiveDict: """ Case insensitve dictionary for searches however preserves the case for retrieval. Needs to be supplied with a set of allowed keys. """ def __init__(self, allowed_keys: Set[str], d: Optional[dict] = None) -> None: self._lc: Dict[str, str] = { value.lower(): value for value in allowed_keys } self._dict = dict() if d is not None: for k, v in d.items(): self[k] = v def fix_key(self, key: str) -> str: key = key.lower() if key not in self._lc: raise KeyError(key) return self._lc[key.lower()] def __setitem__(self, key: str, value: any): key = self.fix_key(key) self._dict.__setitem__(key, value) def __delitem__(self, key: str): key = self.fix_key(key) del self._lc[key] self._dict.__delitem__(key) def __getitem__(self, key: str): key = self.fix_key(key) return self._dict.__getitem__(key) def __contains__(self, key: str): key = self.fix_key(key) return self._dict.__contains__(key) def get(self, key: str, default: any = None): key = self.fix_key(key) return self._dict.get(key, default) def keys(self) -> KeysView[str]: return self._dict.keys() def items(self) -> ItemsView[str, any]: return self._dict.items() def to_dict(self) -> dict: return self._dict
class CaseInsensitiveDict: ''' Case insensitve dictionary for searches however preserves the case for retrieval. Needs to be supplied with a set of allowed keys. ''' def __init__(self, allowed_keys: Set[str], d: Optional[dict] = None) -> None: pass def fix_key(self, key: str) -> str: pass def __setitem__(self, key: str, value: any): pass def __delitem__(self, key: str): pass def __getitem__(self, key: str): pass def __contains__(self, key: str): pass def get(self, key: str, default: any = None): pass def keys(self) -> KeysView[str]: pass def items(self) -> ItemsView[str, any]: pass def to_dict(self) -> dict: pass
11
1
4
0
4
0
1
0.11
0
3
0
0
10
2
10
10
52
12
36
14
25
4
34
14
23
3
0
2
13