This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7c682e
commit 575b7cc
Showing
7 changed files
with
148 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from src.entities.apartment import Apartment | ||
import unittest | ||
|
||
class TestApartment(unittest.TestCase): | ||
|
||
def test_initialization(self): | ||
# Test the initialization of the Apartment instance | ||
apartment = Apartment( | ||
id=1, | ||
address="123 Main St", | ||
location="City", | ||
last_register_date="2023-01-01", | ||
level=2, | ||
rent=1000, | ||
rooms=3, | ||
square_meter=75, | ||
temporary=True, | ||
age=20, | ||
youth=True | ||
) | ||
|
||
self.assertEqual(apartment.id, 1) | ||
self.assertEqual(apartment.address, "123 Main St") | ||
self.assertEqual(apartment.location, "City") | ||
self.assertEqual(apartment.last_register_date, "2023-01-01") | ||
self.assertEqual(apartment.level, 2) | ||
self.assertEqual(apartment.rent, 1000) | ||
self.assertEqual(apartment.rooms, 3) | ||
self.assertEqual(apartment.square_meter, 75) | ||
self.assertTrue(apartment.temporary) | ||
self.assertEqual(apartment.age, 20) | ||
self.assertTrue(apartment.youth) | ||
|
||
def test_string_representation(self): | ||
# Test the __str__ method of the Apartment class | ||
apartment = Apartment( | ||
id=1, | ||
address="123 Main St", | ||
location="City", | ||
last_register_date="2023-01-01", | ||
level=2, | ||
rent=1000, | ||
rooms=3, | ||
square_meter=75, | ||
temporary=True, | ||
age=20, | ||
youth=True | ||
) | ||
|
||
expected_str = "Address: 123 Main St\nLast Register Date: 2023-01-01\nLevel: 2\nLink: https://bostad.stockholm.se/bostad/1\nLocation: City\nRent: 1000\nRooms: 3\nSquare Meter: 75\nTemporary: True\nAge: 20\nYouth: True\n" | ||
self.assertEqual(str(apartment), expected_str) | ||
|
||
def test_youth_set_but_not_age(self): | ||
# Test that an exception is raised when youth and age are not set correctly | ||
with self.assertRaises(ValueError): | ||
Apartment( | ||
id=1, | ||
address="123 Main St", | ||
location="City", | ||
last_register_date="2023-01-01", | ||
level=2, | ||
rent=1000, | ||
rooms=3, | ||
square_meter=75, | ||
youth=True # Age is missing | ||
) | ||
|
||
def test_age_set_but_not_youth(self): | ||
# Test that an exception is raised when youth and age are not set correctly | ||
with self.assertRaises(ValueError): | ||
Apartment( | ||
id=1, | ||
address="123 Main St", | ||
location="City", | ||
last_register_date="2023-01-01", | ||
level=2, | ||
rent=1000, | ||
rooms=3, | ||
square_meter=75, | ||
age=23 # Youth is missing | ||
) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import unittest | ||
from unittest.mock import Mock, patch | ||
from src.repositories.apartment_firestore import ApartmentFirestoreRepository | ||
from src.entities.apartment import Apartment | ||
from google.api_core.exceptions import AlreadyExists | ||
|
||
class TestApartmentFirestoreRepository(unittest.TestCase): | ||
|
||
def setUp(self): | ||
# Mock Firebase Admin initialize_app method | ||
self.mock_firebase_admin = Mock() | ||
self.mock_firestore = Mock() | ||
self.mock_collection = Mock() | ||
self.mock_document = Mock() | ||
self.mock_firestore.client.return_value = self.mock_collection | ||
self.mock_collection.document.return_value = self.mock_document | ||
self.patcher = patch('src.repositories.apartment_firestore.firebase_admin', self.mock_firebase_admin) | ||
self.patcher.start() | ||
|
||
# Initialize the repository with a dummy credentials path | ||
self.repo = ApartmentFirestoreRepository('dummy_credentials.json') | ||
|
||
def tearDown(self): | ||
self.patcher.stop() | ||
|
||
def test_post_apartment_listing_successful(self): | ||
# Create a sample Apartment object | ||
apartment = Apartment("1", "Sample Apartment", 1000) | ||
|
||
# Mock Firestore create method to simulate successful creation | ||
self.mock_document.create.return_value = None | ||
|
||
# Attempt to post the apartment listing | ||
result = self.repo.post_apartment_listing(apartment) | ||
|
||
# Verify that the method returned True, indicating success | ||
self.assertTrue(result) | ||
|
||
def test_post_apartment_listing_already_exists(self): | ||
# Create a sample Apartment object | ||
apartment = Apartment("1", "Sample Apartment", 1000) | ||
|
||
# Mock Firestore create method to simulate AlreadyExists exception | ||
self.mock_document.create.side_effect = AlreadyExists("Document already exists") | ||
|
||
# Attempt to post the apartment listing | ||
result = self.repo.post_apartment_listing(apartment) | ||
|
||
# Verify that the method returned False, indicating that the document already exists | ||
self.assertFalse(result) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |