File: test_module.py

package info (click to toggle)
tryton-modules-country 7.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,112 kB
  • sloc: python: 1,358; xml: 649; makefile: 11; sh: 3
file content (82 lines) | stat: -rw-r--r-- 3,259 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

import datetime as dt

from trytond.pool import Pool
from trytond.tests.test_tryton import ModuleTestCase, with_transaction


class CountryTestCase(ModuleTestCase):
    'Test Country module'
    module = 'country'

    def create_membership(self, from_date=None, to_date=None):
        pool = Pool()
        Country = pool.get('country.country')
        Organization = pool.get('country.organization')
        OrganizationMember = pool.get('country.organization.member')

        organization = Organization(name="Organization")
        organization.save()
        country = Country(name="Country")
        country.save()
        member = OrganizationMember(
            organization=organization, country=country,
            from_date=from_date, to_date=to_date)
        member.save()
        return organization, country

    @with_transaction()
    def test_is_member_no_date(self):
        "Test is member without date"
        organization, country = self.create_membership()

        self.assertTrue(country.is_member(organization))
        self.assertTrue(country.is_member(organization, dt.date.min))
        self.assertTrue(country.is_member(organization, dt.date.max))

    @with_transaction()
    def test_is_member_with_from_date(self):
        "Test is member with from date"
        today = dt.date.today()
        yesterday = today - dt.timedelta(days=1)
        tomorrow = today + dt.timedelta(days=1)
        organization, country = self.create_membership(from_date=today)

        self.assertTrue(country.is_member(organization, today))
        self.assertFalse(country.is_member(organization, yesterday))
        self.assertTrue(country.is_member(organization, tomorrow))
        self.assertFalse(country.is_member(organization, dt.date.min))
        self.assertTrue(country.is_member(organization, dt.date.max))

    @with_transaction()
    def test_is_member_with_to_date(self):
        "Test is member with to date"
        today = dt.date.today()
        yesterday = today - dt.timedelta(days=1)
        tomorrow = today + dt.timedelta(days=1)
        organization, country = self.create_membership(to_date=today)

        self.assertTrue(country.is_member(organization, today))
        self.assertTrue(country.is_member(organization, yesterday))
        self.assertFalse(country.is_member(organization, tomorrow))
        self.assertTrue(country.is_member(organization, dt.date.min))
        self.assertFalse(country.is_member(organization, dt.date.max))

    @with_transaction()
    def test_is_member_with_dates(self):
        "Test is member with dates"
        today = dt.date.today()
        yesterday = today - dt.timedelta(days=1)
        tomorrow = today + dt.timedelta(days=1)
        organization, country = self.create_membership(
            from_date=yesterday, to_date=tomorrow)

        self.assertTrue(country.is_member(organization, today))
        self.assertTrue(country.is_member(organization, yesterday))
        self.assertFalse(country.is_member(organization, dt.date.min))
        self.assertFalse(country.is_member(organization, dt.date.max))


del ModuleTestCase