def test_merge_merges_note_2(self): share1 = ShareFactory.create() share2 = ShareFactory.create(note="Note 2") merge(share1.id, share2.id) assert Share.query.one().note == "Note 2"
def test_merge_other_way(self): share1 = ShareFactory.create() share2 = ShareFactory.create() MemberFactory.create(share=share1) MemberFactory.create(share=share2) MemberFactory.create(share=share2) BetFactory.create(share=share1) BetFactory.create(share=share1) BetFactory.create(share=share2) assert Share.query.count() == 2 assert Bet.query.count() == 3 merge(share2.id, share1.id) updated_share = Share.query.one() assert Share.query.count() == 1 assert len(updated_share.members) == 3 assert len(updated_share.bets) == 3 assert Member.query.count() == 3 assert Bet.query.count() == 3
def test_merge_keeps_station_other_way(self): station1 = StationFactory.create() share1 = ShareFactory.create(station=None) share2 = ShareFactory.create(station=station1) merge(share1.id, share2.id) assert Share.query.one().station == station1
def test_members(self): member1 = MemberFactory.create(email="*****@*****.**", name="Peter Farmer", phone="001234") member2 = MemberFactory.create(email="*****@*****.**", name="Paula Farmer", phone="001234") member3 = MemberFactory.create(email="*****@*****.**", name="Jane Doe", phone="0055689") station1 = StationFactory.create(name="Station 1") station2 = StationFactory.create(name="Station 2") share1 = ShareFactory.create(members=[member1, member2], station=station1) share2 = ShareFactory.create(members=[member3], station=station2) BetFactory.create(share=share1, start_date=date(2018, 1, 1), end_date=date(2018, 12, 1)) BetFactory.create(share=share1, start_date=date(2019, 1, 1)) BetFactory.create(share=share2, start_date=date(2019, 1, 15)) expected = [ { "email": "*****@*****.**", "id": member1.id, "name": "Peter Farmer", "phone": "001234", "share_id": share1.id, "station_name": "Station 1", "join_date": "2018-01-01T00:00:00" }, { "email": "*****@*****.**", "id": member2.id, "name": "Paula Farmer", "phone": "001234", "share_id": share1.id, "station_name": "Station 1", "join_date": "2018-01-01T00:00:00" }, { "email": "*****@*****.**", "id": member3.id, "name": "Jane Doe", "phone": "0055689", "share_id": share2.id, "station_name": "Station 2", "join_date": "2019-01-15T00:00:00" } ] response: Response = self.app.get(f"/api/v1/members") self.assertEqual(response.status_code, 200) self.maxDiff = None self.assertEqual(response.json, {"members": expected})
def test_merge_picks_first_station(self): station1 = StationFactory.create() station2 = StationFactory.create() share1 = ShareFactory.create(station=station1) share2 = ShareFactory.create(station=station2) merge(share1.id, share2.id) assert Share.query.one().station == station1
def test_members(self): member1 = MemberFactory.create(email="*****@*****.**", name="Peter Farmer", phone="001234") member2 = MemberFactory.create(email="*****@*****.**", name="Paula Farmer", phone="001234") member3 = MemberFactory.create(email="*****@*****.**", name="Jane Doe", phone="0055689") station1 = StationFactory.create(name="Station 1") station2 = StationFactory.create(name="Station 2") share1 = ShareFactory.create(members=[member1, member2], station=station1) share2 = ShareFactory.create(members=[member3], station=station2) expected = [ { "email": "*****@*****.**", "id": member1.id, "name": "Peter Farmer", "phone": "001234", "share_id": share1.id, "station_name": "Station 1" }, { "email": "*****@*****.**", "id": member2.id, "name": "Paula Farmer", "phone": "001234", "share_id": share1.id, "station_name": "Station 1" }, { "email": "*****@*****.**", "id": member3.id, "name": "Jane Doe", "phone": "0055689", "share_id": share2.id, "station_name": "Station 2" } ] response: Response = self.app.get(f"/api/v1/members") self.assertEqual(response.status_code, 200) self.maxDiff = None self.assertEqual(response.json, {"members": expected})
def test_share_emails_empty(self): share = ShareFactory.create() response: Response = self.app.get(f"/api/v1/shares/{share.id}/emails") self.assertEqual(response.status_code, 200) self.assertEquals(response.json, {"emails": []})
def test_get_shares(self): # The tests for making sure that the right amout is calculated for the # expected value are in test_models # This should only be for the api station = StationFactory.create(name="Our Station") share = ShareFactory.create(station=station) bet = BetFactory.create(value=99, start_date=date(2019, 1, 1), end_date=date(2019, 2, 1), share=share) person = PersonFactory.create(share=bet.share) DepositFactory.create(person=person, amount=99) response = self.app.get(f"/api/v1/shares/payment_status") expected = {'shares': [{'archived': False, 'difference_today': 0, 'expected_today': 99, 'id': 1, 'name': '', 'note': None, 'number_of_deposits': 1, 'station_name': "Our Station", 'total_deposits': 99.0}]} self.assertEqual(response.status_code, 200) self.assertEqual(response.json, expected)
def test_expected_amount_wiht_custom_start_date(self): from solawi.models import Person, Deposit, Share from datetime import date person = Person.get_or_create("Firstname Lastname") timestamp = date(2016, 3, 25) title = "CSA 123 - March payment for Firstname Lastname and Other One" amount = 63.0 deposit = Deposit(title=title, person=person, amount=amount, timestamp=timestamp) deposit.save() share = ShareFactory.create(people=[person]) assert share.number_of_deposits == 1 assert share.total_deposits == 63 assert len(Deposit.query.all()) == 1 deposit.ignore = True deposit.save() assert share.number_of_deposits == 0 assert share.total_deposits == 0 assert len(Deposit.query.all()) == 1
def test_members_expired(self): member1 = MemberFactory.create() member2 = MemberFactory.create() station1 = StationFactory.create() station2 = StationFactory.create() valid_bet = BetFactory.create() expired_bet = BetFactory.create(end_date=date(2016, 1, 1)) ShareFactory.create(members=[member1], station=station1, bets=[expired_bet]) ShareFactory.create(members=[member2], station=station2, bets=[valid_bet]) response: Response = self.app.get(f"/api/v1/members?active=true") self.assertEqual(response.status_code, 200) self.assertEqual(len(response.json["members"]), 1)
def test_expected_today_across_years(self): import datetime share = ShareFactory.create() bet = Bet(start_date=datetime.date(2016, 1, 1), end_date=datetime.date(2017, 3, 31), value=10, share_id=share.id) bet.save() assert share.expected_today == 150
def test_expected_today_is_decimal(self): import datetime share = ShareFactory.create() bet = Bet(start_date=datetime.date(2017, 1, 1), end_date=datetime.date(2017, 3, 31), value=97.17, share_id=share.id) bet.save() assert share.expected_today == Decimal('291.51')
def test_expected_today_half_month(self): import datetime share = ShareFactory.create() bet = Bet(start_date=datetime.date(2017, 1, 15), end_date=datetime.date(2017, 3, 31), value=100, share_id=share.id) bet.save() assert share.expected_today == 250
def test_share_emails(self): member = MemberFactory.create(email="*****@*****.**") share = ShareFactory.create(members=[member]) response: Response = self.app.get(f"/api/v1/shares/{share.id}/emails") expected = ["*****@*****.**"] self.assertEqual(response.status_code, 200) self.assertEquals(response.json, {"emails": expected})
def test_expected_today_half_month_mocked_today_month_end(self): import datetime share = ShareFactory.create() with patch('solawi.models.date') as mock_date: mock_date.today.return_value = datetime.date(2017, 1, 31) bet = Bet(start_date=datetime.date(2017, 1, 15), value=100, share_id=share.id) bet.save() assert share.expected_today == 150
def test_expected_today_without_end_date_begin_month(self): import datetime share = ShareFactory.create() with patch('solawi.models.date') as mock_date: mock_date.today.return_value = datetime.date(2017, 4, 1) bet = Bet(start_date=datetime.date(2017, 1, 1), value=100, share_id=share.id) bet.save() assert share.expected_today == 400
def test_jsonify(self): share = ShareFactory.create() person = PersonFactory(name="Misses Cash", share=share) expected = { "id": person.id, "name": "Misses Cash", "share_id": share.id } assert person.json == expected
def test_jsonify(self): share = ShareFactory.create() bet = BetFactory(share=share) expected = { 'start_date': datetime(2018, 1, 1, 0, 0), 'end_date': None, 'id': bet.id, 'value': Decimal('90'), 'share_id': share.id } assert bet.json == expected
def test_create_member(self): member1 = MemberFactory.create(name="Paul Wild / Paula Wilder") share = ShareFactory.create(members=[member1]) self.assertEqual(len(share.members), 1) new_member_json = {"name": "Paul Wild", "share_id": share.id} response: Response = self.app.post(f"/api/v1/members", json=new_member_json) updated_share = Share.get(share.id) self.assertEqual(response.status_code, 200) self.assertEqual(len(updated_share.members), 2)
def test_create_bet(self): share = ShareFactory.create() self.assertEqual(db.session.query(Bet).count(), 0) response = self.app.post(f"/api/v1/shares/{share.id}/bets", json={"value": "99", "start_date": "2019-01-01"}) bet = db.session.query(Bet).first() self.assertEqual(response.status_code, 200) self.assertEqual(db.session.query(Bet).count(), 1) self.assertEqual(bet.value, 99) self.assertEqual(bet.start_date, datetime(2019, 1, 1, 0, 0)) self.assertEqual(bet.end_date, None)
def test_merge_one_way(self): share1 = ShareFactory.create() share2 = ShareFactory.create() MemberFactory.create(share=share1) MemberFactory.create(share=share2) MemberFactory.create(share=share2) BetFactory.create(share=share1) BetFactory.create(share=share1) BetFactory.create(share=share2) assert Share.query.count() == 2 assert Bet.query.count() == 3 merge(share1.id, share2.id) updated_share = Share.query.one() assert Share.query.count() == 1 assert len(updated_share.members) == 3 assert len(updated_share.bets) == 3 assert Member.query.count() == 3 assert Bet.query.count() == 3
def test_jsonify(self): share = ShareFactory.create() member = MemberFactory(name="Mister Member", email="*****@*****.**", phone="+49012345", share=share) expected = { "id": member.id, "name": "Mister Member", "email": "*****@*****.**", "phone": "+49012345", "share_id": share.id } assert member.json == expected
def test_get_share_details(self): share = ShareFactory.create() response = self.app.get(f"/api/v1/shares/{share.id}") expected = {'share': {'archived': False, 'bets': [], 'difference_today': 0, 'expected_today': 0, 'id': 1, 'name': '', 'note': None, 'station_id': 1, 'total_deposits': 0}} self.assertEqual(response.status_code, 200) self.assertEqual(response.json, expected)
def test_person(self): from datetime import date from solawi.models import Person, Deposit, Share person = Person.get_or_create("Firstname Lastname") timestamp = date(2016, 1, 2) title = "CSA 123 - June payment for Firstname Lastname and Other One" amount = 63.0 deposit = Deposit(title=title, person=person, amount=amount, timestamp=timestamp) deposit.save() share = ShareFactory.create(people=[person]) assert share.number_of_deposits == 1 assert share.total_deposits == 63 assert len(Deposit.query.all()) == 1