apache / apache/libcloud

DNSPodDNSTests.test_create_record_success() returns an unexpected value

Aperta
#1,538 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
stale
Lingua principale
Python
Stelle
2.1k
Fork
931
Merge medio
1g 2h
PR unite (30g)
4

Descrizione

## `DNSPodDNSTests.test_create_record_success()` returns an unexpected value

Consider the following code (in [test_dnspod.py](https://github.com/apache/libcloud/blob/6b588346083a510396c63b5d18db3012aa083071/libcloud/test/dns/test_dnspod.py#L156)):

def test_create_record_success(self):
DNSPodMockHttp.type = 'CREATE_RECORD_SUCCESS'
record = self.driver.create_record(name='@', zone=self.test_zone,
type='A', data='96.126.115.73',
extra={'ttl': 13,
'record_line': 'default'})

## Expected result

I would expect `record.extra['ttl']` to be an int 13

## Actual result

The actual result, when running this unit test is:

`record.extra['ttl']` is the string `'600'`.
`record.ttl` is `None`.

Note that `'600'` (yes, a string) is the default TTL of the `self.test_zone`. [See the explicit check in line 61](https://github.com/apache/libcloud/blob/6b588346083a510396c63b5d18db3012aa083071/libcloud/test/dns/test_dnspod.py#L61).

## Detailed Information

At first, I expected an error in `DNSPodDNSDriver.create_record()`. Perhaps it ignored the `extra` parameter.

However, the `extra` dict is merged in the `data` dict, which is send to the DNSPod API, so that seems correct (although I don't know the intrinsics of the DNSPod API can am not sure).

Diving deeper in the test code, the perhaps likely explanation is that the API simulator (DNSPodMockHttp) returns the incorrect results. `DNSPodMockHttp._Record_Create_CREATE_RECORD_SUCCESS()` is called, which returns the contents of [`get_record.json`](https://github.com/apache/libcloud/blob/trunk/libcloud/test/dns/fixtures/dnspod/get_record.json). That file indeed contains `"ttl": "600",`. So I suspect that the unit test is flawed, not the actual code or DNSPod API (although I can't verify without access to this API).

## Suggested Fix

Without a contributor who has access to this API, my suggested solution is to disable this particular assertion in `DNSPodDNSTests.test_create_record_success()`.

This fix is included in #1537

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia da libcloud/test/dns/test_dnspod.py, in particolare da DNSPodDNSTests.test_create_record_success(), e ispeziona il percorso della risposta di DNSPodMockHttp e libcloud/test/dns/fixtures/dnspod/get_record.json. Esegui il test mirato e confronta il TTL del fixture con i campi del record attesi dal test; determina se debba essere l’assertion o il fixture a rappresentare il comportamento dell’API, tenendo conto della correzione suggerita in issue #1537.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api, testing-qa
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.