Metadata-Version: 2.4
Name: medicentrev3-auth
Version: 1.2.0
Summary: Authentication and navigation module for MedicentreV3 automation
Author-email: Denis Ndiritu <denis@hanmak.co.ke>
License-Expression: MIT
Project-URL: Homepage, https://github.com/Hanmak-Technologies-Automation-Project/medicentrev3-authentication-package
Project-URL: Repository, https://github.com/Hanmak-Technologies-Automation-Project/medicentrev3-authentication-package
Project-URL: Issues, https://github.com/Hanmak-Technologies-Automation-Project/medicentrev3-authentication-package/issues
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown
Requires-Dist: selenium>=4.11.0
Requires-Dist: python-dotenv>=0.19.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: flake8>=5.0.0; extra == "dev"

# MedicentreV3 Authentication Package

A reusable Python package for MedicentreV3 authentication and navigation.

## Installation

### From GitHub (Production)
```bash
# Install from GitHub (latest version)
pip install git+https://github.com/Hanmak-Technologies-Automation-Project/medicentrev3-authentication-package.git

# For development
pip install -e "git+https://github.com/Hanmak-Technologies-Automation-Project/medicentrev3-authentication-package.git#egg=medicentrev3-auth"
```

### Local Development (Recommended for testing changes)

If you're developing or testing changes to this package, install it locally:

#### Option 1: Editable Install (Recommended)
```bash
# Navigate to the package directory
cd /path/to/medicentrev3-authentication-package

# Install in editable mode (-e flag)
pip install -e .
```

#### Option 2: Install from Local Path
```bash
# Install directly from local directory
pip install /path/to/medicentrev3-authentication-package
```

#### Option 3: Add to PYTHONPATH (For development only)
```bash
# Add the package directory to PYTHONPATH
export PYTHONPATH="/path/to/medicentrev3-authentication-package:$PYTHONPATH"

# Or add to your Python script
import sys
sys.path.insert(0, '/path/to/medicentrev3-authentication-package')
```

### Verifying Installation
```bash
# Check if package is installed
python -c "import medicentrev3_auth; print('Version:', medicentrev3_auth.get_version())"

# Run the version checker
python /path/to/medicentrev3-authentication-package/check_version.py
```

## Development and Testing

### Quick Development Setup
```bash
# Run the development setup script
python setup_dev.py
```

### Example Usage
```bash
# Run the example script to see how to use the package
python example_usage.py
```

### Quick Start Template

Copy the `quick_start_template.py` file to your project and customize it:

```bash
cp /path/to/medicentrev3-authentication-package/quick_start_template.py ~/my_project/my_automation.py
```

Then modify it with your specific automation logic.
   ```bash
   mkdir ~/my_automation_project
   cd ~/my_automation_project
   ```

2. **Install the package locally**:
   ```bash
   pip install -e /path/to/medicentrev3-authentication-package
   ```

3. **Create environment file** (`.env`):
   ```bash
   MEDICENTRE_BASE_URL=https://medicentrev3.hanmak.co.ke
   MEDICENTRE_ACCESS_CODE=your_access_code
   MEDICENTRE_BRANCH=your_branch_name
   MEDICENTRE_USERNAME=your_username
   MEDICENTRE_PASSWORD=your_password
   ```

   `MEDICENTRE_BRANCH` must match a branch in the dropdown (case-insensitive). A partial
   name is accepted only if it matches exactly one branch; otherwise login fails and the
   available branches are logged. The package no longer falls back to the first branch.

   If the branch dropdown comes up empty after entering the access code, the page is
   reloaded and the access code re-entered. This is tunable:
   ```python
   auth = MedicentreAuth(login_attempts=3, branch_load_timeout=10)  # defaults
   ```

4. **Create your automation script** (`automation.py`):
   ```python
   from medicentrev3_auth import MedicentreAuth
   
   # Create auth instance
   auth = MedicentreAuth(headless=False)
   
   # Setup and login
   if auth.setup_and_login():
       print("Login successful!")
       
       # Navigate to procurement suppliers
       if auth.navigate_to('procurement', 'suppliers'):
           print("On suppliers page - ready for automation")
           # Your automation code here
       
       # Always logout
       auth.logout()
   else:
       print("Login failed")
   ```

5. **Run your script**:
   ```bash
   python automation.py
   ```

### Development Workflow

For ongoing development of the authentication package:

1. **Make changes** to the package code
2. **Test locally** using the development setup:
   ```bash
   cd /path/to/medicentrev3-authentication-package
   python setup_dev.py
   ```
3. **Test in external project** to ensure compatibility
4. **Update version** when ready to release
5. **Push changes** and inform users to update

### Troubleshooting

**Import errors:**
```bash
# Make sure package is installed
pip install -e /path/to/medicentrev3-authentication-package

# Check installation
python -c "import medicentrev3_auth; print('OK')"
```

**Login failures:**
- Verify `.env` file exists and has correct values
- Check network connectivity to MedicentreV3
- Ensure credentials are valid
- Try with `headless=False` to see browser behavior

**Permission issues:**
- Ensure write permissions for logs/screenshots directories
- Check that Chrome/Chromium is installed for Selenium

## Usage

```python
from medicentrev3_auth import MedicentreAuth

# Create auth instance (loads .env by default)
auth = MedicentreAuth(headless=False)

# Or disable .env loading if you set env vars manually
auth = MedicentreAuth(load_env_file=False)

# Setup and login
if auth.setup_and_login():
    # Navigate to a module panel
    if auth.navigate_to('procurement', 'suppliers'):
        # Your module-specific automation here
        pass
    # Always logout when done
    auth.logout()
```

## Updating the Package

When updates are available, users should upgrade using:

```bash
# Upgrade to latest version
pip install --upgrade git+https://github.com/Hanmak-Technologies-Automation-Project/medicentrev3-authentication-package.git

# Or reinstall (force latest)
pip install --force-reinstall git+https://github.com/Hanmak-Technologies-Automation-Project/medicentrev3-authentication-package.git
```

**Important**: Always use `--upgrade` or `--force-reinstall` when updating from GitHub to ensure you get the latest changes.

## Checking Your Version

You can check your current package version and see if updates are available:

```bash
# Run the version checker script
python check_version.py

# Or check programmatically in Python
python -c "import medicentrev3_auth; print('Version:', medicentrev3_auth.get_version())"
```

## Version History

### v1.1.0
- Added version checking utilities (`get_version()`, `check_for_updates()`)
- Improved documentation and update instructions
- Enhanced package metadata
- **Modernized WebDriver setup**: Now uses Selenium Manager (Selenium 4.11+) instead of webdriver-manager for better reliability and fewer dependencies

### v1.0.0
- Initial release
- Basic authentication and navigation functionality
- Support for all major MedicentreV3 modules
