From 47bd9d12dc3d18376ddb8dce7f0321bc7f1c2ac2 Mon Sep 17 00:00:00 2001
From: Guillaume Rousse <guillaume.rousse@renater.fr>
Date: Fri, 8 Dec 2017 15:08:39 +0100
Subject: [PATCH] simplification: rename TestAccount as Account

---
 bin/account-manager.pl.in                         | 10 +++++-----
 conf/create-manager-db.sql                        |  2 +-
 lib/AccountManager/{TestAccount.pm => Account.pm} |  4 ++--
 lib/AccountManager/Account/Manager.pm             | 15 +++++++++++++++
 lib/AccountManager/TestAccount/Manager.pm         | 15 ---------------
 lib/AccountManager/WebRequest.pm                  |  8 ++++----
 lib/Makefile.am                                   |  4 ++--
 7 files changed, 29 insertions(+), 29 deletions(-)
 rename lib/AccountManager/{TestAccount.pm => Account.pm} (98%)
 create mode 100644 lib/AccountManager/Account/Manager.pm
 delete mode 100644 lib/AccountManager/TestAccount/Manager.pm

diff --git a/bin/account-manager.pl.in b/bin/account-manager.pl.in
index 2c2fbee..1414838 100755
--- a/bin/account-manager.pl.in
+++ b/bin/account-manager.pl.in
@@ -19,8 +19,8 @@ use AccountManager::Token;
 use AccountManager::Token::Manager;
 use AccountManager::ServiceProvider;
 use AccountManager::ServiceProvider::Manager;
-use AccountManager::TestAccount;
-use AccountManager::TestAccount::Manager;
+use AccountManager::Account;
+use AccountManager::Account::Manager;
 use AccountManager::SAMLMetadata;
 use AccountManager::Tools;
 
@@ -93,7 +93,7 @@ sub add_account {
         $configuration->{service}->{account_validity_period};
     my $password = AccountManager::Tools::generate_password();
 
-    my $account = AccountManager::TestAccount->new(
+    my $account = AccountManager::Account->new(
         db              => $db,
         profile         => $options{profile},
         sp_entityid     => $options{sp_entityid},
@@ -127,7 +127,7 @@ sub list_accounts {
     }
 
     my $accounts =
-        AccountManager::TestAccount::Manager->get_testaccounts(db => $db, %args);
+        AccountManager::Account::Manager->get_accounts(db => $db, %args);
 
     if (! @$accounts) {
         printf "No matching test account in DB\n";
@@ -143,7 +143,7 @@ sub list_accounts {
         }
         printf "%d accounts removed\n", scalar @$accounts;
 
-        $accounts = AccountManager::TestAccount::Manager->get_testaccounts(
+        $accounts = AccountManager::Account::Manager->get_accounts(
             db => $db
         );
 
diff --git a/conf/create-manager-db.sql b/conf/create-manager-db.sql
index 635cbf2..534ad1e 100644
--- a/conf/create-manager-db.sql
+++ b/conf/create-manager-db.sql
@@ -27,7 +27,7 @@ CREATE TABLE `serviceproviders` (
   UNIQUE KEY `entityid` (`entityid`)
 ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
 
-CREATE TABLE `testaccounts` (
+CREATE TABLE `accounts` (
   `id` bigint(20) NOT NULL AUTO_INCREMENT,
   `password_hash` varchar(50) NOT NULL,
   `creation_date` date DEFAULT NULL,
diff --git a/lib/AccountManager/TestAccount.pm b/lib/AccountManager/Account.pm
similarity index 98%
rename from lib/AccountManager/TestAccount.pm
rename to lib/AccountManager/Account.pm
index f85c6c9..65896b6 100644
--- a/lib/AccountManager/TestAccount.pm
+++ b/lib/AccountManager/Account.pm
@@ -1,4 +1,4 @@
-package AccountManager::TestAccount;
+package AccountManager::Account;
 
 use strict;
 use warnings;
@@ -6,7 +6,7 @@ use warnings;
 use base 'AccountManager::DB::Object';
 
 __PACKAGE__->meta->setup(
-    table   => 'testaccounts',
+    table   => 'accounts',
 
     columns => [
         id              => { type => 'bigserial', not_null => 1 },
diff --git a/lib/AccountManager/Account/Manager.pm b/lib/AccountManager/Account/Manager.pm
new file mode 100644
index 0000000..6612114
--- /dev/null
+++ b/lib/AccountManager/Account/Manager.pm
@@ -0,0 +1,15 @@
+package AccountManager::Account::Manager;
+
+use strict;
+use warnings;
+
+use base qw(Rose::DB::Object::Manager);
+
+use AccountManager::Account;
+
+sub object_class { 'AccountManager::Account' }
+
+__PACKAGE__->make_manager_methods('accounts');
+
+1;
+
diff --git a/lib/AccountManager/TestAccount/Manager.pm b/lib/AccountManager/TestAccount/Manager.pm
deleted file mode 100644
index ea035c7..0000000
--- a/lib/AccountManager/TestAccount/Manager.pm
+++ /dev/null
@@ -1,15 +0,0 @@
-package AccountManager::TestAccount::Manager;
-
-use strict;
-use warnings;
-
-use base qw(Rose::DB::Object::Manager);
-
-use AccountManager::TestAccount;
-
-sub object_class { 'AccountManager::TestAccount' }
-
-__PACKAGE__->make_manager_methods('testaccounts');
-
-1;
-
diff --git a/lib/AccountManager/WebRequest.pm b/lib/AccountManager/WebRequest.pm
index 1e5fddd..0681575 100644
--- a/lib/AccountManager/WebRequest.pm
+++ b/lib/AccountManager/WebRequest.pm
@@ -10,8 +10,8 @@ use Template;
 use Log::Any::Adapter;
 use List::MoreUtils qw(uniq);
 
-use AccountManager::TestAccount;
-use AccountManager::TestAccount::Manager;
+use AccountManager::Account;
+use AccountManager::Account::Manager;
 use AccountManager::Token;
 use AccountManager::ServiceProvider;
 use AccountManager::SAMLMetadata;
@@ -470,7 +470,7 @@ sub req_validate_token {
 
     foreach my $profile (split(/, */, $profiles)) {
         my $password = AccountManager::Tools::generate_password();
-        my $account = AccountManager::TestAccount->new(
+        my $account = AccountManager::Account->new(
             db              => $self->{db},
             profile         => $profile,
             sp_entityid     => $entity,
@@ -494,7 +494,7 @@ sub req_validate_token {
     }
 
     ## Update simpleSAMLphp configuration to enable test accounts
-    my $accounts = AccountManager::TestAccount::Manager->get_testaccounts(
+    my $accounts = AccountManager::Account::Manager->get_accounts(
         db => $self->{db}
     );
 
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7ae6a43..d737bc5 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -8,8 +8,8 @@ nobase_modules_DATA = \
 	AccountManager/SAMLMetadata.pm \
 	AccountManager/ServiceProvider.pm \
 	AccountManager/ServiceProvider/Manager.pm \
-	AccountManager/TestAccount.pm \
-	AccountManager/TestAccount/Manager.pm \
+	AccountManager/Account.pm \
+	AccountManager/Account/Manager.pm \
 	AccountManager/Tools.pm \
 	AccountManager/WebRequest.pm
 
-- 
GitLab