99 lines
2.8 KiB
Python
99 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
# ITerativ GmbH
|
|
# http://www.iterativ.ch/
|
|
#
|
|
# Copyright (c) 2020 ITerativ GmbH. All rights reserved.
|
|
#
|
|
# Created on 23.01.20
|
|
# @author: chrigu <christian.cueni@iterativ.ch>
|
|
import json
|
|
from datetime import datetime, timedelta
|
|
|
|
from django.test import TestCase
|
|
from core.hep_client import HepClient, TEACHER_EDITION_DURATION
|
|
|
|
|
|
class HepClientTestCases(TestCase):
|
|
def setUp(self):
|
|
self.hep_client = HepClient()
|
|
self.now = datetime.now()
|
|
|
|
def test_has_no_valid_product(self):
|
|
products = [
|
|
{
|
|
'edition': 'teacher',
|
|
'raw': {},
|
|
'activated': self.now - timedelta(2*TEACHER_EDITION_DURATION)
|
|
},
|
|
{
|
|
'edition': 'teacher',
|
|
'raw': {},
|
|
'activated': self.now - timedelta(3 * TEACHER_EDITION_DURATION)
|
|
},
|
|
{
|
|
'edition': 'teacher',
|
|
'raw': {},
|
|
'activated': self.now - timedelta(4 * TEACHER_EDITION_DURATION)
|
|
}
|
|
]
|
|
|
|
relevant_product = self.hep_client._get_relevant_product(products)
|
|
self.assertIsNone(relevant_product)
|
|
|
|
def test_has_valid_product(self):
|
|
products = [
|
|
{
|
|
'edition': 'teacher',
|
|
'raw': {
|
|
'id': 0
|
|
},
|
|
'activated': self.now - timedelta(7)
|
|
},
|
|
{
|
|
'edition': 'teacher',
|
|
'raw': {
|
|
'id': 1
|
|
},
|
|
'activated': self.now - timedelta(3 * TEACHER_EDITION_DURATION)
|
|
},
|
|
{
|
|
'edition': 'teacher',
|
|
'raw': {
|
|
'id': 2
|
|
},
|
|
'activated': self.now - timedelta(4 * TEACHER_EDITION_DURATION)
|
|
}
|
|
]
|
|
|
|
relevant_product = self.hep_client._get_relevant_product(products)
|
|
self.assertEqual(relevant_product['raw']['id'], 0)
|
|
|
|
def test_has_multiple_valid_products(self):
|
|
products = [
|
|
{
|
|
'edition': 'teacher',
|
|
'raw': {
|
|
'id': 0
|
|
},
|
|
'activated': self.now - timedelta(7)
|
|
},
|
|
{
|
|
'edition': 'teacher',
|
|
'raw': {
|
|
'id': 1
|
|
},
|
|
'activated': self.now - timedelta(3 * TEACHER_EDITION_DURATION)
|
|
},
|
|
{
|
|
'edition': 'teacher',
|
|
'raw': {
|
|
'id': 2
|
|
},
|
|
'activated': self.now - timedelta(4 * TEACHER_EDITION_DURATION)
|
|
}
|
|
]
|
|
|
|
relevant_product = self.hep_client._get_relevant_product(products)
|
|
self.assertEqual(relevant_product['raw']['id'], 0)
|